Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TypeDeclaration] Error on iterable (phpstan > 0.12) #2537

Closed
gnutix opened this issue Dec 30, 2019 · 9 comments · Fixed by #2548
Closed

[TypeDeclaration] Error on iterable (phpstan > 0.12) #2537

gnutix opened this issue Dec 30, 2019 · 9 comments · Fixed by #2548
Assignees
Labels

Comments

@gnutix
Copy link
Contributor

gnutix commented Dec 30, 2019

While trying to debug the type-declaration set on my project, I created a small playground and managed to isolate the issue : https://github.com/gnutix/rector-playground

Running ./scripts/RUN gives :

Run PhpStan
 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%


                                                                                                                        
 [OK] No errors                                                                                                         
                                                                                                                        

Run Rector
Rector 0.6.x-dev@9a330e2
Config file: rector.yaml

[parsing] src/Bar.php
[refactoring] src/Bar.php

In StaticTypeMapper.php line 499:
                                                                                                                                                                          
  [Rector\Exception\NotImplementedException]                                                                                                                              
  Rector\NodeTypeResolver\StaticTypeMapper::mapPHPStanPhpDocTypeNodeToPHPStanType for Rector\BetterPhpDocParser\Attributes\Ast\PhpDoc\Type\AttributeAwareGenericTypeNode  
                                                                                                                                                                          

Exception trace:
  at phar:///home/gnutix/dev/oss/rectorphp/rector/temp/playground/vendor/rector/rector-prefixed/rector/packages/NodeTypeResolver/src/StaticTypeMapper.php:499
 Rector\NodeTypeResolver\StaticTypeMapper->mapPHPStanPhpDocTypeNodeToPHPStanType() at phar:///home/gnutix/dev/oss/rectorphp/rector/temp/playground/vendor/rector/rector-prefixed/rector/packages/NodeTypeResolver/src/StaticTypeMapper.php:369
 Rector\NodeTypeResolver\StaticTypeMapper->mapPHPStanPhpDocTypeToPHPStanType() at phar:///home/gnutix/dev/oss/rectorphp/rector/temp/playground/vendor/rector/rector-prefixed/rector/packages/BetterPhpDocParser/src/PhpDocInfo/PhpDocInfo.php:155
 Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo->getReturnType() at phar:///home/gnutix/dev/oss/rectorphp/rector/temp/playground/vendor/rector/rector-prefixed/rector/packages/NodeTypeResolver/src/PhpDoc/NodeAnalyzer/DocBlockManipulator.php:155
 Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\DocBlockManipulator->getReturnType() at phar:///home/gnutix/dev/oss/rectorphp/rector/temp/playground/vendor/rector/rector-prefixed/rector/packages/NodeTypeResolver/src/PhpDoc/NodeAnalyzer/DocBlockManipulator.php:221
 Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\DocBlockManipulator->addReturnTag() at phar:///home/gnutix/dev/oss/rectorphp/rector/temp/playground/vendor/rector/rector-prefixed/rector/packages/TypeDeclaration/src/Rector/ClassMethod/AddArrayReturnDocTypeRector.php:91
 Rector\TypeDeclaration\Rector\ClassMethod\AddArrayReturnDocTypeRector->refactor() at phar:///home/gnutix/dev/oss/rectorphp/rector/temp/playground/vendor/rector/rector-prefixed/rector/src/Rector/AbstractRector.php:95
 Rector\Rector\AbstractRector->enterNode() at phar:///home/gnutix/dev/oss/rectorphp/rector/temp/playground/vendor/phpstan/phpstan/phpstan.phar/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:176
 PhpParser\NodeTraverser->traverseArray() at phar:///home/gnutix/dev/oss/rectorphp/rector/temp/playground/vendor/phpstan/phpstan/phpstan.phar/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:105
 PhpParser\NodeTraverser->traverseNode() at phar:///home/gnutix/dev/oss/rectorphp/rector/temp/playground/vendor/phpstan/phpstan/phpstan.phar/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:196
 PhpParser\NodeTraverser->traverseArray() at phar:///home/gnutix/dev/oss/rectorphp/rector/temp/playground/vendor/phpstan/phpstan/phpstan.phar/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:105
 PhpParser\NodeTraverser->traverseNode() at phar:///home/gnutix/dev/oss/rectorphp/rector/temp/playground/vendor/phpstan/phpstan/phpstan.phar/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:196
 PhpParser\NodeTraverser->traverseArray() at phar:///home/gnutix/dev/oss/rectorphp/rector/temp/playground/vendor/phpstan/phpstan/phpstan.phar/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:85
 PhpParser\NodeTraverser->traverse() at phar:///home/gnutix/dev/oss/rectorphp/rector/temp/playground/vendor/rector/rector-prefixed/rector/src/PhpParser/NodeTraverser/RectorNodeTraverser.php:53
 Rector\PhpParser\NodeTraverser\RectorNodeTraverser->traverse() at phar:///home/gnutix/dev/oss/rectorphp/rector/temp/playground/vendor/rector/rector-prefixed/rector/src/Application/FileProcessor.php:100
 Rector\Application\FileProcessor->refactor() at phar:///home/gnutix/dev/oss/rectorphp/rector/temp/playground/vendor/rector/rector-prefixed/rector/src/Application/RectorApplication.php:123
 Rector\Application\RectorApplication->Rector\Application\{closure}() at phar:///home/gnutix/dev/oss/rectorphp/rector/temp/playground/vendor/rector/rector-prefixed/rector/src/Application/RectorApplication.php:176
 Rector\Application\RectorApplication->tryCatchWrapper() at phar:///home/gnutix/dev/oss/rectorphp/rector/temp/playground/vendor/rector/rector-prefixed/rector/src/Application/RectorApplication.php:124
 Rector\Application\RectorApplication->runOnFileInfos() at phar:///home/gnutix/dev/oss/rectorphp/rector/temp/playground/vendor/rector/rector-prefixed/rector/src/Console/Command/ProcessCommand.php:116
 Rector\Console\Command\ProcessCommand->execute() at phar:///home/gnutix/dev/oss/rectorphp/rector/temp/playground/vendor/rector/rector-prefixed/rector/vendor/symfony/console/Command/Command.php:228
 _HumbugBox655fe0f4d050\Symfony\Component\Console\Command\Command->run() at phar:///home/gnutix/dev/oss/rectorphp/rector/temp/playground/vendor/rector/rector-prefixed/rector/src/Console/Command/AbstractCommand.php:30
 Rector\Console\Command\AbstractCommand->run() at phar:///home/gnutix/dev/oss/rectorphp/rector/temp/playground/vendor/rector/rector-prefixed/rector/vendor/symfony/console/Application.php:858
 _HumbugBox655fe0f4d050\Symfony\Component\Console\Application->doRunCommand() at phar:///home/gnutix/dev/oss/rectorphp/rector/temp/playground/vendor/rector/rector-prefixed/rector/vendor/symfony/console/Application.php:236
 _HumbugBox655fe0f4d050\Symfony\Component\Console\Application->doRun() at phar:///home/gnutix/dev/oss/rectorphp/rector/temp/playground/vendor/rector/rector-prefixed/rector/src/Console/Application.php:76
 Rector\Console\Application->doRun() at phar:///home/gnutix/dev/oss/rectorphp/rector/temp/playground/vendor/rector/rector-prefixed/rector/vendor/symfony/console/Application.php:137
 _HumbugBox655fe0f4d050\Symfony\Component\Console\Application->run() at phar:///home/gnutix/dev/oss/rectorphp/rector/temp/playground/vendor/rector/rector-prefixed/rector/bin/rector:41
 require() at /home/gnutix/dev/oss/rectorphp/rector/temp/playground/vendor/rector/rector-prefixed/rector:6

process [-n|--dry-run] [-a|--autoload-file AUTOLOAD-FILE] [-e|--hide-autoload-errors] [--match-git-diff] [-r|--rule RULE] [-o|--output-format [OUTPUT-FORMAT]] [--] [<source>...]

I've also tried adding a test case, but it passed (and it shouldn't...) :

diff --git a/packages/TypeDeclaration/tests/Rector/Property/PropertyTypeDeclarationRector/Fixture/phpstan_class_string_in_generics_type.php.inc b/packages/TypeDeclaration/tests/Rector/Property/PropertyTypeDeclarationRector/Fixture/phpstan_class_string_in_generics_type.php.inc
new file mode 100644
index 000000000..3fb31f69e
--- /dev/null
+++ b/packages/TypeDeclaration/tests/Rector/Property/PropertyTypeDeclarationRector/Fixture/phpstan_class_string_in_generics_type.php.inc
@@ -0,0 +1,14 @@
+<?php
+
+namespace Rector\TypeDeclaration\Tests\Rector\FunctionLike\PropertyTypeDeclarationRector\Fixture;
+
+class PhpstanClassStringInGenericsType
+{
+    /**
+     * @return iterable<string>
+     */
+    public static function getHandledMessages(): iterable
+    {
+        yield ['some string'];
+    }
+}

I've tried changing the docblock to iterable<mixed>, \Generator<string>, etc. Some passed PhpStan, but none passed Rector.

@gnutix gnutix closed this as completed Dec 30, 2019
@gnutix gnutix changed the title [TypeDeclaration] Errors when running from Docker [TypeDeclaration] Error on iterable (phpstan > 0.12) Dec 30, 2019
@gnutix gnutix reopened this Dec 30, 2019
@gnutix
Copy link
Contributor Author

gnutix commented Dec 30, 2019

Seems like you're working on that tonight, right ? :) #2534

@TomasVotruba
Copy link
Member

Not sure if related thought. I've merged it now :)

@gnutix
Copy link
Contributor Author

gnutix commented Dec 30, 2019

Indeed; I've updated the playground and the error remains. Let me know if you need any help to get it running (hopefully it's easy :) )

@TomasVotruba
Copy link
Member

TomasVotruba commented Dec 30, 2019

Thanks 👍 Link to failing Travis CI in that repository would be the best :)

@gnutix
Copy link
Contributor Author

gnutix commented Dec 30, 2019

Not sure I could trigger the CI there at each update of Rector's repository though... But I could give you access to Travis for this repo so you could run the test ?

@TomasVotruba
Copy link
Member

No need for that.
All you need to do is add Travis yourself. If there is error, I'll see it.

@gnutix
Copy link
Contributor Author

gnutix commented Dec 30, 2019

Done! I've added you as a collaborator on the repository too, so you hopefully have access to Travis and can restart the builds.

@TomasVotruba
Copy link
Member

Thank you, I'm looking into it now

@TomasVotruba
Copy link
Member

Thanks for the demo! I've discovered 2 more bugs thanks to it

Let's see how this helps

TomasVotruba added a commit that referenced this issue Jun 20, 2022
rectorphp/rector-src@21fc218 [Core] AbstractScopeAwareRector is ready to be used in custom rules (#2537)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants