From e1a79c62f8de28403b7a5d3a7632db027b3e0899 Mon Sep 17 00:00:00 2001 From: MoscoviumAlchemist <155810892+MoscoviumAlchemist@users.noreply.github.com> Date: Wed, 19 Mar 2025 21:32:24 -0400 Subject: [PATCH 1/4] Support symfony/filesystem ^7.0 Support symfony/filesystem ^7.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 385d37b..12af615 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "php": "^7.3 || ^8.0", "nikic/php-parser": "^4.10", "symfony/console": "^5.1 || ^6.0", - "symfony/filesystem": "^5.0 || ^6.0", + "symfony/filesystem": "^5.0 || ^6.0 || ^7.0", "symfony/finder": "^5.0 || ^6.0" }, "require-dev": { From 8f7d3ac0d45bb4d60b525d31f1890e99cd491e4b Mon Sep 17 00:00:00 2001 From: MoscoviumAlchemist <155810892+MoscoviumAlchemist@users.noreply.github.com> Date: Thu, 20 Mar 2025 09:24:10 -0400 Subject: [PATCH 2/4] Add ^7.0 support for all symfony dependencies Add ^7.0 support for all symfony dependencies --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 12af615..ef338d6 100644 --- a/composer.json +++ b/composer.json @@ -25,9 +25,9 @@ "require": { "php": "^7.3 || ^8.0", "nikic/php-parser": "^4.10", - "symfony/console": "^5.1 || ^6.0", + "symfony/console": "^5.1 || ^6.0 || ^7.0", "symfony/filesystem": "^5.0 || ^6.0 || ^7.0", - "symfony/finder": "^5.0 || ^6.0" + "symfony/finder": "^5.0 || ^6.0 || ^7.0" }, "require-dev": { "vimeo/psalm": "^4.1", From 720e15e9948696810826bd7def56cacfc1913ea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Fri, 9 Aug 2024 18:44:45 +0200 Subject: [PATCH 3/4] bump up php-parser --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index ef338d6..eec3740 100644 --- a/composer.json +++ b/composer.json @@ -24,13 +24,12 @@ ], "require": { "php": "^7.3 || ^8.0", - "nikic/php-parser": "^4.10", + "nikic/php-parser": "^4.10 || ^5.1", "symfony/console": "^5.1 || ^6.0 || ^7.0", "symfony/filesystem": "^5.0 || ^6.0 || ^7.0", "symfony/finder": "^5.0 || ^6.0 || ^7.0" }, "require-dev": { - "vimeo/psalm": "^4.1", "phpunit/phpunit": "^9.4", "friendsofphp/php-cs-fixer": "^2.16 || ^3.12" }, From b1a4a31934deabcc33eb949dbad29f172f391f50 Mon Sep 17 00:00:00 2001 From: Marian <42134098+IanDelMar@users.noreply.github.com> Date: Fri, 18 Apr 2025 02:23:58 +0200 Subject: [PATCH 4/4] Add support for PhpParser v5 for PHP 7.4+ --- .editorconfig | 12 ++++++++++++ .gitignore | 3 +-- .php_cs => .php-cs-fixer.php | 13 ++++++------- composer.json | 13 ++++++++++--- phpstan.neon | 4 ++++ phpunit.xml | 22 +++++++++++----------- src/NodeVisitor.php | 6 +++--- src/StubsGenerator.php | 4 ++-- test/NodeVisitorTest.php | 2 +- 9 files changed, 50 insertions(+), 29 deletions(-) create mode 100644 .editorconfig rename .php_cs => .php-cs-fixer.php (83%) create mode 100644 phpstan.neon diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..bcc46d0 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true +block_comment_start = /* +block_comment = * +block_comment_end = */ diff --git a/.gitignore b/.gitignore index 4009a04..e7d03de 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,4 @@ /vendor/ # Cache files -.php_cs.cache -.phpunit.result.cache +*.cache diff --git a/.php_cs b/.php-cs-fixer.php similarity index 83% rename from .php_cs rename to .php-cs-fixer.php index f5c289d..5d931ad 100644 --- a/.php_cs +++ b/.php-cs-fixer.php @@ -1,12 +1,12 @@ in(__DIR__ . '/src') ->in(__DIR__ . '/test') ->in(__DIR__ . '/bin') ; -return PhpCsFixer\Config::create() +return (new PhpCsFixer\Config()) ->setRules([ // If you're curious what these do, use `php-cs-fixer describe ` '@PSR1' => true, @@ -19,9 +19,9 @@ 'function_typehint_space' => true, 'include' => true, 'linebreak_after_opening_tag' => true, - // 'list_syntax' => ['syntax' => 'short'], Requires PHP 7.1 + 'list_syntax' => ['syntax' => 'short'], 'magic_constant_casing' => true, - 'method_separation' => true, + 'class_attributes_separation' => ['elements' => ['method' => 'one']], 'native_function_casing' => true, 'new_with_braces' => true, 'no_blank_lines_after_class_opening' => true, @@ -34,7 +34,7 @@ 'no_unused_imports' => true, 'normalize_index_brace' => true, 'not_operator_with_successor_space' => false, - 'ordered_imports' => ['sortAlgorithm' => 'alpha'], + 'ordered_imports' => ['sort_algorithm' => 'alpha'], 'phpdoc_indent' => true, 'phpdoc_order' => true, 'phpdoc_scalar' => true, @@ -49,5 +49,4 @@ 'whitespace_after_comma_in_array' => true, ]) ->setFinder($finder) - ->setCacheFile(__DIR__ . '/.php_cs.cache') ; diff --git a/composer.json b/composer.json index eec3740..3167b1f 100644 --- a/composer.json +++ b/composer.json @@ -30,10 +30,17 @@ "symfony/finder": "^5.0 || ^6.0 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "^9.4", - "friendsofphp/php-cs-fixer": "^2.16 || ^3.12" + "friendsofphp/php-cs-fixer": "3.4.0 || ^3.12", + "phpstan/phpstan": "^1.0 || ^2.0", + "phpunit/phpunit": "^9.4" }, "scripts": { - "test": "phpunit --verbose" + "test": "phpunit --verbose", + "cs:check": "php-cs-fixer check", + "cs:fix": "php-cs-fixer fix", + "phpstan": "phpstan analyse" + }, + "config": { + "sort-packages": true } } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..776ccd8 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,4 @@ +parameters: + level: max + paths: + - src diff --git a/phpunit.xml b/phpunit.xml index 2de21df..593b45a 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,16 +1,16 @@ diff --git a/src/NodeVisitor.php b/src/NodeVisitor.php index 2505150..f3c52e7 100644 --- a/src/NodeVisitor.php +++ b/src/NodeVisitor.php @@ -172,7 +172,7 @@ public function enterNode(Node $node) $node instanceof Expression && $node->expr instanceof FuncCall && $node->expr->name instanceof Name && - $node->expr->name->parts[0] === 'define' + $node->expr->name->getFirst() === 'define' ) { $this->isInDeclaration = true; } elseif ($node instanceof If_) { @@ -207,7 +207,7 @@ public function leaveNode(Node $node, bool $preserveStack = false) $node instanceof Expression && $node->expr instanceof FuncCall && $node->expr->name instanceof Name && - $node->expr->name->parts[0] === 'define' + $node->expr->name->getFirst() === 'define' ) ) { // We're leaving one of these. @@ -388,7 +388,7 @@ function (\PhpParser\Node\Const_ $const) { $node instanceof Expression && $node->expr instanceof FuncCall && $node->expr->name instanceof Name && - $node->expr->name->parts[0] === 'define' + $node->expr->name->getFirst() === 'define' ) { $fullyQualifiedName = $node->expr->args[0]->value->value; diff --git a/src/StubsGenerator.php b/src/StubsGenerator.php index afa6c10..eea0bec 100644 --- a/src/StubsGenerator.php +++ b/src/StubsGenerator.php @@ -112,10 +112,10 @@ public function __construct(int $symbols = self::DEFAULT, array $config = []) */ public function generate(Finder $finder, NodeVisitor $visitor = null): Result { - $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7); + $parser = (new ParserFactory())->createForNewestSupportedVersion(); if (!($visitor instanceof NodeVisitor)) { - $visitor = new NodeVisitor; + $visitor = new NodeVisitor(); } $visitor->init($this->symbols, $this->config); diff --git a/test/NodeVisitorTest.php b/test/NodeVisitorTest.php index 7af26e4..d5d11db 100644 --- a/test/NodeVisitorTest.php +++ b/test/NodeVisitorTest.php @@ -12,7 +12,7 @@ class NodeVisitorTest extends TestCase { private function parse(string $php, int $symbols, array $config): NodeVisitor { - $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7); + $parser = (new ParserFactory())->createForNewestSupportedVersion(); $traverser = new NodeTraverser(); $traverser->addVisitor(new NameResolver());