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 385d37b..3167b1f 100644 --- a/composer.json +++ b/composer.json @@ -24,17 +24,23 @@ ], "require": { "php": "^7.3 || ^8.0", - "nikic/php-parser": "^4.10", - "symfony/console": "^5.1 || ^6.0", - "symfony/filesystem": "^5.0 || ^6.0", - "symfony/finder": "^5.0 || ^6.0" + "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" + "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());