phpro / grumphp

A PHP code-quality tool
MIT License
4.15k stars 431 forks source link

Add PHP-Parser 4 support #508

Closed vyshkant closed 6 years ago

vyshkant commented 6 years ago
Q A
Version GrumPHP 0.14.0
Bug? no
New feature? yes
Question? no
Documentation? no

I have one case of incompatibility with PhpParser 4, but there could be more.

The type of \PhpParser\Node\Stmt\DeclareDeclare::$key has been changed since 4.0.0 version of PHP-Parser.

We expect this property to be string: https://github.com/phpro/grumphp/blob/60ed6970d432c889aba6316bfd223b22b139cb5b/src/Parser/Php/Visitor/DeclareStrictTypesVisitor.php#L26

but in ^4.0 version it is PhpParser\Node\Identifier: https://github.com/nikic/PHP-Parser/blob/9c18e3db49fa469f5feffe40dbd7b1ec2b61e41f/lib/PhpParser/Node/Stmt/DeclareDeclare.php#L9-L10

So strict comparison will always return false, which leads to unexpected behavior.

A quick-fix of my single case is to cast $declare->key to string (PhpParser\Node\Identifier::__toString() will return expected value):

if ((string)$declare->key !== 'strict_types') { 
vyshkant commented 6 years ago

Moreover: symfony/maker-bundle v1.5.0 requires nikic/php-parser ^4.0.

symfony/maker-bundle is provided by default with Symfony 4.0.

In other words, phpparser task is incompatible with Symfony 4, so https://github.com/phpro/grumphp/issues/423 need to be reopened.

Landerstraeten commented 6 years ago

Fixed

vyshkant commented 6 years ago

@Landerstraeten can you please release this fix?