Skip to content

Commit 820db58

Browse files
IanDelMarMoscoviumAlchemistszepeviktor
authored
Add support for PhpParser v5 for PHP 7.4+ (#33)
* Support symfony/filesystem ^7.0 Support symfony/filesystem ^7.0 * Add ^7.0 support for all symfony dependencies Add ^7.0 support for all symfony dependencies * bump up php-parser * Add support for PhpParser v5 for PHP 7.4+ --------- Co-authored-by: MoscoviumAlchemist <[email protected]> Co-authored-by: Viktor Szépe <[email protected]>
1 parent 16d9fa9 commit 820db58

File tree

9 files changed

+54
-34
lines changed

9 files changed

+54
-34
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 4
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
block_comment_start = /*
11+
block_comment = *
12+
block_comment_end = */

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
/vendor/
33

44
# Cache files
5-
.php_cs.cache
6-
.phpunit.result.cache
5+
*.cache

.php_cs renamed to .php-cs-fixer.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
2-
// http://cs.sensiolabs.org/#usage
3-
$finder = PhpCsFixer\Finder::create()
2+
// https://cs.symfony.com/doc/usage.html
3+
$finder = (new PhpCsFixer\Finder())
44
->in(__DIR__ . '/src')
55
->in(__DIR__ . '/test')
66
->in(__DIR__ . '/bin')
77
;
88

9-
return PhpCsFixer\Config::create()
9+
return (new PhpCsFixer\Config())
1010
->setRules([
1111
// If you're curious what these do, use `php-cs-fixer describe <key>`
1212
'@PSR1' => true,
@@ -19,9 +19,9 @@
1919
'function_typehint_space' => true,
2020
'include' => true,
2121
'linebreak_after_opening_tag' => true,
22-
// 'list_syntax' => ['syntax' => 'short'], Requires PHP 7.1
22+
'list_syntax' => ['syntax' => 'short'],
2323
'magic_constant_casing' => true,
24-
'method_separation' => true,
24+
'class_attributes_separation' => ['elements' => ['method' => 'one']],
2525
'native_function_casing' => true,
2626
'new_with_braces' => true,
2727
'no_blank_lines_after_class_opening' => true,
@@ -34,7 +34,7 @@
3434
'no_unused_imports' => true,
3535
'normalize_index_brace' => true,
3636
'not_operator_with_successor_space' => false,
37-
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
37+
'ordered_imports' => ['sort_algorithm' => 'alpha'],
3838
'phpdoc_indent' => true,
3939
'phpdoc_order' => true,
4040
'phpdoc_scalar' => true,
@@ -49,5 +49,4 @@
4949
'whitespace_after_comma_in_array' => true,
5050
])
5151
->setFinder($finder)
52-
->setCacheFile(__DIR__ . '/.php_cs.cache')
5352
;

composer.json

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,23 @@
2424
],
2525
"require": {
2626
"php": "^7.3 || ^8.0",
27-
"nikic/php-parser": "^4.10",
28-
"symfony/console": "^5.1 || ^6.0",
29-
"symfony/filesystem": "^5.0 || ^6.0",
30-
"symfony/finder": "^5.0 || ^6.0"
27+
"nikic/php-parser": "^4.10 || ^5.1",
28+
"symfony/console": "^5.1 || ^6.0 || ^7.0",
29+
"symfony/filesystem": "^5.0 || ^6.0 || ^7.0",
30+
"symfony/finder": "^5.0 || ^6.0 || ^7.0"
3131
},
3232
"require-dev": {
33-
"vimeo/psalm": "^4.1",
34-
"phpunit/phpunit": "^9.4",
35-
"friendsofphp/php-cs-fixer": "^2.16 || ^3.12"
33+
"friendsofphp/php-cs-fixer": "3.4.0 || ^3.12",
34+
"phpstan/phpstan": "^1.0 || ^2.0",
35+
"phpunit/phpunit": "^9.4"
3636
},
3737
"scripts": {
38-
"test": "phpunit --verbose"
38+
"test": "phpunit --verbose",
39+
"cs:check": "php-cs-fixer check",
40+
"cs:fix": "php-cs-fixer fix",
41+
"phpstan": "phpstan analyse"
42+
},
43+
"config": {
44+
"sort-packages": true
3945
}
4046
}

phpstan.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
parameters:
2+
level: max
3+
paths:
4+
- src

phpunit.xml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<!--bootstrap="tests/bootstrap.php" -->
22
<phpunit
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.4/phpunit.xsd"
5-
backupGlobals="false"
6-
beStrictAboutChangesToGlobalState="true"
7-
beStrictAboutCoversAnnotation="true"
8-
beStrictAboutOutputDuringTests="true"
9-
beStrictAboutTestsThatDoNotTestAnything="true"
10-
colors="true"
11-
convertErrorsToExceptions="true"
12-
convertNoticesToExceptions="true"
13-
convertWarningsToExceptions="true"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.4/phpunit.xsd"
5+
backupGlobals="false"
6+
beStrictAboutChangesToGlobalState="true"
7+
beStrictAboutCoversAnnotation="true"
8+
beStrictAboutOutputDuringTests="true"
9+
beStrictAboutTestsThatDoNotTestAnything="true"
10+
colors="true"
11+
convertErrorsToExceptions="true"
12+
convertNoticesToExceptions="true"
13+
convertWarningsToExceptions="true"
1414
>
1515
<testsuites>
1616
<testsuite name="Stub Generator Tests">

src/NodeVisitor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public function enterNode(Node $node)
172172
$node instanceof Expression &&
173173
$node->expr instanceof FuncCall &&
174174
$node->expr->name instanceof Name &&
175-
$node->expr->name->parts[0] === 'define'
175+
$node->expr->name->getFirst() === 'define'
176176
) {
177177
$this->isInDeclaration = true;
178178
} elseif ($node instanceof If_) {
@@ -207,7 +207,7 @@ public function leaveNode(Node $node, bool $preserveStack = false)
207207
$node instanceof Expression &&
208208
$node->expr instanceof FuncCall &&
209209
$node->expr->name instanceof Name &&
210-
$node->expr->name->parts[0] === 'define'
210+
$node->expr->name->getFirst() === 'define'
211211
)
212212
) {
213213
// We're leaving one of these.
@@ -388,7 +388,7 @@ function (\PhpParser\Node\Const_ $const) {
388388
$node instanceof Expression &&
389389
$node->expr instanceof FuncCall &&
390390
$node->expr->name instanceof Name &&
391-
$node->expr->name->parts[0] === 'define'
391+
$node->expr->name->getFirst() === 'define'
392392
) {
393393
$fullyQualifiedName = $node->expr->args[0]->value->value;
394394

src/StubsGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ public function __construct(int $symbols = self::DEFAULT, array $config = [])
112112
*/
113113
public function generate(Finder $finder, NodeVisitor $visitor = null): Result
114114
{
115-
$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
115+
$parser = (new ParserFactory())->createForNewestSupportedVersion();
116116

117117
if (!($visitor instanceof NodeVisitor)) {
118-
$visitor = new NodeVisitor;
118+
$visitor = new NodeVisitor();
119119
}
120120

121121
$visitor->init($this->symbols, $this->config);

test/NodeVisitorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class NodeVisitorTest extends TestCase
1212
{
1313
private function parse(string $php, int $symbols, array $config): NodeVisitor
1414
{
15-
$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
15+
$parser = (new ParserFactory())->createForNewestSupportedVersion();
1616

1717
$traverser = new NodeTraverser();
1818
$traverser->addVisitor(new NameResolver());

0 commit comments

Comments
 (0)