mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-19 14:27:14 +01:00
node docs (#4259)
This commit is contained in:
parent
7400aea355
commit
e0cb8c228b
@ -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'
|
||||
```
|
||||
|
@ -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.
|
||||
|
||||
|
5
utils/node-documentation-generator/snippet/class.php.inc
Normal file
5
utils/node-documentation-generator/snippet/class.php.inc
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
|
||||
return new Class_('ClassName');
|
11
utils/node-documentation-generator/snippet/class2.php.inc
Normal file
11
utils/node-documentation-generator/snippet/class2.php.inc
Normal 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;
|
@ -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);
|
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
use PhpParser\Node\Expr\ClassConstFetch;
|
||||
use PhpParser\Node\Name;
|
||||
|
||||
$class = new Name('SomeClassName');
|
||||
|
||||
return new ClassConstFetch($class, 'SOME_CONSTANT');
|
@ -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;
|
@ -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;
|
6
utils/node-documentation-generator/snippet/const.php.inc
Normal file
6
utils/node-documentation-generator/snippet/const.php.inc
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
use PhpParser\Node\Const_;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
|
||||
return new Const_('CONSTANT_NAME', new String_('default'));
|
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
use PhpParser\Node\Expr\ConstFetch;
|
||||
use PhpParser\Node\Name;
|
||||
|
||||
$name = new Name('true');
|
||||
|
||||
return new ConstFetch($name);
|
10
utils/node-documentation-generator/snippet/declare.php.inc
Normal file
10
utils/node-documentation-generator/snippet/declare.php.inc
Normal 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]);
|
||||
|
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
use PhpParser\Node\Stmt\DeclareDeclare;
|
||||
|
||||
return new DeclareDeclare('strict_types', new LNumber(1));
|
8
utils/node-documentation-generator/snippet/do.php.inc
Normal file
8
utils/node-documentation-generator/snippet/do.php.inc
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\Do_;
|
||||
|
||||
$variable = new Variable('variableName');
|
||||
|
||||
return new Do_($variable);
|
8
utils/node-documentation-generator/snippet/echo.php.inc
Normal file
8
utils/node-documentation-generator/snippet/echo.php.inc
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt\Echo_;
|
||||
|
||||
$msg = new String_('hello');
|
||||
|
||||
return new Echo_([$msg]);
|
12
utils/node-documentation-generator/snippet/else_if.php.inc
Normal file
12
utils/node-documentation-generator/snippet/else_if.php.inc
Normal 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]);
|
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
|
||||
$variable = new Variable('variableName');
|
||||
|
||||
return new PropertyFetch($variable, 'propertyName');
|
Loading…
x
Reference in New Issue
Block a user