From c570bc940358fd215878d80c3aa4244301066a8c Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 22 Jul 2023 14:20:36 +0200 Subject: [PATCH 01/16] add fluent call --- README.md | 67 +++++++++++++++++++++++++------- phpstan.neon | 5 --- snippet/method_call_fluent.php | 19 +++++++++ src/Command/DumpNodesCommand.php | 23 ++--------- src/NodeCodeSampleProvider.php | 3 +- 5 files changed, 79 insertions(+), 38 deletions(-) create mode 100644 snippet/method_call_fluent.php diff --git a/README.md b/README.md index ab1dce5..99de4d3 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ CONSTANT_NAME = 'default' * `$name` - `/** @var Identifier Name */` * `$value` - `/** @var Expr Value */` + * `$namespacedName` - `/** @var Name|null Namespaced name (if using NameResolver) */`
@@ -168,7 +169,7 @@ fn() => 1 * `$static` - `/** @var bool */` * `$byRef` - `/** @var bool */` * `$params` - `/** @var Node\Param[] */` - * `$returnType` - `/** @var null|Node\Identifier|Node\Name|Node\NullableType|Node\UnionType */` + * `$returnType` - `/** @var null|Node\Identifier|Node\Name|Node\ComplexType */` * `$expr` - `/** @var Expr */` * `$attrGroups` - `/** @var Node\AttributeGroup[] */` @@ -937,7 +938,7 @@ func_call($someVariable) ### Public Properties * `$name` - `/** @var Node\Name|Expr Function name */` - * `$args` - `/** @var Node\Arg[] Arguments */` + * `$args` - `/** @var array Arguments */`
@@ -1165,6 +1166,36 @@ $someObject->methodName() declare(strict_types=1); +use PhpParser\Node\Arg; +use PhpParser\Node\Expr\MethodCall; +use PhpParser\Node\Expr\Variable; +use PhpParser\Node\Scalar\String_; + +$variable = new Variable('someObject'); + +$args = []; +$args[] = new Arg(new String_('yes')); + +$methodCall = new MethodCall($variable, 'methodName', $args); + +$nestedMethodCall = new MethodCall($methodCall, 'nextMethodName'); + +return $nestedMethodCall; +``` + +↓ + +```php +$someObject->methodName('yes')->nextMethodName() +``` + +
+ +```php +methodName('yes', 'maybe') * `$var` - `/** @var Expr Variable holding object */` * `$name` - `/** @var Identifier|Expr Method name */` - * `$args` - `/** @var Arg[] Arguments */` + * `$args` - `/** @var array Arguments */`
@@ -1271,7 +1302,7 @@ new SomeClass() ### Public Properties * `$class` - `/** @var Node\Name|Expr|Node\Stmt\Class_ Class name */` - * `$args` - `/** @var Node\Arg[] Arguments */` + * `$args` - `/** @var array Arguments */`
@@ -1304,7 +1335,7 @@ $variableName?->methodName() * `$var` - `/** @var Expr Variable holding object */` * `$name` - `/** @var Identifier|Expr Method name */` - * `$args` - `/** @var Arg[] Arguments */` + * `$args` - `/** @var array Arguments */`
@@ -1401,7 +1432,7 @@ return new StaticCall($fullyQualified, 'methodName'); * `$class` - `/** @var Node\Name|Expr Class name */` * `$name` - `/** @var Identifier|Expr Method name */` - * `$args` - `/** @var Node\Arg[] Arguments */` + * `$args` - `/** @var array Arguments */`
@@ -1592,7 +1623,10 @@ shortName ### Public Properties - * `$parts` - `/** @var string[] Parts of the name */` + * `$parts` - `/** + * @var string[] Parts of the name + * @deprecated Use getParts() instead + */` * `$specialClassNames` - ``
@@ -1621,7 +1655,10 @@ return new FullyQualified('SomeNamespace\ShortName'); ### Public Properties - * `$parts` - `/** @var string[] Parts of the name */` + * `$parts` - `/** + * @var string[] Parts of the name + * @deprecated Use getParts() instead + */`
@@ -1680,7 +1717,7 @@ $variableName ### Public Properties - * `$type` - `/** @var null|Identifier|Name|NullableType|UnionType Type declaration */` + * `$type` - `/** @var null|Identifier|Name|ComplexType Type declaration */` * `$byRef` - `/** @var bool Whether parameter is passed by reference */` * `$variadic` - `/** @var bool Whether this is a variadic argument */` * `$var` - `/** @var Expr\Variable|Expr\Error Parameter variable */` @@ -1940,7 +1977,7 @@ public function methodName() * `$byRef` - `/** @var bool Whether to return by reference */` * `$name` - `/** @var Node\Identifier Name */` * `$params` - `/** @var Node\Param[] Parameters */` - * `$returnType` - `/** @var null|Node\Identifier|Node\Name|Node\NullableType|Node\UnionType Return type */` + * `$returnType` - `/** @var null|Node\Identifier|Node\Name|Node\ComplexType Return type */` * `$stmts` - `/** @var Node\Stmt[]|null Statements */` * `$attrGroups` - `/** @var Node\AttributeGroup[] PHP attribute groups */` * `$magicNames` - `` @@ -2028,6 +2065,7 @@ final class ClassName extends \ParentClass * `$name` - `/** @var Node\Identifier|null Name */` * `$stmts` - `/** @var Node\Stmt[] Statements */` * `$attrGroups` - `/** @var Node\AttributeGroup[] PHP attribute groups */` + * `$namespacedName` - `/** @var Node\Name|null Namespaced name (if using NameResolver) */`
@@ -2264,9 +2302,10 @@ function some_function() * `$byRef` - `/** @var bool Whether function returns by reference */` * `$name` - `/** @var Node\Identifier Name */` * `$params` - `/** @var Node\Param[] Parameters */` - * `$returnType` - `/** @var null|Node\Identifier|Node\Name|Node\NullableType|Node\UnionType Return type */` + * `$returnType` - `/** @var null|Node\Identifier|Node\Name|Node\ComplexType Return type */` * `$stmts` - `/** @var Node\Stmt[] Statements */` * `$attrGroups` - `/** @var Node\AttributeGroup[] PHP attribute groups */` + * `$namespacedName` - `/** @var Node\Name|null Namespaced name (if using NameResolver) */`
@@ -2366,6 +2405,7 @@ interface InterfaceName * `$name` - `/** @var Node\Identifier|null Name */` * `$stmts` - `/** @var Node\Stmt[] Statements */` * `$attrGroups` - `/** @var Node\AttributeGroup[] PHP attribute groups */` + * `$namespacedName` - `/** @var Node\Name|null Namespaced name (if using NameResolver) */`
@@ -2473,7 +2513,7 @@ public static $firstProperty, $secondProperty; * `$flags` - `/** @var int Modifiers */` * `$props` - `/** @var PropertyProperty[] Properties */` - * `$type` - `/** @var null|Identifier|Name|NullableType|UnionType Type declaration */` + * `$type` - `/** @var null|Identifier|Name|ComplexType Type declaration */` * `$attrGroups` - `/** @var Node\AttributeGroup[] PHP attribute groups */`
@@ -2742,6 +2782,7 @@ trait TraitName * `$name` - `/** @var Node\Identifier|null Name */` * `$stmts` - `/** @var Node\Stmt[] Statements */` * `$attrGroups` - `/** @var Node\AttributeGroup[] PHP attribute groups */` + * `$namespacedName` - `/** @var Node\Name|null Namespaced name (if using NameResolver) */`
@@ -2915,6 +2956,6 @@ string|int ### Public Properties - * `$types` - `/** @var (Identifier|Name)[] Types */` + * `$types` - `/** @var (Identifier|Name|IntersectionType)[] Types */`
\ No newline at end of file diff --git a/phpstan.neon b/phpstan.neon index 74e0b1b..028820a 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,8 +4,3 @@ parameters: paths: - src - tests - - ignoreErrors: - - - message: '#Cannot cast (.*?) to string#' - path: src/Command/DumpNodesCommand.php diff --git a/snippet/method_call_fluent.php b/snippet/method_call_fluent.php new file mode 100644 index 0000000..e31cfec --- /dev/null +++ b/snippet/method_call_fluent.php @@ -0,0 +1,19 @@ +setName('dump-nodes'); $this->setDescription('Dump nodes overview'); - - $this->addOption( - self::OUTPUT_FILE, - null, - InputOption::VALUE_REQUIRED, - 'Where to output the file', - getcwd() . '/docs/nodes_overview.md' - ); } protected function execute(InputInterface $input, OutputInterface $output): int { - $outputFile = (string) $input->getOption(self::OUTPUT_FILE); - $nodeInfos = $this->nodeInfosFactory->create(); $printedContent = $this->markdownNodeInfosPrinter->print($nodeInfos); - file_put_contents($outputFile, $printedContent); + file_put_contents(getcwd() . '/README.md', $printedContent); + + $output->write(PHP_EOL); $output->writeln(sprintf( - 'Documentation for "%d" PhpParser Nodes was generated to "%s"', + 'Documentation for %d nodes was generated to README.md' . PHP_EOL, count($nodeInfos), - $outputFile )); return self::SUCCESS; diff --git a/src/NodeCodeSampleProvider.php b/src/NodeCodeSampleProvider.php index d5ccb8c..c4ab3c9 100644 --- a/src/NodeCodeSampleProvider.php +++ b/src/NodeCodeSampleProvider.php @@ -34,7 +34,8 @@ public function provide(): array /** @var string $fileContents */ $fileContents = file_get_contents($phpFilePath); - Assert::isInstanceOf($node, Node::class, $phpFilePath); + $errorMessage = sprintf('The "%s" file must return "%s" instance ', $phpFilePath, Node::class); + Assert::isInstanceOf($node, Node::class, $errorMessage); $nodeClass = $node::class; From a77a0c0a3d626c3c97844554d7d4c80d559a46f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Fri, 27 Oct 2023 19:07:55 +0000 Subject: [PATCH 02/16] Fix typos --- README.md | 6 +++--- snippet/list.php | 2 +- snippet/try_catch.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 99de4d3..77c2084 100644 --- a/README.md +++ b/README.md @@ -1074,7 +1074,7 @@ use PhpParser\Node\Expr\List_; use PhpParser\Node\Expr\Variable; $variable = new Variable('variableName'); -$anotherVariable = new Variable('anoterVariableName'); +$anotherVariable = new Variable('anotherVariableName'); $arrayItems = [new ArrayItem($variable), new ArrayItem($anotherVariable)]; @@ -1084,7 +1084,7 @@ return new List_($arrayItems); ↓ ```php -list($variableName, $anoterVariableName) +list($variableName, $anotherVariableName) ```
@@ -2806,7 +2806,7 @@ $echo = new Echo_([new String_('one')]); $tryStmts = [$echo]; $echo2 = new Echo_([new String_('two')]); -$catch = new Catch_([new FullyQualified('CatchedType')], null, [$echo2]); +$catch = new Catch_([new FullyQualified('CaughtType')], null, [$echo2]); $echo3 = new Echo_([new String_('three')]); $finally = new Finally_([$echo3]); diff --git a/snippet/list.php b/snippet/list.php index 37b9e4b..41b6067 100644 --- a/snippet/list.php +++ b/snippet/list.php @@ -7,7 +7,7 @@ use PhpParser\Node\Expr\Variable; $variable = new Variable('variableName'); -$anotherVariable = new Variable('anoterVariableName'); +$anotherVariable = new Variable('anotherVariableName'); $arrayItems = [new ArrayItem($variable), new ArrayItem($anotherVariable)]; diff --git a/snippet/try_catch.php b/snippet/try_catch.php index bfeb6c6..f7135cf 100644 --- a/snippet/try_catch.php +++ b/snippet/try_catch.php @@ -13,7 +13,7 @@ $tryStmts = [$echo]; $echo2 = new Echo_([new String_('two')]); -$catch = new Catch_([new FullyQualified('CatchedType')], null, [$echo2]); +$catch = new Catch_([new FullyQualified('CaughtType')], null, [$echo2]); $echo3 = new Echo_([new String_('three')]); $finally = new Finally_([$echo3]); From be06ca58880ce7969d72c310266ab037a5042953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Sat, 28 Oct 2023 09:32:59 +0000 Subject: [PATCH 03/16] Correct to "SomeType" --- README.md | 4 ++-- snippet/try_catch.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 77c2084..48add1a 100644 --- a/README.md +++ b/README.md @@ -2806,7 +2806,7 @@ $echo = new Echo_([new String_('one')]); $tryStmts = [$echo]; $echo2 = new Echo_([new String_('two')]); -$catch = new Catch_([new FullyQualified('CaughtType')], null, [$echo2]); +$catch = new Catch_([new FullyQualified('SomeType')], null, [$echo2]); $echo3 = new Echo_([new String_('three')]); $finally = new Finally_([$echo3]); @@ -2819,7 +2819,7 @@ return new TryCatch($tryStmts, [$catch]); ```php try { echo 'one'; -} catch (\CatchedType) { +} catch (\SomeType) { echo 'two'; } ``` diff --git a/snippet/try_catch.php b/snippet/try_catch.php index f7135cf..737c673 100644 --- a/snippet/try_catch.php +++ b/snippet/try_catch.php @@ -13,7 +13,7 @@ $tryStmts = [$echo]; $echo2 = new Echo_([new String_('two')]); -$catch = new Catch_([new FullyQualified('CaughtType')], null, [$echo2]); +$catch = new Catch_([new FullyQualified('SomeType')], null, [$echo2]); $echo3 = new Echo_([new String_('three')]); $finally = new Finally_([$echo3]); From 0f86a6029ddb058e84605aabc91e6f08b63edcad Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 10 Oct 2025 22:44:14 +0200 Subject: [PATCH 04/16] update --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 48add1a..5359e8b 100644 --- a/README.md +++ b/README.md @@ -779,7 +779,7 @@ return new ClassConstFetch($class, 'SOME_CONSTANT'); ### Public Properties * `$class` - `/** @var Name|Expr Class name */` - * `$name` - `/** @var Identifier|Error Constant name */` + * `$name` - `/** @var Identifier|Expr|Error Constant name */`
@@ -1873,7 +1873,8 @@ public const SOME_CLASS_CONSTANT = 'default value'; * `$flags` - `/** @var int Modifiers */` * `$consts` - `/** @var Node\Const_[] Constant declarations */` - * `$attrGroups` - `/** @var Node\AttributeGroup[] */` + * `$attrGroups` - `/** @var Node\AttributeGroup[] PHP attribute groups */` + * `$type` - `/** @var Node\Identifier|Node\Name|Node\ComplexType|null Type declaration */`
From 9f016683c7791e59f80908ab6d2b3a8245ba9d14 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 10 Oct 2025 22:45:23 +0200 Subject: [PATCH 05/16] bump deps --- composer.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 5bb2dab..76f477e 100644 --- a/composer.json +++ b/composer.json @@ -7,17 +7,17 @@ "bin/console.php" ], "require": { - "php": "^8.1", + "php": "^8.2", "symfony/console": "^6.3", - "nikic/php-parser": "^4.16", - "illuminate/container": "^10.15", + "nikic/php-parser": "^5.6", + "illuminate/container": "^12.15", "webmozart/assert": "^1.11" }, "require-dev": { "symplify/easy-coding-standard": "^11.5", - "phpstan/phpstan": "^1.10", - "phpunit/phpunit": "^10.2", - "rector/rector": "^0.17.6" + "phpstan/phpstan": "^2.1", + "phpunit/phpunit": "^11.2", + "rector/rector": "^2.1" }, "autoload": { "psr-4": { From 6f7e9211efc1ed682519728ca265150e592be10a Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 10 Oct 2025 22:48:54 +0200 Subject: [PATCH 06/16] static --- composer.json | 10 +++++----- ecs.php | 2 ++ phpstan.neon | 10 +++++++++- src/Finder/PhpFilesFinder.php | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 76f477e..a0c56e7 100644 --- a/composer.json +++ b/composer.json @@ -8,16 +8,16 @@ ], "require": { "php": "^8.2", - "symfony/console": "^6.3", + "symfony/console": "^6.4", "nikic/php-parser": "^5.6", - "illuminate/container": "^12.15", + "illuminate/container": "^12.33", "webmozart/assert": "^1.11" }, "require-dev": { - "symplify/easy-coding-standard": "^11.5", + "phpecs/phpecs": "^2.2", "phpstan/phpstan": "^2.1", - "phpunit/phpunit": "^11.2", - "rector/rector": "^2.1" + "phpunit/phpunit": "^11.5", + "rector/rector": "^2.2" }, "autoload": { "psr-4": { diff --git a/ecs.php b/ecs.php index ce3a451..60fd030 100644 --- a/ecs.php +++ b/ecs.php @@ -5,6 +5,8 @@ use Symplify\EasyCodingStandard\Config\ECSConfig; use Symplify\EasyCodingStandard\ValueObject\Set\SetList; +return ECSConfig::configure() + ->with return static function (ECSConfig $ecsConfig): void { $ecsConfig->paths([ __DIR__ . '/src', diff --git a/phpstan.neon b/phpstan.neon index 028820a..ce4501d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,14 @@ parameters: - level: max + level: 8 paths: + - bin - src - tests + + treatPhpDocTypesAsCertain: false + + ignoreErrors: + - + path: src/Finder/PhpFilesFinder.php + identifier: varTag.nativeType \ No newline at end of file diff --git a/src/Finder/PhpFilesFinder.php b/src/Finder/PhpFilesFinder.php index 4305cd0..dbf14f7 100644 --- a/src/Finder/PhpFilesFinder.php +++ b/src/Finder/PhpFilesFinder.php @@ -42,7 +42,7 @@ public function findPhpFiles(array $paths): array private function findFilesUsingGlob(string $directory): array { // Search for php files in the current directory - /** @var string[] $phpFiles */ + /** @var list $phpFiles */ $phpFiles = glob($directory . '/*.php'); // recursively search in subdirectories From 4e827e4eba8fdfc51020c98da5a83a2cffb71fbe Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 10 Oct 2025 22:50:19 +0200 Subject: [PATCH 07/16] dump nodes for PHP Parser 5.6 --- README.md | 387 +++++++++++++++--------------- snippet/nullable_type.php | 2 +- snippet/php_74/property_typed.php | 2 +- snippet/throw_stmt.php | 2 +- 4 files changed, 193 insertions(+), 200 deletions(-) diff --git a/README.md b/README.md index 5359e8b..3109994 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Here you can find overview of commonly used nodes and how to build PHP code from them. For all nodes, [check php-parser code](https://github.com/nikic/PHP-Parser/tree/master/lib/PhpParser/Node). -## `PhpParser\Node\Const_` +## `PhpParser\Node\ArrayItem` ### Example PHP Code @@ -11,29 +11,34 @@ Here you can find overview of commonly used nodes and how to build PHP code from declare(strict_types=1); -use PhpParser\Node\Const_; +use PhpParser\Node\Expr\ArrayItem; +use PhpParser\Node\Expr\Variable; use PhpParser\Node\Scalar\String_; -return new Const_('CONSTANT_NAME', new String_('default')); +$value = new Variable('Tom'); +$key = new String_('name'); + +return new ArrayItem($value, $key); ``` ↓ ```php -CONSTANT_NAME = 'default' +'name' => $Tom ```
### Public Properties - * `$name` - `/** @var Identifier Name */` + * `$key` - `/** @var null|Expr Key */` * `$value` - `/** @var Expr Value */` - * `$namespacedName` - `/** @var Name|null Namespaced name (if using NameResolver) */` + * `$byRef` - `/** @var bool Whether to assign by reference */` + * `$unpack` - `/** @var bool Whether to unpack the argument */`
-## `PhpParser\Node\Expr\ArrayDimFetch` +## `PhpParser\Node\ClosureUse` ### Example PHP Code @@ -42,32 +47,30 @@ CONSTANT_NAME = 'default' declare(strict_types=1); -use PhpParser\Node\Expr\ArrayDimFetch; +use PhpParser\Node\Expr\ClosureUse; use PhpParser\Node\Expr\Variable; -use PhpParser\Node\Scalar\LNumber; $variable = new Variable('variableName'); -$dimension = new LNumber(0); -return new ArrayDimFetch($variable, $dimension); +return new ClosureUse($variable); ``` ↓ ```php -$variableName[0] +$variableName ```
### Public Properties - * `$var` - `/** @var Expr Variable */` - * `$dim` - `/** @var null|Expr Array index / dim */` + * `$var` - `/** @var Expr\Variable Variable to use */` + * `$byRef` - `/** @var bool Whether to use by reference */`
-## `PhpParser\Node\Expr\ArrayItem` +## `PhpParser\Node\Const_` ### Example PHP Code @@ -76,30 +79,59 @@ $variableName[0] declare(strict_types=1); -use PhpParser\Node\Expr\ArrayItem; -use PhpParser\Node\Expr\Variable; +use PhpParser\Node\Const_; use PhpParser\Node\Scalar\String_; -$value = new Variable('Tom'); -$key = new String_('name'); - -return new ArrayItem($value, $key); +return new Const_('CONSTANT_NAME', new String_('default')); ``` ↓ ```php -'name' => $Tom +CONSTANT_NAME = 'default' ```
### Public Properties - * `$key` - `/** @var null|Expr Key */` + * `$name` - `/** @var Identifier Name */` * `$value` - `/** @var Expr Value */` - * `$byRef` - `/** @var bool Whether to assign by reference */` - * `$unpack` - `/** @var bool Whether to unpack the argument */` + * `$namespacedName` - `/** @var Name|null Namespaced name (if using NameResolver) */` + +
+ +## `PhpParser\Node\Expr\ArrayDimFetch` + +### Example PHP Code + +```php + + +### Public Properties + + * `$var` - `/** @var Expr Variable */` + * `$dim` - `/** @var null|Expr Array index / dim */`
@@ -128,14 +160,14 @@ return new Array_([$arrayItem]); ↓ ```php -array('name' => $Tom) +['name' => $Tom] ```
### Public Properties - * `$items` - `/** @var (ArrayItem|null)[] Items */` + * `$items` - `/** @var ArrayItem[] Items */`
@@ -166,11 +198,11 @@ fn() => 1 ### Public Properties - * `$static` - `/** @var bool */` - * `$byRef` - `/** @var bool */` + * `$static` - `/** @var bool Whether the closure is static */` + * `$byRef` - `/** @var bool Whether to return by reference */` * `$params` - `/** @var Node\Param[] */` * `$returnType` - `/** @var null|Node\Identifier|Node\Name|Node\ComplexType */` - * `$expr` - `/** @var Expr */` + * `$expr` - `/** @var Expr Expression body */` * `$attrGroups` - `/** @var Node\AttributeGroup[] */`
@@ -783,38 +815,6 @@ return new ClassConstFetch($class, 'SOME_CONSTANT');
-## `PhpParser\Node\Expr\ClosureUse` - -### Example PHP Code - -```php - - -### Public Properties - - * `$var` - `/** @var Expr\Variable Variable to use */` - * `$byRef` - `/** @var bool Whether to use by reference */` - -
- ## `PhpParser\Node\Expr\ConstFetch` ### Example PHP Code @@ -1084,7 +1084,7 @@ return new List_($arrayItems); ↓ ```php -list($variableName, $anotherVariableName) +[$variableName, $anotherVariableName] ```
@@ -1131,7 +1131,7 @@ match ($variableName) { ### Public Properties - * `$cond` - `/** @var Node\Expr */` + * `$cond` - `/** @var Node\Expr Condition */` * `$arms` - `/** @var MatchArm[] */`
@@ -1531,6 +1531,27 @@ throw 'some string'
+```php + + ### Public Properties * `$expr` - `/** @var Node\Expr Expression */` @@ -1594,8 +1615,8 @@ return new MatchArm($conds, $body); ### Public Properties - * `$conds` - `/** @var null|Node\Expr[] */` - * `$body` - `/** @var Node\Expr */` + * `$conds` - `/** @var null|list */` + * `$body` - ``
@@ -1623,11 +1644,11 @@ shortName ### Public Properties - * `$parts` - `/** - * @var string[] Parts of the name - * @deprecated Use getParts() instead + * `$name` - `/** + * @psalm-var non-empty-string + * @var string Name as string */` - * `$specialClassNames` - `` + * `$specialClassNames` - `/** @var array */`
@@ -1655,9 +1676,9 @@ return new FullyQualified('SomeNamespace\ShortName'); ### Public Properties - * `$parts` - `/** - * @var string[] Parts of the name - * @deprecated Use getParts() instead + * `$name` - `/** + * @psalm-var non-empty-string + * @var string Name as string */`
@@ -1673,7 +1694,7 @@ declare(strict_types=1); use PhpParser\Node\NullableType; -return new NullableType('SomeType'); +return new NullableType(new \PhpParser\Node\Name('SomeType')); ``` ↓ @@ -1722,12 +1743,13 @@ $variableName * `$variadic` - `/** @var bool Whether this is a variadic argument */` * `$var` - `/** @var Expr\Variable|Expr\Error Parameter variable */` * `$default` - `/** @var null|Expr Default value */` - * `$flags` - `/** @var int */` + * `$flags` - `/** @var int Optional visibility flags */` * `$attrGroups` - `/** @var AttributeGroup[] PHP attribute groups */` + * `$hooks` - `/** @var PropertyHook[] Property hooks for promoted properties */`
-## `PhpParser\Node\Scalar\DNumber` +## `PhpParser\Node\PropertyItem` ### Example PHP Code @@ -1736,26 +1758,36 @@ $variableName declare(strict_types=1); -use PhpParser\Node\Scalar\DNumber; +use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Stmt\Property; +use PhpParser\Node\Stmt\PropertyProperty; -return new DNumber(10.5); +$class = new Class_('ClassName'); + +$propertyProperty = new PropertyProperty('someProperty'); +$property = new Property(Class_::MODIFIER_PRIVATE, [$propertyProperty]); + +$class->stmts[] = $property; + +return $propertyProperty; ``` ↓ ```php -10.5 +$someProperty ```
### Public Properties - * `$value` - `/** @var float Number value */` + * `$name` - `/** @var Node\VarLikeIdentifier Name */` + * `$default` - `/** @var null|Node\Expr Default */`
-## `PhpParser\Node\Scalar\Encapsed` +## `PhpParser\Node\Scalar\Float_` ### Example PHP Code @@ -1764,27 +1796,26 @@ return new DNumber(10.5); declare(strict_types=1); -use PhpParser\Node\Expr\Variable; -use PhpParser\Node\Scalar\Encapsed; +use PhpParser\Node\Scalar\DNumber; -return new Encapsed([new Variable('variableName')]); +return new DNumber(10.5); ``` ↓ ```php -"{$variableName}" +10.5 ```
### Public Properties - * `$parts` - `/** @var Expr[] list of string parts */` + * `$value` - `/** @var float Number value */`
-## `PhpParser\Node\Scalar\LNumber` +## `PhpParser\Node\Scalar\Int_` ### Example PHP Code @@ -1812,6 +1843,35 @@ return new LNumber(1000);
+## `PhpParser\Node\Scalar\InterpolatedString` + +### Example PHP Code + +```php + + +### Public Properties + + * `$parts` - `/** @var (Expr|InterpolatedStringPart)[] list of string parts */` + +
+ ## `PhpParser\Node\Scalar\String_` ### Example PHP Code @@ -1837,7 +1897,39 @@ return new String_('some string'); ### Public Properties * `$value` - `/** @var string String value */` - * `$replacements` - `` + * `$replacements` - `/** @var array Escaped character to its decoded value */` + +
+ +## `PhpParser\Node\StaticVar` + +### Example PHP Code + +```php + + +### Public Properties + + * `$var` - `/** @var Expr\Variable Variable */` + * `$default` - `/** @var null|Node\Expr Default value */`
@@ -1930,7 +2022,7 @@ return $classMethod; ↓ ```php -private function methodName($paramName) : string +private function methodName($paramName): string { } ``` @@ -1981,7 +2073,7 @@ public function methodName() * `$returnType` - `/** @var null|Node\Identifier|Node\Name|Node\ComplexType Return type */` * `$stmts` - `/** @var Node\Stmt[]|null Statements */` * `$attrGroups` - `/** @var Node\AttributeGroup[] PHP attribute groups */` - * `$magicNames` - `` + * `$magicNames` - `/** @var array */`
@@ -2060,7 +2152,7 @@ final class ClassName extends \ParentClass ### Public Properties - * `$flags` - `/** @var int Type */` + * `$flags` - `/** @var int Modifiers */` * `$extends` - `/** @var null|Node\Name Name of extended class */` * `$implements` - `/** @var Node\Name[] Names of implemented interfaces */` * `$name` - `/** @var Node\Identifier|null Name */` @@ -2099,6 +2191,7 @@ const CONSTANT_IN_CLASS = 'default value'; ### Public Properties * `$consts` - `/** @var Node\Const_[] Constant declarations */` + * `$attrGroups` - `/** @var Node\AttributeGroup[] PHP attribute groups */`
@@ -2130,7 +2223,7 @@ declare (strict_types=1); ### Public Properties - * `$declares` - `/** @var DeclareDeclare[] List of declares */` + * `$declares` - `/** @var DeclareItem[] List of declares */` * `$stmts` - `/** @var Node\Stmt[]|null Statements */`
@@ -2454,7 +2547,7 @@ use PhpParser\Node\VarLikeIdentifier; $propertyProperty = new PropertyProperty(new VarLikeIdentifier('propertyName')); -return new Property(Class_::MODIFIER_PUBLIC, [$propertyProperty], [], 'string'); +return new Property(\PhpParser\Modifiers::PUBLIC, [$propertyProperty], [], new \PhpParser\Node\Identifier('string')); ``` ↓ @@ -2513,79 +2606,10 @@ public static $firstProperty, $secondProperty; ### Public Properties * `$flags` - `/** @var int Modifiers */` - * `$props` - `/** @var PropertyProperty[] Properties */` + * `$props` - `/** @var PropertyItem[] Properties */` * `$type` - `/** @var null|Identifier|Name|ComplexType Type declaration */` * `$attrGroups` - `/** @var Node\AttributeGroup[] PHP attribute groups */` - -
- -## `PhpParser\Node\Stmt\PropertyProperty` - -### Example PHP Code - -```php -stmts[] = $property; - -return $propertyProperty; -``` - -↓ - -```php -$someProperty -``` - -
- -### Public Properties - - * `$name` - `/** @var Node\VarLikeIdentifier Name */` - * `$default` - `/** @var null|Node\Expr Default */` - -
- -## `PhpParser\Node\Stmt\StaticVar` - -### Example PHP Code - -```php - - -### Public Properties - - * `$var` - `/** @var Expr\Variable Variable */` - * `$default` - `/** @var null|Node\Expr Default value */` + * `$hooks` - `/** @var Node\PropertyHook[] Property hooks */`
@@ -2658,37 +2682,6 @@ switch ($variableName) {
-## `PhpParser\Node\Stmt\Throw_` - -### Example PHP Code - -```php - - -### Public Properties - - * `$expr` - `/** @var Node\Expr Expression */` - -
- ## `PhpParser\Node\Stmt\TraitUse` ### Example PHP Code @@ -2894,8 +2887,8 @@ use UsedNamespace; ### Public Properties - * `$type` - `/** @var int Type of alias */` - * `$uses` - `/** @var UseUse[] Aliases */` + * `$type` - `/** @var self::TYPE_* Type of alias */` + * `$uses` - `/** @var UseItem[] Aliases */`
diff --git a/snippet/nullable_type.php b/snippet/nullable_type.php index 4adf3a0..3a6cc97 100644 --- a/snippet/nullable_type.php +++ b/snippet/nullable_type.php @@ -4,4 +4,4 @@ use PhpParser\Node\NullableType; -return new NullableType('SomeType'); +return new NullableType(new \PhpParser\Node\Name('SomeType')); diff --git a/snippet/php_74/property_typed.php b/snippet/php_74/property_typed.php index 7961ea3..dba4497 100644 --- a/snippet/php_74/property_typed.php +++ b/snippet/php_74/property_typed.php @@ -9,4 +9,4 @@ $propertyProperty = new PropertyProperty(new VarLikeIdentifier('propertyName')); -return new Property(Class_::MODIFIER_PUBLIC, [$propertyProperty], [], 'string'); +return new Property(\PhpParser\Modifiers::PUBLIC, [$propertyProperty], [], new \PhpParser\Node\Identifier('string')); diff --git a/snippet/throw_stmt.php b/snippet/throw_stmt.php index 299fa06..0942c05 100644 --- a/snippet/throw_stmt.php +++ b/snippet/throw_stmt.php @@ -2,8 +2,8 @@ declare(strict_types=1); +use PhpParser\Node\Expr\Throw_; use PhpParser\Node\Scalar\String_; -use PhpParser\Node\Stmt\Throw_; $string = new String_('some string'); From 48d0c51ce0bee6e19a321b8a33b2e29d72afc5e5 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 11 Oct 2025 07:50:43 +0200 Subject: [PATCH 08/16] newer php --- .github/workflows/code_analysis.yaml | 8 ++-- bin/console | 4 -- bin/console.php | 22 ---------- bin/dump-nodes.php | 28 +++++++++++++ composer.json | 10 ++--- ecs.php | 16 ++----- snippet/nullable_type.php | 3 +- snippet/php_74/property_typed.php | 4 +- src/Command/DumpNodesCommand.php | 44 -------------------- src/DependencyInjection/ContainerFactory.php | 29 ------------- src/NodeCodeSampleProvider.php | 5 +-- src/Sorter/NodeInfoSorter.php | 5 ++- tests/NodeInfosFactoryTest.php | 16 +++---- 13 files changed, 58 insertions(+), 136 deletions(-) delete mode 100755 bin/console delete mode 100644 bin/console.php create mode 100644 bin/dump-nodes.php delete mode 100644 src/Command/DumpNodesCommand.php delete mode 100644 src/DependencyInjection/ContainerFactory.php diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index 167ad19..9b4e2d5 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -15,15 +15,15 @@ jobs: - name: 'Bare Run' - run: bin/console + run: bin/dump-nodes.php - name: 'ECS' - run: composer check-cs + run: vendor/bin/ecs - name: 'PHPStan' - run: composer phpstan + run: vendor/bin/phpstan name: ${{ matrix.actions.name }} runs-on: ubuntu-latest @@ -34,7 +34,7 @@ jobs: - uses: shivammathur/setup-php@v2 with: - php-version: 8.1 + php-version: 8.3 coverage: none - uses: "ramsey/composer-install@v1" diff --git a/bin/console b/bin/console deleted file mode 100755 index e7f0299..0000000 --- a/bin/console +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env php -create(); - -/** @var Application $application */ -$application = $container->make(Application::class); - -$input = new ArgvInput(); -$output = new ConsoleOutput(); - -$exitCode = $application->run($input, $output); -exit($exitCode); diff --git a/bin/dump-nodes.php b/bin/dump-nodes.php new file mode 100644 index 0000000..183dcda --- /dev/null +++ b/bin/dump-nodes.php @@ -0,0 +1,28 @@ +create(); +$printedContent = $markdownNodeInfosPrinter->print($nodeInfos); + +file_put_contents(getcwd() . '/README.md', $printedContent); + +echo sprintf('Documentation for %d nodes was generated to README.md' . PHP_EOL, count($nodeInfos)); + +// success +exit(0); diff --git a/composer.json b/composer.json index a0c56e7..8ab859d 100644 --- a/composer.json +++ b/composer.json @@ -7,17 +7,15 @@ "bin/console.php" ], "require": { - "php": "^8.2", - "symfony/console": "^6.4", + "php": "^8.3", "nikic/php-parser": "^5.6", - "illuminate/container": "^12.33", "webmozart/assert": "^1.11" }, "require-dev": { - "phpecs/phpecs": "^2.2", + "symplify/easy-coding-standard": "^12.6", "phpstan/phpstan": "^2.1", - "phpunit/phpunit": "^11.5", - "rector/rector": "^2.2" + "phpunit/phpunit": "^12.4", + "rector/rector": "^2.2.2" }, "autoload": { "psr-4": { diff --git a/ecs.php b/ecs.php index 60fd030..4629829 100644 --- a/ecs.php +++ b/ecs.php @@ -3,19 +3,11 @@ declare(strict_types=1); use Symplify\EasyCodingStandard\Config\ECSConfig; -use Symplify\EasyCodingStandard\ValueObject\Set\SetList; return ECSConfig::configure() - ->with -return static function (ECSConfig $ecsConfig): void { - $ecsConfig->paths([ + ->withPaths([ + __DIR__ . '/bin', __DIR__ . '/src', __DIR__ . '/tests', - ]); - - $ecsConfig->sets([ - SetList::STRICT, - SetList::COMMON, - SetList::PSR_12, - ]); -}; + ]) + ->withPreparedSets(symplify: true, common: true, psr12: true); diff --git a/snippet/nullable_type.php b/snippet/nullable_type.php index 3a6cc97..d2418f7 100644 --- a/snippet/nullable_type.php +++ b/snippet/nullable_type.php @@ -2,6 +2,7 @@ declare(strict_types=1); +use PhpParser\Node\Name; use PhpParser\Node\NullableType; -return new NullableType(new \PhpParser\Node\Name('SomeType')); +return new NullableType(new Name('SomeType')); diff --git a/snippet/php_74/property_typed.php b/snippet/php_74/property_typed.php index dba4497..cb8164a 100644 --- a/snippet/php_74/property_typed.php +++ b/snippet/php_74/property_typed.php @@ -2,11 +2,11 @@ declare(strict_types=1); -use PhpParser\Node\Stmt\Class_; +use PhpParser\Modifiers; use PhpParser\Node\Stmt\Property; use PhpParser\Node\Stmt\PropertyProperty; use PhpParser\Node\VarLikeIdentifier; $propertyProperty = new PropertyProperty(new VarLikeIdentifier('propertyName')); -return new Property(\PhpParser\Modifiers::PUBLIC, [$propertyProperty], [], new \PhpParser\Node\Identifier('string')); +return new Property(Modifiers::PUBLIC, [$propertyProperty], [], new \PhpParser\Node\Identifier('string')); diff --git a/src/Command/DumpNodesCommand.php b/src/Command/DumpNodesCommand.php deleted file mode 100644 index 422c7a7..0000000 --- a/src/Command/DumpNodesCommand.php +++ /dev/null @@ -1,44 +0,0 @@ -setName('dump-nodes'); - $this->setDescription('Dump nodes overview'); - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { - $nodeInfos = $this->nodeInfosFactory->create(); - $printedContent = $this->markdownNodeInfosPrinter->print($nodeInfos); - - file_put_contents(getcwd() . '/README.md', $printedContent); - - $output->write(PHP_EOL); - - $output->writeln(sprintf( - 'Documentation for %d nodes was generated to README.md' . PHP_EOL, - count($nodeInfos), - )); - - return self::SUCCESS; - } -} diff --git a/src/DependencyInjection/ContainerFactory.php b/src/DependencyInjection/ContainerFactory.php deleted file mode 100644 index 6e9412f..0000000 --- a/src/DependencyInjection/ContainerFactory.php +++ /dev/null @@ -1,29 +0,0 @@ -singleton(Application::class, function (Container $container) { - $application = new Application(); - - /** @var DumpNodesCommand $dumpNodesCommand */ - $dumpNodesCommand = $container->make(DumpNodesCommand::class); - $application->add($dumpNodesCommand); - - return $application; - }); - - return $container; - } -} diff --git a/src/NodeCodeSampleProvider.php b/src/NodeCodeSampleProvider.php index c4ab3c9..05b4e26 100644 --- a/src/NodeCodeSampleProvider.php +++ b/src/NodeCodeSampleProvider.php @@ -41,10 +41,7 @@ public function provide(): array $printedContent = $this->standard->prettyPrint([$node]); - $nodeCodeSamplesByNodeClass[$nodeClass][] = new NodeCodeSample( - $fileContents, - $printedContent - ); + $nodeCodeSamplesByNodeClass[$nodeClass][] = new NodeCodeSample($fileContents, $printedContent); } ksort($nodeCodeSamplesByNodeClass); diff --git a/src/Sorter/NodeInfoSorter.php b/src/Sorter/NodeInfoSorter.php index f933bd4..4c74983 100644 --- a/src/Sorter/NodeInfoSorter.php +++ b/src/Sorter/NodeInfoSorter.php @@ -14,7 +14,10 @@ final class NodeInfoSorter */ public function sortNodeInfosByClass(array $nodeInfos): array { - usort($nodeInfos, fn (NodeInfo $firstNodeInfo, NodeInfo $secondNodeInfo): int => $firstNodeInfo->getClass() <=> $secondNodeInfo->getClass()); + usort( + $nodeInfos, + fn (NodeInfo $firstNodeInfo, NodeInfo $secondNodeInfo): int => $firstNodeInfo->getClass() <=> $secondNodeInfo->getClass() + ); return $nodeInfos; } diff --git a/tests/NodeInfosFactoryTest.php b/tests/NodeInfosFactoryTest.php index b818de1..08921be 100644 --- a/tests/NodeInfosFactoryTest.php +++ b/tests/NodeInfosFactoryTest.php @@ -4,23 +4,25 @@ namespace Rector\PhpParserNodesDocs\Tests; +use PhpParser\PrettyPrinter\Standard; use PHPUnit\Framework\TestCase; -use Rector\PhpParserNodesDocs\DependencyInjection\ContainerFactory; +use Rector\PhpParserNodesDocs\Finder\PhpFilesFinder; +use Rector\PhpParserNodesDocs\NodeCodeSampleProvider; use Rector\PhpParserNodesDocs\NodeInfosFactory; +use Rector\PhpParserNodesDocs\Sorter\NodeInfoSorter; final class NodeInfosFactoryTest extends TestCase { public function test(): void { - $containerFactory = new ContainerFactory(); - $container = $containerFactory->create(); - - /** @var NodeInfosFactory $nodeInfosFactory */ - $nodeInfosFactory = $container->make(NodeInfosFactory::class); + $nodeInfosFactory = new NodeInfosFactory( + new NodeCodeSampleProvider(new Standard(), new PhpFilesFinder()), + new NodeInfoSorter() + ); $nodeInfos = $nodeInfosFactory->create(); $nodeInfoCount = count($nodeInfos); - $this->assertGreaterThan(50, $nodeInfoCount); + $this->assertGreaterThan(78, $nodeInfoCount); } } From 1183a70928a3ec81212c49946ba19aae69f72c5b Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 11 Oct 2025 08:34:38 +0200 Subject: [PATCH 09/16] run on deprecatdions --- composer.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8ab859d..30f3991 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,9 @@ "symplify/easy-coding-standard": "^12.6", "phpstan/phpstan": "^2.1", "phpunit/phpunit": "^12.4", - "rector/rector": "^2.2.2" + "rector/rector": "^2.2.2", + "phpstan/phpstan-deprecation-rules": "^2.0", + "phpstan/extension-installer": "^1.4" }, "autoload": { "psr-4": { @@ -32,5 +34,10 @@ "fix-cs": "vendor/bin/ecs check --fix --ansi", "phpstan": "vendor/bin/phpstan analyse --ansi", "build": "bin/console dump-nodes" + }, + "config": { + "allow-plugins": { + "phpstan/extension-installer": true + } } } From b01c17e84b8a056cf1505a460923a15a4f4f621e Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 11 Oct 2025 08:35:25 +0200 Subject: [PATCH 10/16] cs --- .github/workflows/code_analysis.yaml | 2 +- README.md | 9 +++++---- bin/dump-nodes.php | 0 src/Printer/MarkdownNodeInfosPrinter.php | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) mode change 100644 => 100755 bin/dump-nodes.php diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index 9b4e2d5..10d6763 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -15,7 +15,7 @@ jobs: - name: 'Bare Run' - run: bin/dump-nodes.php + run: php bin/dump-nodes.php - name: 'ECS' diff --git a/README.md b/README.md index 3109994..530c779 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Node Overview +# Node Overview for PHP-Parser 5.6 (2025) Here you can find overview of commonly used nodes and how to build PHP code from them. For all nodes, [check php-parser code](https://github.com/nikic/PHP-Parser/tree/master/lib/PhpParser/Node). @@ -1692,9 +1692,10 @@ return new FullyQualified('SomeNamespace\ShortName'); declare(strict_types=1); +use PhpParser\Node\Name; use PhpParser\Node\NullableType; -return new NullableType(new \PhpParser\Node\Name('SomeType')); +return new NullableType(new Name('SomeType')); ``` ↓ @@ -2540,14 +2541,14 @@ labelName: declare(strict_types=1); -use PhpParser\Node\Stmt\Class_; +use PhpParser\Modifiers; use PhpParser\Node\Stmt\Property; use PhpParser\Node\Stmt\PropertyProperty; use PhpParser\Node\VarLikeIdentifier; $propertyProperty = new PropertyProperty(new VarLikeIdentifier('propertyName')); -return new Property(\PhpParser\Modifiers::PUBLIC, [$propertyProperty], [], new \PhpParser\Node\Identifier('string')); +return new Property(Modifiers::PUBLIC, [$propertyProperty], [], new \PhpParser\Node\Identifier('string')); ``` ↓ diff --git a/bin/dump-nodes.php b/bin/dump-nodes.php old mode 100644 new mode 100755 diff --git a/src/Printer/MarkdownNodeInfosPrinter.php b/src/Printer/MarkdownNodeInfosPrinter.php index a49f6c2..245edae 100644 --- a/src/Printer/MarkdownNodeInfosPrinter.php +++ b/src/Printer/MarkdownNodeInfosPrinter.php @@ -15,7 +15,7 @@ final class MarkdownNodeInfosPrinter public function print(array $nodeInfos): string { $contentLines = []; - $contentLines[] = '# Node Overview'; + $contentLines[] = '# Node Overview for PHP-Parser 5.6 (2025)'; $contentLines[] = 'Here you can find overview of commonly used nodes and how to build PHP code from them. For all nodes, [check php-parser code](https://github.com/nikic/PHP-Parser/tree/master/lib/PhpParser/Node).'; foreach ($nodeInfos as $nodeInfo) { From 5405484fa568d00bab2db13cfd56bea867c66cd4 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 11 Oct 2025 08:46:58 +0200 Subject: [PATCH 11/16] misc --- bin/dump-nodes.php | 10 ++----- composer.json | 3 +- phpstan.neon | 6 ---- src/Finder/PhpFilesFinder.php | 52 +++++++--------------------------- src/NodeCodeSampleProvider.php | 21 +++++++------- tests/NodeInfosFactoryTest.php | 7 +---- 6 files changed, 27 insertions(+), 72 deletions(-) diff --git a/bin/dump-nodes.php b/bin/dump-nodes.php index 183dcda..a8ecb86 100755 --- a/bin/dump-nodes.php +++ b/bin/dump-nodes.php @@ -2,8 +2,6 @@ declare(strict_types=1); -use PhpParser\PrettyPrinter\Standard; -use Rector\PhpParserNodesDocs\Finder\PhpFilesFinder; use Rector\PhpParserNodesDocs\NodeCodeSampleProvider; use Rector\PhpParserNodesDocs\NodeInfosFactory; use Rector\PhpParserNodesDocs\Printer\MarkdownNodeInfosPrinter; @@ -12,17 +10,15 @@ require_once __DIR__ . '/../vendor/autoload.php'; $markdownNodeInfosPrinter = new MarkdownNodeInfosPrinter(); -$nodeInfosFactory = new NodeInfosFactory( - new NodeCodeSampleProvider(new Standard(), new PhpFilesFinder()), - new NodeInfoSorter() -); + +$nodeInfosFactory = new NodeInfosFactory(new NodeCodeSampleProvider(), new NodeInfoSorter()); $nodeInfos = $nodeInfosFactory->create(); $printedContent = $markdownNodeInfosPrinter->print($nodeInfos); file_put_contents(getcwd() . '/README.md', $printedContent); -echo sprintf('Documentation for %d nodes was generated to README.md' . PHP_EOL, count($nodeInfos)); +echo sprintf('Documentation for %d nodes was generated to README.md' . PHP_EOL . PHP_EOL, count($nodeInfos)); // success exit(0); diff --git a/composer.json b/composer.json index 30f3991..cd697c9 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,8 @@ "require": { "php": "^8.3", "nikic/php-parser": "^5.6", - "webmozart/assert": "^1.11" + "webmozart/assert": "^1.11", + "symfony/finder": "^7.3" }, "require-dev": { "symplify/easy-coding-standard": "^12.6", diff --git a/phpstan.neon b/phpstan.neon index ce4501d..8c52d23 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -5,10 +5,4 @@ parameters: - bin - src - tests - treatPhpDocTypesAsCertain: false - - ignoreErrors: - - - path: src/Finder/PhpFilesFinder.php - identifier: varTag.nativeType \ No newline at end of file diff --git a/src/Finder/PhpFilesFinder.php b/src/Finder/PhpFilesFinder.php index dbf14f7..af4b032 100644 --- a/src/Finder/PhpFilesFinder.php +++ b/src/Finder/PhpFilesFinder.php @@ -4,57 +4,25 @@ namespace Rector\PhpParserNodesDocs\Finder; +use Symfony\Component\Finder\Finder; +use Symfony\Component\Finder\SplFileInfo; use Webmozart\Assert\Assert; final class PhpFilesFinder { /** * @param string[] $paths - * @return string[] + * @return SplFileInfo[] */ - public function findPhpFiles(array $paths): array + public static function find(array $paths): array { - Assert::allFileExists($paths); + Assert::allString($paths); - // fallback to config paths - $filePaths = []; + $finder = Finder::create() + ->name('*.php') + ->sortByName() + ->in($paths); - foreach ($paths as $path) { - if (is_file($path)) { - $filePaths[] = $path; - } else { - $currentFilePaths = $this->findFilesUsingGlob($path); - $filePaths = array_merge($filePaths, $currentFilePaths); - } - } - - sort($filePaths); - - Assert::allString($filePaths); - Assert::allFileExists($filePaths); - - return $filePaths; - } - - /** - * @return string[] - */ - private function findFilesUsingGlob(string $directory): array - { - // Search for php files in the current directory - /** @var list $phpFiles */ - $phpFiles = glob($directory . '/*.php'); - - // recursively search in subdirectories - - /** @var string[] $subdirectories */ - $subdirectories = glob($directory . '/*', GLOB_ONLYDIR); - - foreach ($subdirectories as $subdirectory) { - // Merge the results from subdirectories - $phpFiles = array_merge($phpFiles, $this->findFilesUsingGlob($subdirectory)); - } - - return $phpFiles; + return iterator_to_array($finder->getIterator()); } } diff --git a/src/NodeCodeSampleProvider.php b/src/NodeCodeSampleProvider.php index 05b4e26..0f52040 100644 --- a/src/NodeCodeSampleProvider.php +++ b/src/NodeCodeSampleProvider.php @@ -12,10 +12,11 @@ final class NodeCodeSampleProvider { + private Standard $standardPrinter; + public function __construct( - private readonly Standard $standard, - private readonly PhpFilesFinder $phpFilesFinder, ) { + $this->standardPrinter = new Standard(); } /** @@ -23,23 +24,23 @@ public function __construct( */ public function provide(): array { - $phpFilePaths = $this->phpFilesFinder->findPhpFiles([__DIR__ . '/../snippet']); + $phpFileInfos = PhpFilesFinder::find([__DIR__ . '/../snippet']); $nodeCodeSamplesByNodeClass = []; - foreach ($phpFilePaths as $phpFilePath) { + foreach ($phpFileInfos as $phpFileInfo) { /** @var Node $node */ - $node = include $phpFilePath; - - /** @var string $fileContents */ - $fileContents = file_get_contents($phpFilePath); + $node = include $phpFileInfo->getRealPath(); - $errorMessage = sprintf('The "%s" file must return "%s" instance ', $phpFilePath, Node::class); + $errorMessage = sprintf('The "%s" file must return "%s" instance ', $phpFileInfo, Node::class); Assert::isInstanceOf($node, Node::class, $errorMessage); + /** @var string $fileContents */ + $fileContents = $phpFileInfo->getContents(); + $nodeClass = $node::class; - $printedContent = $this->standard->prettyPrint([$node]); + $printedContent = $this->standardPrinter->prettyPrint([$node]); $nodeCodeSamplesByNodeClass[$nodeClass][] = new NodeCodeSample($fileContents, $printedContent); } diff --git a/tests/NodeInfosFactoryTest.php b/tests/NodeInfosFactoryTest.php index 08921be..3e0e16f 100644 --- a/tests/NodeInfosFactoryTest.php +++ b/tests/NodeInfosFactoryTest.php @@ -4,9 +4,7 @@ namespace Rector\PhpParserNodesDocs\Tests; -use PhpParser\PrettyPrinter\Standard; use PHPUnit\Framework\TestCase; -use Rector\PhpParserNodesDocs\Finder\PhpFilesFinder; use Rector\PhpParserNodesDocs\NodeCodeSampleProvider; use Rector\PhpParserNodesDocs\NodeInfosFactory; use Rector\PhpParserNodesDocs\Sorter\NodeInfoSorter; @@ -15,10 +13,7 @@ final class NodeInfosFactoryTest extends TestCase { public function test(): void { - $nodeInfosFactory = new NodeInfosFactory( - new NodeCodeSampleProvider(new Standard(), new PhpFilesFinder()), - new NodeInfoSorter() - ); + $nodeInfosFactory = new NodeInfosFactory(new NodeCodeSampleProvider(), new NodeInfoSorter()); $nodeInfos = $nodeInfosFactory->create(); From b36dae5b2539836b09194203c830439892afe12a Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 11 Oct 2025 08:54:46 +0200 Subject: [PATCH 12/16] add number and int --- README.md | 36 ++++++++++++++++++++++++++++++++++++ snippet/float_.php | 7 +++++++ snippet/int_.php | 7 +++++++ 3 files changed, 50 insertions(+) create mode 100644 snippet/float_.php create mode 100644 snippet/int_.php diff --git a/README.md b/README.md index 530c779..ad5359c 100644 --- a/README.md +++ b/README.md @@ -1810,6 +1810,24 @@ return new DNumber(10.5);
+```php + + ### Public Properties * `$value` - `/** @var float Number value */` @@ -1825,6 +1843,24 @@ return new DNumber(10.5); declare(strict_types=1); +use PhpParser\Node\Scalar\Int_; + +return new Int_(100); +``` + +↓ + +```php +100 +``` + +
+ +```php + Date: Sat, 11 Oct 2025 08:59:50 +0200 Subject: [PATCH 13/16] update class to modifier --- README.md | 167 +++++++++--------- ecs.php | 1 + phpstan.neon | 2 + snippet/alias.php | 4 +- snippet/block.php | 13 ++ snippet/class_const.php | 3 +- snippet/class_final.php | 2 +- snippet/class_method.php | 3 +- ...lass_method_with_param_and_return_type.php | 3 +- snippet/class_method_with_stmts.php | 3 +- snippet/class_with_property.php | 8 +- snippet/d_number.php | 7 - snippet/final_class_with_parent_class.php | 2 +- snippet/float_.php | 2 +- snippet/int_.php | 2 +- snippet/l_number.php | 7 - snippet/magic_property.php | 7 + snippet/property.php | 3 +- snippet/property_double.php | 4 +- 19 files changed, 125 insertions(+), 118 deletions(-) create mode 100644 snippet/block.php delete mode 100644 snippet/d_number.php delete mode 100644 snippet/l_number.php create mode 100644 snippet/magic_property.php diff --git a/README.md b/README.md index ad5359c..cadcca1 100644 --- a/README.md +++ b/README.md @@ -1750,44 +1750,6 @@ $variableName
-## `PhpParser\Node\PropertyItem` - -### Example PHP Code - -```php -stmts[] = $property; - -return $propertyProperty; -``` - -↓ - -```php -$someProperty -``` - -
- -### Public Properties - - * `$name` - `/** @var Node\VarLikeIdentifier Name */` - * `$default` - `/** @var null|Node\Expr Default */` - -
- ## `PhpParser\Node\Scalar\Float_` ### Example PHP Code @@ -1797,24 +1759,6 @@ $someProperty declare(strict_types=1); -use PhpParser\Node\Scalar\DNumber; - -return new DNumber(10.5); -``` - -↓ - -```php -10.5 -``` - -
- -```php - +### Public Properties + + * `$value` - `/** @var int Number value */` + +
+ +## `PhpParser\Node\Scalar\InterpolatedString` + +### Example PHP Code + ```php ### Public Properties - * `$value` - `/** @var int Number value */` + * `$parts` - `/** @var (Expr|InterpolatedStringPart)[] list of string parts */`
-## `PhpParser\Node\Scalar\InterpolatedString` +## `PhpParser\Node\Scalar\MagicConst\Property` ### Example PHP Code @@ -1889,23 +1844,20 @@ return new LNumber(1000); declare(strict_types=1); -use PhpParser\Node\Expr\Variable; -use PhpParser\Node\Scalar\Encapsed; +use PhpParser\Node\Scalar\MagicConst\Property; -return new Encapsed([new Variable('variableName')]); +return new Property(); ``` ↓ ```php -"{$variableName}" +__PROPERTY__ ```
-### Public Properties - * `$parts` - `/** @var (Expr|InterpolatedStringPart)[] list of string parts */`
@@ -1981,13 +1933,12 @@ declare(strict_types=1); use PhpParser\Node\Const_; use PhpParser\Node\Scalar\String_; -use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassConst; $defaultValue = new String_('default value'); $const = new Const_('SOME_CLASS_CONSTANT', $defaultValue); -return new ClassConst([$const], Class_::MODIFIER_PUBLIC); +return new ClassConst([$const], \PhpParser\Modifiers::PUBLIC); ``` ↓ @@ -2016,11 +1967,10 @@ public const SOME_CLASS_CONSTANT = 'default value'; declare(strict_types=1); -use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; $classMethod = new ClassMethod('methodName'); -$classMethod->flags = Class_::MODIFIER_PUBLIC; +$classMethod->flags = \PhpParser\Modifiers::PUBLIC; return $classMethod; ``` @@ -2043,11 +1993,10 @@ declare(strict_types=1); use PhpParser\Node\Expr\Variable; use PhpParser\Node\Identifier; use PhpParser\Node\Param; -use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; $classMethod = new ClassMethod('methodName'); -$classMethod->flags = Class_::MODIFIER_PRIVATE; +$classMethod->flags = \PhpParser\Modifiers::PRIVATE; $param = new Param(new Variable('paramName')); $classMethod->params = [$param]; @@ -2074,12 +2023,11 @@ declare(strict_types=1); use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Scalar\LNumber; -use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Expression; $classMethod = new ClassMethod('methodName'); -$classMethod->flags = Class_::MODIFIER_PUBLIC; +$classMethod->flags = \PhpParser\Modifiers::PUBLIC; $variable = new Variable('some'); $number = new LNumber(10000); @@ -2146,7 +2094,7 @@ declare(strict_types=1); use PhpParser\Node\Stmt\Class_; $class = new Class_('ClassName'); -$class->flags |= Class_::MODIFIER_FINAL; +$class->flags |= \PhpParser\Modifiers::FINAL; return $class; ``` @@ -2166,12 +2114,44 @@ final class ClassName declare(strict_types=1); +use PhpParser\Modifiers; +use PhpParser\Node\Identifier; +use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Stmt\Property; +use PhpParser\Node\Stmt\PropertyProperty; + +$class = new Class_(new Identifier('ClassName')); + +$propertyProperty = new PropertyProperty('someProperty'); +$property = new Property(Modifiers::PRIVATE, [$propertyProperty]); + +$class->stmts[] = $property; + +return $class; +``` + +↓ + +```php +class ClassName +{ + private $someProperty; +} +``` + +
+ +```php +flags = Class_::MODIFIER_FINAL; +$class->flags = \PhpParser\Modifiers::FINAL; $class->extends = new FullyQualified('ParentClass'); return $class; @@ -2600,14 +2580,13 @@ public string $propertyName; declare(strict_types=1); -use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\Property; use PhpParser\Node\Stmt\PropertyProperty; use PhpParser\Node\VarLikeIdentifier; $propertyProperty = new PropertyProperty(new VarLikeIdentifier('propertyName')); -return new Property(Class_::MODIFIER_PUBLIC, [$propertyProperty]); +return new Property(\PhpParser\Modifiers::PUBLIC, [$propertyProperty]); ``` ↓ @@ -2623,13 +2602,13 @@ public $propertyName; declare(strict_types=1); -use PhpParser\Node\Stmt\Class_; +use PhpParser\Modifiers; use PhpParser\Node\Stmt\Property; use PhpParser\Node\Stmt\PropertyProperty; $propertyProperties = [new PropertyProperty('firstProperty'), new PropertyProperty('secondProperty')]; -return new Property(Class_::MODIFIER_STATIC | Class_::MODIFIER_PUBLIC, $propertyProperties); +return new Property(Modifiers::STATIC | Modifiers::PUBLIC, $propertyProperties); ``` ↓ @@ -2758,13 +2737,35 @@ use \TraitName; declare(strict_types=1); +use PhpParser\Modifiers; +use PhpParser\Node\Name\FullyQualified; +use PhpParser\Node\Stmt\TraitUseAdaptation\Alias; + +$traitFullyQualified = new FullyQualified('TraitName'); + +return new Alias($traitFullyQualified, 'method', Modifiers::PUBLIC, 'aliasedMethod'); +``` + +↓ + +```php +\TraitName::method as public aliasedMethod; +``` + +
+ +```php +withPreparedSets(symplify: true, common: true, psr12: true); diff --git a/phpstan.neon b/phpstan.neon index 8c52d23..7b46b98 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -5,4 +5,6 @@ parameters: - bin - src - tests + - snippet + treatPhpDocTypesAsCertain: false diff --git a/snippet/alias.php b/snippet/alias.php index e315ff9..a978ca6 100644 --- a/snippet/alias.php +++ b/snippet/alias.php @@ -2,10 +2,10 @@ declare(strict_types=1); +use PhpParser\Modifiers; use PhpParser\Node\Name\FullyQualified; -use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\TraitUseAdaptation\Alias; $traitFullyQualified = new FullyQualified('TraitName'); -return new Alias($traitFullyQualified, 'method', Class_::MODIFIER_PUBLIC, 'aliasedMethod'); +return new Alias($traitFullyQualified, 'method', Modifiers::PUBLIC, 'aliasedMethod'); diff --git a/snippet/block.php b/snippet/block.php new file mode 100644 index 0000000..26a6c2f --- /dev/null +++ b/snippet/block.php @@ -0,0 +1,13 @@ +flags |= Class_::MODIFIER_FINAL; +$class->flags |= \PhpParser\Modifiers::FINAL; return $class; diff --git a/snippet/class_method.php b/snippet/class_method.php index 863937c..ff80054 100644 --- a/snippet/class_method.php +++ b/snippet/class_method.php @@ -2,10 +2,9 @@ declare(strict_types=1); -use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; $classMethod = new ClassMethod('methodName'); -$classMethod->flags = Class_::MODIFIER_PUBLIC; +$classMethod->flags = \PhpParser\Modifiers::PUBLIC; return $classMethod; diff --git a/snippet/class_method_with_param_and_return_type.php b/snippet/class_method_with_param_and_return_type.php index 50597df..34816db 100644 --- a/snippet/class_method_with_param_and_return_type.php +++ b/snippet/class_method_with_param_and_return_type.php @@ -5,11 +5,10 @@ use PhpParser\Node\Expr\Variable; use PhpParser\Node\Identifier; use PhpParser\Node\Param; -use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; $classMethod = new ClassMethod('methodName'); -$classMethod->flags = Class_::MODIFIER_PRIVATE; +$classMethod->flags = \PhpParser\Modifiers::PRIVATE; $param = new Param(new Variable('paramName')); $classMethod->params = [$param]; diff --git a/snippet/class_method_with_stmts.php b/snippet/class_method_with_stmts.php index 9f6513b..5107f27 100644 --- a/snippet/class_method_with_stmts.php +++ b/snippet/class_method_with_stmts.php @@ -5,12 +5,11 @@ use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Scalar\LNumber; -use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Expression; $classMethod = new ClassMethod('methodName'); -$classMethod->flags = Class_::MODIFIER_PUBLIC; +$classMethod->flags = \PhpParser\Modifiers::PUBLIC; $variable = new Variable('some'); $number = new LNumber(10000); diff --git a/snippet/class_with_property.php b/snippet/class_with_property.php index 82d58d1..02bc830 100644 --- a/snippet/class_with_property.php +++ b/snippet/class_with_property.php @@ -2,15 +2,17 @@ declare(strict_types=1); +use PhpParser\Modifiers; +use PhpParser\Node\Identifier; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\Property; use PhpParser\Node\Stmt\PropertyProperty; -$class = new Class_('ClassName'); +$class = new Class_(new Identifier('ClassName')); $propertyProperty = new PropertyProperty('someProperty'); -$property = new Property(Class_::MODIFIER_PRIVATE, [$propertyProperty]); +$property = new Property(Modifiers::PRIVATE, [$propertyProperty]); $class->stmts[] = $property; -return $propertyProperty; +return $class; diff --git a/snippet/d_number.php b/snippet/d_number.php deleted file mode 100644 index bce611a..0000000 --- a/snippet/d_number.php +++ /dev/null @@ -1,7 +0,0 @@ -flags = Class_::MODIFIER_FINAL; +$class->flags = \PhpParser\Modifiers::FINAL; $class->extends = new FullyQualified('ParentClass'); return $class; diff --git a/snippet/float_.php b/snippet/float_.php index 0ff35c0..df216e6 100644 --- a/snippet/float_.php +++ b/snippet/float_.php @@ -4,4 +4,4 @@ use PhpParser\Node\Scalar\Float_; -return new Float_(100); \ No newline at end of file +return new Float_(100); diff --git a/snippet/int_.php b/snippet/int_.php index f6dcacd..07441cd 100644 --- a/snippet/int_.php +++ b/snippet/int_.php @@ -4,4 +4,4 @@ use PhpParser\Node\Scalar\Int_; -return new Int_(100); \ No newline at end of file +return new Int_(100); diff --git a/snippet/l_number.php b/snippet/l_number.php deleted file mode 100644 index 7e8395c..0000000 --- a/snippet/l_number.php +++ /dev/null @@ -1,7 +0,0 @@ - Date: Sat, 11 Oct 2025 09:12:59 +0200 Subject: [PATCH 14/16] add property hook --- README.md | 94 ++++++++++++++++++++++++-------- snippet/float_.php | 2 +- snippet/php_84/property_hook.php | 19 +++++++ src/NodeCodeSampleProvider.php | 2 +- 4 files changed, 91 insertions(+), 26 deletions(-) create mode 100644 snippet/php_84/property_hook.php diff --git a/README.md b/README.md index cadcca1..35001d8 100644 --- a/README.md +++ b/README.md @@ -1761,13 +1761,13 @@ declare(strict_types=1); use PhpParser\Node\Scalar\Float_; -return new Float_(100); +return new Float_(100.5); ``` ↓ ```php -100.0 +100.5 ```
@@ -1922,6 +1922,42 @@ $variableName
+## `PhpParser\Node\Stmt\Block` + +### Example PHP Code + +```php + + +### Public Properties + + * `$stmts` - `/** @var Stmt[] Statements */` + +
+ ## `PhpParser\Node\Stmt\ClassConst` ### Example PHP Code @@ -2580,6 +2616,38 @@ public string $propertyName; declare(strict_types=1); +use PhpParser\Modifiers; + +$propertyItem = new \PhpParser\Node\PropertyItem('someProperty'); +$property = new \PhpParser\Node\Stmt\Property(Modifiers::PUBLIC, [$propertyItem]); + +$plus = new \PhpParser\Node\Expr\BinaryOp\Plus( + new \PhpParser\Node\Expr\Variable('variable'), + new \PhpParser\Node\Scalar\Int_(100) +); + +$getPropertyHook = new \PhpParser\Node\PropertyHook('getProperty', $plus); + +$property->hooks[] = $getPropertyHook; + +return $property; +``` + +↓ + +```php +public $someProperty { + getProperty => $variable + 100; +} +``` + +
+ +```php + -```php - - ### Public Properties * `$newModifier` - `/** @var null|int New modifier */` diff --git a/snippet/float_.php b/snippet/float_.php index df216e6..8a6a172 100644 --- a/snippet/float_.php +++ b/snippet/float_.php @@ -4,4 +4,4 @@ use PhpParser\Node\Scalar\Float_; -return new Float_(100); +return new Float_(100.5); diff --git a/snippet/php_84/property_hook.php b/snippet/php_84/property_hook.php new file mode 100644 index 0000000..b8a090d --- /dev/null +++ b/snippet/php_84/property_hook.php @@ -0,0 +1,19 @@ +hooks[] = $getPropertyHook; + +return $property; diff --git a/src/NodeCodeSampleProvider.php b/src/NodeCodeSampleProvider.php index 0f52040..e7fc230 100644 --- a/src/NodeCodeSampleProvider.php +++ b/src/NodeCodeSampleProvider.php @@ -12,7 +12,7 @@ final class NodeCodeSampleProvider { - private Standard $standardPrinter; + private readonly Standard $standardPrinter; public function __construct( ) { From 464f9448042e7905087e6684bc6e20d56c9291ee Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 11 Oct 2025 09:18:01 +0200 Subject: [PATCH 15/16] use Int_ over LNUmber --- snippet/array_dim_fetch.php | 4 ++-- snippet/assign_op/assign_op_coalesce.php | 6 +++--- snippet/assign_op/assign_op_concat.php | 6 +++--- snippet/binary_op/binary_op_boolean_and.php | 6 +++--- snippet/binary_op/binary_op_coalesce.php | 6 +++--- snippet/binary_op/binary_op_concat.php | 6 +++--- snippet/binary_op/binary_op_equal.php | 6 +++--- snippet/binary_op/binary_op_identical.php | 6 +++--- snippet/binary_op/binary_op_minus.php | 6 +++--- snippet/binary_op/binary_op_not_equal.php | 6 +++--- snippet/binary_op/binary_op_not_identical.php | 6 +++--- snippet/binary_op/binary_op_spaceship.php | 6 +++--- snippet/block.php | 4 ++-- snippet/class_method_with_stmts.php | 4 ++-- snippet/declare.php | 4 ++-- snippet/php_74/arrow_function.php | 4 ++-- snippet/php_80/match.php | 4 ++-- snippet/php_80/match_arm.php | 4 ++-- snippet/switch.php | 4 ++-- 19 files changed, 49 insertions(+), 49 deletions(-) diff --git a/snippet/array_dim_fetch.php b/snippet/array_dim_fetch.php index 36413c9..4bf725b 100644 --- a/snippet/array_dim_fetch.php +++ b/snippet/array_dim_fetch.php @@ -4,9 +4,9 @@ use PhpParser\Node\Expr\ArrayDimFetch; use PhpParser\Node\Expr\Variable; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; $variable = new Variable('variableName'); -$dimension = new LNumber(0); +$dimension = new Int_(0); return new ArrayDimFetch($variable, $dimension); diff --git a/snippet/assign_op/assign_op_coalesce.php b/snippet/assign_op/assign_op_coalesce.php index 35d778e..7b17257 100644 --- a/snippet/assign_op/assign_op_coalesce.php +++ b/snippet/assign_op/assign_op_coalesce.php @@ -3,9 +3,9 @@ declare(strict_types=1); use PhpParser\Node\Expr\AssignOp\Coalesce; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; -$left = new LNumber(5); -$right = new LNumber(10); +$left = new Int_(5); +$right = new Int_(10); return new Coalesce($left, $right); diff --git a/snippet/assign_op/assign_op_concat.php b/snippet/assign_op/assign_op_concat.php index d9b7999..b4353e8 100644 --- a/snippet/assign_op/assign_op_concat.php +++ b/snippet/assign_op/assign_op_concat.php @@ -3,9 +3,9 @@ declare(strict_types=1); use PhpParser\Node\Expr\AssignOp\Concat; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; -$left = new LNumber(5); -$right = new LNumber(10); +$left = new Int_(5); +$right = new Int_(10); return new Concat($left, $right); diff --git a/snippet/binary_op/binary_op_boolean_and.php b/snippet/binary_op/binary_op_boolean_and.php index e51a54e..0d46a66 100644 --- a/snippet/binary_op/binary_op_boolean_and.php +++ b/snippet/binary_op/binary_op_boolean_and.php @@ -3,9 +3,9 @@ declare(strict_types=1); use PhpParser\Node\Expr\BinaryOp\BooleanAnd; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; -$left = new LNumber(5); -$right = new LNumber(10); +$left = new Int_(5); +$right = new Int_(10); return new BooleanAnd($left, $right); diff --git a/snippet/binary_op/binary_op_coalesce.php b/snippet/binary_op/binary_op_coalesce.php index 863a063..b277b75 100644 --- a/snippet/binary_op/binary_op_coalesce.php +++ b/snippet/binary_op/binary_op_coalesce.php @@ -3,9 +3,9 @@ declare(strict_types=1); use PhpParser\Node\Expr\BinaryOp\Coalesce; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; -$left = new LNumber(5); -$right = new LNumber(10); +$left = new Int_(5); +$right = new Int_(10); return new Coalesce($left, $right); diff --git a/snippet/binary_op/binary_op_concat.php b/snippet/binary_op/binary_op_concat.php index f8e852b..17b878b 100644 --- a/snippet/binary_op/binary_op_concat.php +++ b/snippet/binary_op/binary_op_concat.php @@ -3,9 +3,9 @@ declare(strict_types=1); use PhpParser\Node\Expr\BinaryOp\Concat; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; -$left = new LNumber(5); -$right = new LNumber(10); +$left = new Int_(5); +$right = new Int_(10); return new Concat($left, $right); diff --git a/snippet/binary_op/binary_op_equal.php b/snippet/binary_op/binary_op_equal.php index c7b4fe2..a7af1c6 100644 --- a/snippet/binary_op/binary_op_equal.php +++ b/snippet/binary_op/binary_op_equal.php @@ -3,9 +3,9 @@ declare(strict_types=1); use PhpParser\Node\Expr\BinaryOp\Equal; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; -$left = new LNumber(5); -$right = new LNumber(10); +$left = new Int_(5); +$right = new Int_(10); return new Equal($left, $right); diff --git a/snippet/binary_op/binary_op_identical.php b/snippet/binary_op/binary_op_identical.php index 76273c2..63a5ff3 100644 --- a/snippet/binary_op/binary_op_identical.php +++ b/snippet/binary_op/binary_op_identical.php @@ -3,9 +3,9 @@ declare(strict_types=1); use PhpParser\Node\Expr\BinaryOp\Identical; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; -$left = new LNumber(5); -$right = new LNumber(10); +$left = new Int_(5); +$right = new Int_(10); return new Identical($left, $right); diff --git a/snippet/binary_op/binary_op_minus.php b/snippet/binary_op/binary_op_minus.php index 587732c..d23c37f 100644 --- a/snippet/binary_op/binary_op_minus.php +++ b/snippet/binary_op/binary_op_minus.php @@ -3,9 +3,9 @@ declare(strict_types=1); use PhpParser\Node\Expr\BinaryOp\Minus; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; -$left = new LNumber(5); -$right = new LNumber(10); +$left = new Int_(5); +$right = new Int_(10); return new Minus($left, $right); diff --git a/snippet/binary_op/binary_op_not_equal.php b/snippet/binary_op/binary_op_not_equal.php index bb20c6c..f84e931 100644 --- a/snippet/binary_op/binary_op_not_equal.php +++ b/snippet/binary_op/binary_op_not_equal.php @@ -3,9 +3,9 @@ declare(strict_types=1); use PhpParser\Node\Expr\BinaryOp\NotEqual; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; -$left = new LNumber(5); -$right = new LNumber(10); +$left = new Int_(5); +$right = new Int_(10); return new NotEqual($left, $right); diff --git a/snippet/binary_op/binary_op_not_identical.php b/snippet/binary_op/binary_op_not_identical.php index 068e001..db3da4f 100644 --- a/snippet/binary_op/binary_op_not_identical.php +++ b/snippet/binary_op/binary_op_not_identical.php @@ -3,9 +3,9 @@ declare(strict_types=1); use PhpParser\Node\Expr\BinaryOp\NotIdentical; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; -$left = new LNumber(5); -$right = new LNumber(10); +$left = new Int_(5); +$right = new Int_(10); return new NotIdentical($left, $right); diff --git a/snippet/binary_op/binary_op_spaceship.php b/snippet/binary_op/binary_op_spaceship.php index 5c2b09e..f0a77ae 100644 --- a/snippet/binary_op/binary_op_spaceship.php +++ b/snippet/binary_op/binary_op_spaceship.php @@ -3,9 +3,9 @@ declare(strict_types=1); use PhpParser\Node\Expr\BinaryOp\Spaceship; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; -$left = new LNumber(5); -$right = new LNumber(10); +$left = new Int_(5); +$right = new Int_(10); return new Spaceship($left, $right); diff --git a/snippet/block.php b/snippet/block.php index 26a6c2f..7852218 100644 --- a/snippet/block.php +++ b/snippet/block.php @@ -4,10 +4,10 @@ use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Variable; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Stmt\Block; use PhpParser\Node\Stmt\Expression; -$assign = new Assign(new Variable('someValue'), new LNumber(10000)); +$assign = new Assign(new Variable('someValue'), new Int_(10000)); return new Block([new Expression($assign)]); diff --git a/snippet/class_method_with_stmts.php b/snippet/class_method_with_stmts.php index 5107f27..edbafdc 100644 --- a/snippet/class_method_with_stmts.php +++ b/snippet/class_method_with_stmts.php @@ -4,7 +4,7 @@ use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Variable; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Expression; @@ -12,7 +12,7 @@ $classMethod->flags = \PhpParser\Modifiers::PUBLIC; $variable = new Variable('some'); -$number = new LNumber(10000); +$number = new Int_(10000); $assign = new Assign($variable, $number); $classMethod->stmts[] = new Expression($assign); diff --git a/snippet/declare.php b/snippet/declare.php index a6dd69f..cbf64a7 100644 --- a/snippet/declare.php +++ b/snippet/declare.php @@ -2,10 +2,10 @@ declare(strict_types=1); -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Stmt\Declare_; use PhpParser\Node\Stmt\DeclareDeclare; -$declareDeclare = new DeclareDeclare('strict_types', new LNumber(1)); +$declareDeclare = new DeclareDeclare('strict_types', new Int_(1)); return new Declare_([$declareDeclare]); diff --git a/snippet/php_74/arrow_function.php b/snippet/php_74/arrow_function.php index 234e621..7845d22 100644 --- a/snippet/php_74/arrow_function.php +++ b/snippet/php_74/arrow_function.php @@ -3,8 +3,8 @@ declare(strict_types=1); use PhpParser\Node\Expr\ArrowFunction; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; -$subNodes['expr'] = new LNumber(1); +$subNodes['expr'] = new Int_(1); return new ArrowFunction($subNodes); diff --git a/snippet/php_80/match.php b/snippet/php_80/match.php index 6381e4b..83dcf4f 100644 --- a/snippet/php_80/match.php +++ b/snippet/php_80/match.php @@ -5,13 +5,13 @@ use PhpParser\Node\Expr\Match_; use PhpParser\Node\Expr\Variable; use PhpParser\Node\MatchArm; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Scalar\String_; $variable = new Variable('variableName'); $body = new String_('yes'); -$cond = new LNumber(1); +$cond = new Int_(1); $matchArm = new MatchArm([$cond], $body); return new Match_($variable, [$matchArm]); diff --git a/snippet/php_80/match_arm.php b/snippet/php_80/match_arm.php index 6e4ce73..afd9a86 100644 --- a/snippet/php_80/match_arm.php +++ b/snippet/php_80/match_arm.php @@ -3,10 +3,10 @@ declare(strict_types=1); use PhpParser\Node\MatchArm; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Scalar\String_; -$conds = [new LNumber(1)]; +$conds = [new Int_(1)]; $body = new String_('yes'); return new MatchArm($conds, $body); diff --git a/snippet/switch.php b/snippet/switch.php index 61bb24d..a81422b 100644 --- a/snippet/switch.php +++ b/snippet/switch.php @@ -3,11 +3,11 @@ declare(strict_types=1); use PhpParser\Node\Expr\Variable; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Stmt\Case_; use PhpParser\Node\Stmt\Switch_; $cond = new Variable('variableName'); -$cases = [new Case_(new LNumber(1))]; +$cases = [new Case_(new Int_(1))]; return new Switch_($cond, $cases); From 780f4196d20ea8a202b6ccf0cf1d686545576b9a Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 11 Oct 2025 09:19:34 +0200 Subject: [PATCH 16/16] bump to PHP 8.3 --- README.md | 140 ++++++++++-------- rector.php | 16 +- snippet/class_const.php | 3 +- snippet/class_final.php | 3 +- snippet/class_method.php | 3 +- ...lass_method_with_param_and_return_type.php | 3 +- snippet/class_method_with_stmts.php | 3 +- snippet/final_class_with_parent_class.php | 3 +- snippet/php_74/property_typed.php | 3 +- snippet/php_84/property_hook.php | 17 ++- snippet/property.php | 3 +- src/NodeCodeSampleProvider.php | 4 +- src/NodeInfosFactory.php | 6 +- src/ValueObject/NodeCodeSample.php | 6 +- 14 files changed, 117 insertions(+), 96 deletions(-) diff --git a/README.md b/README.md index 35001d8..b875f53 100644 --- a/README.md +++ b/README.md @@ -112,10 +112,10 @@ declare(strict_types=1); use PhpParser\Node\Expr\ArrayDimFetch; use PhpParser\Node\Expr\Variable; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; $variable = new Variable('variableName'); -$dimension = new LNumber(0); +$dimension = new Int_(0); return new ArrayDimFetch($variable, $dimension); ``` @@ -181,9 +181,9 @@ return new Array_([$arrayItem]); declare(strict_types=1); use PhpParser\Node\Expr\ArrowFunction; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; -$subNodes['expr'] = new LNumber(1); +$subNodes['expr'] = new Int_(1); return new ArrowFunction($subNodes); ``` @@ -275,10 +275,10 @@ $someObject->someProperty = 'some value' declare(strict_types=1); use PhpParser\Node\Expr\AssignOp\Coalesce; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; -$left = new LNumber(5); -$right = new LNumber(10); +$left = new Int_(5); +$right = new Int_(10); return new Coalesce($left, $right); ``` @@ -308,10 +308,10 @@ return new Coalesce($left, $right); declare(strict_types=1); use PhpParser\Node\Expr\AssignOp\Concat; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; -$left = new LNumber(5); -$right = new LNumber(10); +$left = new Int_(5); +$right = new Int_(10); return new Concat($left, $right); ``` @@ -341,10 +341,10 @@ return new Concat($left, $right); declare(strict_types=1); use PhpParser\Node\Expr\BinaryOp\BooleanAnd; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; -$left = new LNumber(5); -$right = new LNumber(10); +$left = new Int_(5); +$right = new Int_(10); return new BooleanAnd($left, $right); ``` @@ -374,10 +374,10 @@ return new BooleanAnd($left, $right); declare(strict_types=1); use PhpParser\Node\Expr\BinaryOp\Coalesce; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; -$left = new LNumber(5); -$right = new LNumber(10); +$left = new Int_(5); +$right = new Int_(10); return new Coalesce($left, $right); ``` @@ -407,10 +407,10 @@ return new Coalesce($left, $right); declare(strict_types=1); use PhpParser\Node\Expr\BinaryOp\Concat; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; -$left = new LNumber(5); -$right = new LNumber(10); +$left = new Int_(5); +$right = new Int_(10); return new Concat($left, $right); ``` @@ -440,10 +440,10 @@ return new Concat($left, $right); declare(strict_types=1); use PhpParser\Node\Expr\BinaryOp\Equal; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; -$left = new LNumber(5); -$right = new LNumber(10); +$left = new Int_(5); +$right = new Int_(10); return new Equal($left, $right); ``` @@ -473,10 +473,10 @@ return new Equal($left, $right); declare(strict_types=1); use PhpParser\Node\Expr\BinaryOp\Identical; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; -$left = new LNumber(5); -$right = new LNumber(10); +$left = new Int_(5); +$right = new Int_(10); return new Identical($left, $right); ``` @@ -506,10 +506,10 @@ return new Identical($left, $right); declare(strict_types=1); use PhpParser\Node\Expr\BinaryOp\Minus; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; -$left = new LNumber(5); -$right = new LNumber(10); +$left = new Int_(5); +$right = new Int_(10); return new Minus($left, $right); ``` @@ -539,10 +539,10 @@ return new Minus($left, $right); declare(strict_types=1); use PhpParser\Node\Expr\BinaryOp\NotEqual; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; -$left = new LNumber(5); -$right = new LNumber(10); +$left = new Int_(5); +$right = new Int_(10); return new NotEqual($left, $right); ``` @@ -572,10 +572,10 @@ return new NotEqual($left, $right); declare(strict_types=1); use PhpParser\Node\Expr\BinaryOp\NotIdentical; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; -$left = new LNumber(5); -$right = new LNumber(10); +$left = new Int_(5); +$right = new Int_(10); return new NotIdentical($left, $right); ``` @@ -605,10 +605,10 @@ return new NotIdentical($left, $right); declare(strict_types=1); use PhpParser\Node\Expr\BinaryOp\Spaceship; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; -$left = new LNumber(5); -$right = new LNumber(10); +$left = new Int_(5); +$right = new Int_(10); return new Spaceship($left, $right); ``` @@ -1107,13 +1107,13 @@ declare(strict_types=1); use PhpParser\Node\Expr\Match_; use PhpParser\Node\Expr\Variable; use PhpParser\Node\MatchArm; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Scalar\String_; $variable = new Variable('variableName'); $body = new String_('yes'); -$cond = new LNumber(1); +$cond = new Int_(1); $matchArm = new MatchArm([$cond], $body); return new Match_($variable, [$matchArm]); @@ -1596,10 +1596,10 @@ $variableName declare(strict_types=1); use PhpParser\Node\MatchArm; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Scalar\String_; -$conds = [new LNumber(1)]; +$conds = [new Int_(1)]; $body = new String_('yes'); return new MatchArm($conds, $body); @@ -1933,11 +1933,11 @@ declare(strict_types=1); use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Variable; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Stmt\Block; use PhpParser\Node\Stmt\Expression; -$assign = new Assign(new Variable('someValue'), new LNumber(10000)); +$assign = new Assign(new Variable('someValue'), new Int_(10000)); return new Block([new Expression($assign)]); ``` @@ -1967,6 +1967,7 @@ return new Block([new Expression($assign)]); declare(strict_types=1); +use PhpParser\Modifiers; use PhpParser\Node\Const_; use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt\ClassConst; @@ -1974,7 +1975,7 @@ use PhpParser\Node\Stmt\ClassConst; $defaultValue = new String_('default value'); $const = new Const_('SOME_CLASS_CONSTANT', $defaultValue); -return new ClassConst([$const], \PhpParser\Modifiers::PUBLIC); +return new ClassConst([$const], Modifiers::PUBLIC); ``` ↓ @@ -2003,10 +2004,11 @@ public const SOME_CLASS_CONSTANT = 'default value'; declare(strict_types=1); +use PhpParser\Modifiers; use PhpParser\Node\Stmt\ClassMethod; $classMethod = new ClassMethod('methodName'); -$classMethod->flags = \PhpParser\Modifiers::PUBLIC; +$classMethod->flags = Modifiers::PUBLIC; return $classMethod; ``` @@ -2026,13 +2028,14 @@ public function methodName() declare(strict_types=1); +use PhpParser\Modifiers; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Identifier; use PhpParser\Node\Param; use PhpParser\Node\Stmt\ClassMethod; $classMethod = new ClassMethod('methodName'); -$classMethod->flags = \PhpParser\Modifiers::PRIVATE; +$classMethod->flags = Modifiers::PRIVATE; $param = new Param(new Variable('paramName')); $classMethod->params = [$param]; @@ -2056,17 +2059,18 @@ private function methodName($paramName): string declare(strict_types=1); +use PhpParser\Modifiers; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Variable; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Expression; $classMethod = new ClassMethod('methodName'); -$classMethod->flags = \PhpParser\Modifiers::PUBLIC; +$classMethod->flags = Modifiers::PUBLIC; $variable = new Variable('some'); -$number = new LNumber(10000); +$number = new Int_(10000); $assign = new Assign($variable, $number); $classMethod->stmts[] = new Expression($assign); @@ -2127,10 +2131,11 @@ class ClassName declare(strict_types=1); +use PhpParser\Modifiers; use PhpParser\Node\Stmt\Class_; $class = new Class_('ClassName'); -$class->flags |= \PhpParser\Modifiers::FINAL; +$class->flags |= Modifiers::FINAL; return $class; ``` @@ -2182,12 +2187,13 @@ class ClassName declare(strict_types=1); +use PhpParser\Modifiers; use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Stmt\Class_; $class = new Class_('ClassName'); -$class->flags = \PhpParser\Modifiers::FINAL; +$class->flags = Modifiers::FINAL; $class->extends = new FullyQualified('ParentClass'); return $class; @@ -2257,11 +2263,11 @@ const CONSTANT_IN_CLASS = 'default value'; declare(strict_types=1); -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Stmt\Declare_; use PhpParser\Node\Stmt\DeclareDeclare; -$declareDeclare = new DeclareDeclare('strict_types', new LNumber(1)); +$declareDeclare = new DeclareDeclare('strict_types', new Int_(1)); return new Declare_([$declareDeclare]); ``` @@ -2593,6 +2599,7 @@ labelName: declare(strict_types=1); +use PhpParser\Node\Identifier; use PhpParser\Modifiers; use PhpParser\Node\Stmt\Property; use PhpParser\Node\Stmt\PropertyProperty; @@ -2600,7 +2607,7 @@ use PhpParser\Node\VarLikeIdentifier; $propertyProperty = new PropertyProperty(new VarLikeIdentifier('propertyName')); -return new Property(Modifiers::PUBLIC, [$propertyProperty], [], new \PhpParser\Node\Identifier('string')); +return new Property(Modifiers::PUBLIC, [$propertyProperty], [], new Identifier('string')); ``` ↓ @@ -2616,17 +2623,23 @@ public string $propertyName; declare(strict_types=1); +use PhpParser\Node\PropertyItem; +use PhpParser\Node\Stmt\Property; +use PhpParser\Node\Expr\BinaryOp\Plus; +use PhpParser\Node\Expr\Variable; +use PhpParser\Node\Scalar\Int_; +use PhpParser\Node\PropertyHook; use PhpParser\Modifiers; -$propertyItem = new \PhpParser\Node\PropertyItem('someProperty'); -$property = new \PhpParser\Node\Stmt\Property(Modifiers::PUBLIC, [$propertyItem]); +$propertyItem = new PropertyItem('someProperty'); +$property = new Property(Modifiers::PUBLIC, [$propertyItem]); -$plus = new \PhpParser\Node\Expr\BinaryOp\Plus( - new \PhpParser\Node\Expr\Variable('variable'), - new \PhpParser\Node\Scalar\Int_(100) +$plus = new Plus( + new Variable('variable'), + new Int_(100) ); -$getPropertyHook = new \PhpParser\Node\PropertyHook('getProperty', $plus); +$getPropertyHook = new PropertyHook('getProperty', $plus); $property->hooks[] = $getPropertyHook; @@ -2648,13 +2661,14 @@ public $someProperty { declare(strict_types=1); +use PhpParser\Modifiers; use PhpParser\Node\Stmt\Property; use PhpParser\Node\Stmt\PropertyProperty; use PhpParser\Node\VarLikeIdentifier; $propertyProperty = new PropertyProperty(new VarLikeIdentifier('propertyName')); -return new Property(\PhpParser\Modifiers::PUBLIC, [$propertyProperty]); +return new Property(Modifiers::PUBLIC, [$propertyProperty]); ``` ↓ @@ -2739,12 +2753,12 @@ static $static; declare(strict_types=1); use PhpParser\Node\Expr\Variable; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Stmt\Case_; use PhpParser\Node\Stmt\Switch_; $cond = new Variable('variableName'); -$cases = [new Case_(new LNumber(1))]; +$cases = [new Case_(new Int_(1))]; return new Switch_($cond, $cases); ``` diff --git a/rector.php b/rector.php index bd90c28..e694c74 100644 --- a/rector.php +++ b/rector.php @@ -6,15 +6,11 @@ use Rector\Config\RectorConfig; use Rector\Set\ValueObject\LevelSetList; -return static function (RectorConfig $rectorConfig): void { - $rectorConfig->importNames(); - - $rectorConfig->paths([ +return RectorConfig::configure() + ->withImportNames() + ->withPaths([ + __DIR__ . '/snippet', __DIR__ . '/src', __DIR__ . '/tests', - ]); - - $rectorConfig->sets([ - LevelSetList::UP_TO_PHP_81 - ]); -}; + ]) + ->withPhpSets(); diff --git a/snippet/class_const.php b/snippet/class_const.php index 1d82914..99e8f05 100644 --- a/snippet/class_const.php +++ b/snippet/class_const.php @@ -2,6 +2,7 @@ declare(strict_types=1); +use PhpParser\Modifiers; use PhpParser\Node\Const_; use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt\ClassConst; @@ -9,4 +10,4 @@ $defaultValue = new String_('default value'); $const = new Const_('SOME_CLASS_CONSTANT', $defaultValue); -return new ClassConst([$const], \PhpParser\Modifiers::PUBLIC); +return new ClassConst([$const], Modifiers::PUBLIC); diff --git a/snippet/class_final.php b/snippet/class_final.php index 84a7079..e4c8dac 100644 --- a/snippet/class_final.php +++ b/snippet/class_final.php @@ -2,9 +2,10 @@ declare(strict_types=1); +use PhpParser\Modifiers; use PhpParser\Node\Stmt\Class_; $class = new Class_('ClassName'); -$class->flags |= \PhpParser\Modifiers::FINAL; +$class->flags |= Modifiers::FINAL; return $class; diff --git a/snippet/class_method.php b/snippet/class_method.php index ff80054..5e7df90 100644 --- a/snippet/class_method.php +++ b/snippet/class_method.php @@ -2,9 +2,10 @@ declare(strict_types=1); +use PhpParser\Modifiers; use PhpParser\Node\Stmt\ClassMethod; $classMethod = new ClassMethod('methodName'); -$classMethod->flags = \PhpParser\Modifiers::PUBLIC; +$classMethod->flags = Modifiers::PUBLIC; return $classMethod; diff --git a/snippet/class_method_with_param_and_return_type.php b/snippet/class_method_with_param_and_return_type.php index 34816db..d2edef1 100644 --- a/snippet/class_method_with_param_and_return_type.php +++ b/snippet/class_method_with_param_and_return_type.php @@ -2,13 +2,14 @@ declare(strict_types=1); +use PhpParser\Modifiers; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Identifier; use PhpParser\Node\Param; use PhpParser\Node\Stmt\ClassMethod; $classMethod = new ClassMethod('methodName'); -$classMethod->flags = \PhpParser\Modifiers::PRIVATE; +$classMethod->flags = Modifiers::PRIVATE; $param = new Param(new Variable('paramName')); $classMethod->params = [$param]; diff --git a/snippet/class_method_with_stmts.php b/snippet/class_method_with_stmts.php index edbafdc..a09bb44 100644 --- a/snippet/class_method_with_stmts.php +++ b/snippet/class_method_with_stmts.php @@ -2,6 +2,7 @@ declare(strict_types=1); +use PhpParser\Modifiers; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Scalar\Int_; @@ -9,7 +10,7 @@ use PhpParser\Node\Stmt\Expression; $classMethod = new ClassMethod('methodName'); -$classMethod->flags = \PhpParser\Modifiers::PUBLIC; +$classMethod->flags = Modifiers::PUBLIC; $variable = new Variable('some'); $number = new Int_(10000); diff --git a/snippet/final_class_with_parent_class.php b/snippet/final_class_with_parent_class.php index 3814adb..8296897 100644 --- a/snippet/final_class_with_parent_class.php +++ b/snippet/final_class_with_parent_class.php @@ -2,12 +2,13 @@ declare(strict_types=1); +use PhpParser\Modifiers; use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Stmt\Class_; $class = new Class_('ClassName'); -$class->flags = \PhpParser\Modifiers::FINAL; +$class->flags = Modifiers::FINAL; $class->extends = new FullyQualified('ParentClass'); return $class; diff --git a/snippet/php_74/property_typed.php b/snippet/php_74/property_typed.php index cb8164a..b37dfe5 100644 --- a/snippet/php_74/property_typed.php +++ b/snippet/php_74/property_typed.php @@ -3,10 +3,11 @@ declare(strict_types=1); use PhpParser\Modifiers; +use PhpParser\Node\Identifier; use PhpParser\Node\Stmt\Property; use PhpParser\Node\Stmt\PropertyProperty; use PhpParser\Node\VarLikeIdentifier; $propertyProperty = new PropertyProperty(new VarLikeIdentifier('propertyName')); -return new Property(Modifiers::PUBLIC, [$propertyProperty], [], new \PhpParser\Node\Identifier('string')); +return new Property(Modifiers::PUBLIC, [$propertyProperty], [], new Identifier('string')); diff --git a/snippet/php_84/property_hook.php b/snippet/php_84/property_hook.php index b8a090d..248fc83 100644 --- a/snippet/php_84/property_hook.php +++ b/snippet/php_84/property_hook.php @@ -3,16 +3,19 @@ declare(strict_types=1); use PhpParser\Modifiers; +use PhpParser\Node\Expr\BinaryOp\Plus; +use PhpParser\Node\Expr\Variable; +use PhpParser\Node\PropertyHook; +use PhpParser\Node\PropertyItem; +use PhpParser\Node\Scalar\Int_; +use PhpParser\Node\Stmt\Property; -$propertyItem = new \PhpParser\Node\PropertyItem('someProperty'); -$property = new \PhpParser\Node\Stmt\Property(Modifiers::PUBLIC, [$propertyItem]); +$propertyItem = new PropertyItem('someProperty'); +$property = new Property(Modifiers::PUBLIC, [$propertyItem]); -$plus = new \PhpParser\Node\Expr\BinaryOp\Plus( - new \PhpParser\Node\Expr\Variable('variable'), - new \PhpParser\Node\Scalar\Int_(100) -); +$plus = new Plus(new Variable('variable'), new Int_(100)); -$getPropertyHook = new \PhpParser\Node\PropertyHook('getProperty', $plus); +$getPropertyHook = new PropertyHook('getProperty', $plus); $property->hooks[] = $getPropertyHook; diff --git a/snippet/property.php b/snippet/property.php index 0e533db..4588481 100644 --- a/snippet/property.php +++ b/snippet/property.php @@ -2,10 +2,11 @@ declare(strict_types=1); +use PhpParser\Modifiers; use PhpParser\Node\Stmt\Property; use PhpParser\Node\Stmt\PropertyProperty; use PhpParser\Node\VarLikeIdentifier; $propertyProperty = new PropertyProperty(new VarLikeIdentifier('propertyName')); -return new Property(\PhpParser\Modifiers::PUBLIC, [$propertyProperty]); +return new Property(Modifiers::PUBLIC, [$propertyProperty]); diff --git a/src/NodeCodeSampleProvider.php b/src/NodeCodeSampleProvider.php index e7fc230..1a050a6 100644 --- a/src/NodeCodeSampleProvider.php +++ b/src/NodeCodeSampleProvider.php @@ -10,9 +10,9 @@ use Rector\PhpParserNodesDocs\ValueObject\NodeCodeSample; use Webmozart\Assert\Assert; -final class NodeCodeSampleProvider +final readonly class NodeCodeSampleProvider { - private readonly Standard $standardPrinter; + private Standard $standardPrinter; public function __construct( ) { diff --git a/src/NodeInfosFactory.php b/src/NodeInfosFactory.php index 015aeb1..a424288 100644 --- a/src/NodeInfosFactory.php +++ b/src/NodeInfosFactory.php @@ -10,11 +10,11 @@ /** * @see \Rector\PhpParserNodesDocs\Tests\NodeInfosFactoryTest */ -final class NodeInfosFactory +final readonly class NodeInfosFactory { public function __construct( - private readonly NodeCodeSampleProvider $nodeCodeSampleProvider, - private readonly NodeInfoSorter $nodeInfoSorter + private NodeCodeSampleProvider $nodeCodeSampleProvider, + private NodeInfoSorter $nodeInfoSorter ) { } diff --git a/src/ValueObject/NodeCodeSample.php b/src/ValueObject/NodeCodeSample.php index cc33bbf..9fea207 100644 --- a/src/ValueObject/NodeCodeSample.php +++ b/src/ValueObject/NodeCodeSample.php @@ -4,11 +4,11 @@ namespace Rector\PhpParserNodesDocs\ValueObject; -final class NodeCodeSample +final readonly class NodeCodeSample { - private readonly string $phpCode; + private string $phpCode; - private readonly string $printedContent; + private string $printedContent; public function __construct(string $phpCode, string $printedContent) {