This commit is contained in:
Marek Šimeček 2020-09-18 16:06:24 +02:00 committed by GitHub
parent 7400aea355
commit e0cb8c228b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 371 additions and 1 deletions

View File

@ -152,6 +152,22 @@ $variableName =& $someOtherVariable
#### Example PHP Code
```php
SomeClassName::SOME_CONSTANT
```
```php
<?php
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Name;
$class = new Name('SomeClassName');
return new ClassConstFetch($class, 'SOME_CONSTANT');
```
```php
SomeClassName::SOME_CONSTANT
```
@ -222,6 +238,22 @@ $variableName
#### Example PHP Code
```php
true
```
```php
<?php
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Name;
$name = new Name('true');
return new ConstFetch($name);
```
```php
true
```
@ -554,6 +586,22 @@ print $variableName
#### Example PHP Code
```php
$variableName->propertyName
```
```php
<?php
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\Variable;
$variable = new Variable('variableName');
return new PropertyFetch($variable, 'propertyName');
```
```php
$variableName->propertyName
```
@ -1802,6 +1850,24 @@ catch (CatchedType $catchedVariable) {
```php
const SOME_CLASS_CONSTANT = 'default value';
```
```php
<?php
use PhpParser\Node\Const_;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassConst;
$const = new Const_('SOME_CLASS_CONSTANT', new String_('default value'));
return new ClassConst([$const], Class_::MODIFIER_PUBLIC);
```
```php
public const SOME_CLASS_CONSTANT = 'default value';
```
#### Public Properties
@ -1821,6 +1887,50 @@ public function methodName()
{
}
```
```php
<?php
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
$classMethod = new ClassMethod('methodName');
$classMethod->flags = Class_::MODIFIER_PUBLIC;
return $classMethod;
```
```php
public function methodName()
{
}
```
```php
<?php
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
$classMethod = new ClassMethod('methodName');
$classMethod->flags = Class_::MODIFIER_PRIVATE;
$classMethod->params = [new Variable('param')];
$classMethod->returnType = new Identifier('string');
return $classMethod;
```
```php
private function methodName($param): string
{
}
```
#### Public Properties
@ -1845,6 +1955,42 @@ class ClassName
{
}
```
```php
<?php
use PhpParser\Node\Stmt\Class_;
return new Class_('ClassName');
```
```php
class ClassName
{
}
```
```php
<?php
use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt\Class_;
$class = new Class_('ClassName');
$class->flags = Class_::MODIFIER_FINAL;
$class->extends = new Identifier('Parent');
return $class;
```
```php
final class ClassName extends Parent
{
}
```
#### Public Properties
@ -1892,6 +2038,20 @@ continue;
#### Example PHP Code
```php
strict_types=1
```
```php
<?php
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Stmt\DeclareDeclare;
return new DeclareDeclare('strict_types', new LNumber(1));
```
```php
strict_types=1
```
@ -1909,6 +2069,23 @@ strict_types=1
#### Example PHP Code
```php
declare(strict_types=1);
```
```php
<?php
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Stmt\Declare_;
use PhpParser\Node\Stmt\DeclareDeclare;
$declareDeclare = new DeclareDeclare('strict_types', new LNumber(1));
return new Declare_([$declareDeclare]);
```
```php
declare(strict_types=1);
```
@ -1926,6 +2103,23 @@ declare(strict_types=1);
#### Example PHP Code
```php
do {
} while ($variableName);
```
```php
<?php
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Do_;
$variable = new Variable('variableName');
return new Do_($variable);
```
```php
do {
} while ($variableName);
@ -1944,6 +2138,22 @@ do {
#### Example PHP Code
```php
echo 'hello';
```
```php
<?php
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Echo_;
$msg = new String_('hello');
return new Echo_([$msg]);
```
```php
echo 'hello';
```
@ -1964,6 +2174,28 @@ echo 'hello';
elseif (true) {
}
```
```php
<?php
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\ElseIf_;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Stmt\Return_;
$name = new Name('true');
$constFetch = new ConstFetch($name);
$stmt = new Return_();
return new ElseIf_($constFetch, [$stmt]);
```
```php
elseif (true) {
return;
}
```
#### Public Properties
@ -2574,6 +2806,20 @@ $variableName
#### Example PHP Code
```php
CONSTANT_NAME = 'default'
```
```php
<?php
use PhpParser\Node\Const_;
use PhpParser\Node\Scalar\String_;
return new Const_('CONSTANT_NAME', new String_('default'));
```
```php
CONSTANT_NAME = 'default'
```

View File

@ -4861,7 +4861,7 @@ Remove null coalescing operator ??=
### `DowngradeTypedPropertyRector`
- class: [`Rector\DowngradePhp74\Rector\Property\DowngradeTypedPropertyRector`](/rules/downgrade-php74/src/Rector/Property/DowngradeTypedPropertyRector.php)
- [test fixtures](/rules/downgrade-php74/tests/Rector/Property/DowngradeTypedPropertyRector/Fixture)
- [test fixtures](/rules/downgrade-php74/tests/Rector/Property/NoDocBlockDowngradeTypedPropertyRector/Fixture)
Changes property type definition from type definitions to `@var` annotations.

View File

@ -0,0 +1,5 @@
<?php
use PhpParser\Node\Stmt\Class_;
return new Class_('ClassName');

View File

@ -0,0 +1,11 @@
<?php
use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt\Class_;
$class = new Class_('ClassName');
$class->flags = Class_::MODIFIER_FINAL;
$class->extends = new Identifier('Parent');
return $class;

View File

@ -0,0 +1,10 @@
<?php
use PhpParser\Node\Const_;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassConst;
$const = new Const_('SOME_CLASS_CONSTANT', new String_('default value'));
return new ClassConst([$const], Class_::MODIFIER_PUBLIC);

View File

@ -0,0 +1,8 @@
<?php
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Name;
$class = new Name('SomeClassName');
return new ClassConstFetch($class, 'SOME_CONSTANT');

View File

@ -0,0 +1,10 @@
<?php
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
$classMethod = new ClassMethod('methodName');
$classMethod->flags = Class_::MODIFIER_PUBLIC;
return $classMethod;

View File

@ -0,0 +1,14 @@
<?php
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
$classMethod = new ClassMethod('methodName');
$classMethod->flags = Class_::MODIFIER_PRIVATE;
$classMethod->params = [new Variable('param')];
$classMethod->returnType = new Identifier('string');
return $classMethod;

View File

@ -0,0 +1,6 @@
<?php
use PhpParser\Node\Const_;
use PhpParser\Node\Scalar\String_;
return new Const_('CONSTANT_NAME', new String_('default'));

View File

@ -0,0 +1,8 @@
<?php
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Name;
$name = new Name('true');
return new ConstFetch($name);

View File

@ -0,0 +1,10 @@
<?php
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Stmt\Declare_;
use PhpParser\Node\Stmt\DeclareDeclare;
$declareDeclare = new DeclareDeclare('strict_types', new LNumber(1));
return new Declare_([$declareDeclare]);

View File

@ -0,0 +1,6 @@
<?php
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Stmt\DeclareDeclare;
return new DeclareDeclare('strict_types', new LNumber(1));

View File

@ -0,0 +1,8 @@
<?php
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Do_;
$variable = new Variable('variableName');
return new Do_($variable);

View File

@ -0,0 +1,8 @@
<?php
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Echo_;
$msg = new String_('hello');
return new Echo_([$msg]);

View File

@ -0,0 +1,12 @@
<?php
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\ElseIf_;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Stmt\Return_;
$name = new Name('true');
$constFetch = new ConstFetch($name);
$stmt = new Return_();
return new ElseIf_($constFetch, [$stmt]);

View File

@ -0,0 +1,8 @@
<?php
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\Variable;
$variable = new Variable('variableName');
return new PropertyFetch($variable, 'propertyName');