From 0f86a6029ddb058e84605aabc91e6f08b63edcad Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 10 Oct 2025 22:44:14 +0200 Subject: [PATCH 1/7] 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 2/7] 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 3/7] 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 4/7] 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 5/7] 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 6/7] 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 7/7] 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) {