-
-
Notifications
You must be signed in to change notification settings - Fork 946
Description
Hi there
I have this factory which is creating an instance of CouchbaseCluster class.
<?php declare(strict_types = 1);
namespace MyNamespace;
use CouchbaseCluster;
class CouchbaseClusterFactory
{
public function create(string $clusterDsn) : CouchbaseCluster
{
return new CouchbaseCluster($clusterDsn);
}
}Given that all Couchbase* classes are defined in couchbase.so extension, the $declaringClass->getNativeReflection()->getFileName() for that class is [CouchbaseNative]/CouchbaseCluster.class.php.
This is no problem for other parts of my code, where I typehint/returntype various other Couchbase* classes. Probably because this is the only place where I'm creating new instance of it.
So only this one is causing PHPStan to fail on getting contents/mtime of non-existing file as shown below.
$ bin/phpstan analyse --level=7 src/CouchbaseClusterFactory.php
Warning: filemtime(): stat failed for [CouchbaseNative]/CouchbaseCluster.class.php in /var/www/store/vendor/phpstan/phpstan/src/Type/FileTypeMapper.php on line 36
Call Stack:
0.0002 727872 1. {main}() /var/www/store/vendor/phpstan/phpstan/bin/phpstan:0
0.0122 2524880 2. Symfony\Component\Console\Application->run() /var/www/store/vendor/phpstan/phpstan/bin/phpstan:35
0.0155 2832496 3. Symfony\Component\Console\Application->doRun() /var/www/store/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:125
0.0156 2832496 4. Symfony\Component\Console\Application->doRunCommand() /var/www/store/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:224
0.0157 2832496 5. PHPStan\Command\AnalyseCommand->run() /var/www/store/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:888
0.0161 2838384 6. PHPStan\Command\AnalyseCommand->execute() /var/www/store/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:262
0.0393 6371328 7. PHPStan\Command\AnalyseApplication->analyse() /var/www/store/vendor/phpstan/phpstan/src/Command/AnalyseCommand.php:216
0.0396 6373136 8. PHPStan\Analyser\Analyser->analyse() /var/www/store/vendor/phpstan/phpstan/src/Command/AnalyseApplication.php:113
0.0518 7423488 9. PHPStan\Analyser\NodeScopeResolver->processNodes() /var/www/store/vendor/phpstan/phpstan/src/Analyser/Analyser.php:149
0.0520 7489024 10. PHPStan\Analyser\NodeScopeResolver->processNode() /var/www/store/vendor/phpstan/phpstan/src/Analyser/NodeScopeResolver.php:176
0.0521 7490816 11. PHPStan\Analyser\NodeScopeResolver->processNodes() /var/www/store/vendor/phpstan/phpstan/src/Analyser/NodeScopeResolver.php:586
0.0530 7490816 12. PHPStan\Analyser\NodeScopeResolver->processNode() /var/www/store/vendor/phpstan/phpstan/src/Analyser/NodeScopeResolver.php:176
0.0539 7579352 13. PHPStan\Analyser\NodeScopeResolver->processNodes() /var/www/store/vendor/phpstan/phpstan/src/Analyser/NodeScopeResolver.php:586
0.0551 7604072 14. PHPStan\Analyser\NodeScopeResolver->processNode() /var/www/store/vendor/phpstan/phpstan/src/Analyser/NodeScopeResolver.php:176
0.0584 7918504 15. PHPStan\Analyser\NodeScopeResolver->processNodes() /var/www/store/vendor/phpstan/phpstan/src/Analyser/NodeScopeResolver.php:586
0.0584 7918504 16. PHPStan\Analyser\NodeScopeResolver->processNode() /var/www/store/vendor/phpstan/phpstan/src/Analyser/NodeScopeResolver.php:176
0.0586 7919264 17. PHPStan\Analyser\NodeScopeResolver->processNode() /var/www/store/vendor/phpstan/phpstan/src/Analyser/NodeScopeResolver.php:650
0.0586 7919264 18. PHPStan\Analyser\Analyser->PHPStan\Analyser\{closure}() /var/www/store/vendor/phpstan/phpstan/src/Analyser/NodeScopeResolver.php:303
0.0586 7920016 19. PHPStan\Rules\Classes\InstantiationRule->processNode() /var/www/store/vendor/phpstan/phpstan/src/Analyser/Analyser.php:145
0.0586 7920696 20. PHPStan\Reflection\ClassReflection->getMethod() /var/www/store/vendor/phpstan/phpstan/src/Rules/Classes/InstantiationRule.php:114
0.0586 7921016 21. PHPStan\Reflection\Php\PhpClassReflectionExtension->getMethod() /var/www/store/vendor/phpstan/phpstan/src/Reflection/ClassReflection.php:108
0.0586 7921016 22. PHPStan\Reflection\Php\PhpClassReflectionExtension->createMethods() /var/www/store/vendor/phpstan/phpstan/src/Reflection/Php/PhpClassReflectionExtension.php:127
0.0589 7936832 23. PHPStan\Type\FileTypeMapper->getTypeMap() /var/www/store/vendor/phpstan/phpstan/src/Reflection/Php/PhpClassReflectionExtension.php:171
0.0589 7936832 24. filemtime() /var/www/store/vendor/phpstan/phpstan/src/Type/FileTypeMapper.php:36
Warning: file_get_contents([CouchbaseNative]/CouchbaseCluster.class.php): failed to open stream: No such file or directory in /var/www/store/vendor/phpstan/phpstan/src/Parser/DirectParser.php on line 32
Call Stack:
0.0002 727872 1. {main}() /var/www/store/vendor/phpstan/phpstan/bin/phpstan:0
0.0122 2524880 2. Symfony\Component\Console\Application->run() /var/www/store/vendor/phpstan/phpstan/bin/phpstan:35
0.0155 2832496 3. Symfony\Component\Console\Application->doRun() /var/www/store/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:125
0.0156 2832496 4. Symfony\Component\Console\Application->doRunCommand() /var/www/store/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:224
0.0157 2832496 5. PHPStan\Command\AnalyseCommand->run() /var/www/store/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:888
0.0161 2838384 6. PHPStan\Command\AnalyseCommand->execute() /var/www/store/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:262
0.0393 6371328 7. PHPStan\Command\AnalyseApplication->analyse() /var/www/store/vendor/phpstan/phpstan/src/Command/AnalyseCommand.php:216
0.0396 6373136 8. PHPStan\Analyser\Analyser->analyse() /var/www/store/vendor/phpstan/phpstan/src/Command/AnalyseApplication.php:113
0.0518 7423488 9. PHPStan\Analyser\NodeScopeResolver->processNodes() /var/www/store/vendor/phpstan/phpstan/src/Analyser/Analyser.php:149
0.0520 7489024 10. PHPStan\Analyser\NodeScopeResolver->processNode() /var/www/store/vendor/phpstan/phpstan/src/Analyser/NodeScopeResolver.php:176
0.0521 7490816 11. PHPStan\Analyser\NodeScopeResolver->processNodes() /var/www/store/vendor/phpstan/phpstan/src/Analyser/NodeScopeResolver.php:586
0.0530 7490816 12. PHPStan\Analyser\NodeScopeResolver->processNode() /var/www/store/vendor/phpstan/phpstan/src/Analyser/NodeScopeResolver.php:176
0.0539 7579352 13. PHPStan\Analyser\NodeScopeResolver->processNodes() /var/www/store/vendor/phpstan/phpstan/src/Analyser/NodeScopeResolver.php:586
0.0551 7604072 14. PHPStan\Analyser\NodeScopeResolver->processNode() /var/www/store/vendor/phpstan/phpstan/src/Analyser/NodeScopeResolver.php:176
0.0584 7918504 15. PHPStan\Analyser\NodeScopeResolver->processNodes() /var/www/store/vendor/phpstan/phpstan/src/Analyser/NodeScopeResolver.php:586
0.0584 7918504 16. PHPStan\Analyser\NodeScopeResolver->processNode() /var/www/store/vendor/phpstan/phpstan/src/Analyser/NodeScopeResolver.php:176
0.0586 7919264 17. PHPStan\Analyser\NodeScopeResolver->processNode() /var/www/store/vendor/phpstan/phpstan/src/Analyser/NodeScopeResolver.php:650
0.0586 7919264 18. PHPStan\Analyser\Analyser->PHPStan\Analyser\{closure}() /var/www/store/vendor/phpstan/phpstan/src/Analyser/NodeScopeResolver.php:303
0.0586 7920016 19. PHPStan\Rules\Classes\InstantiationRule->processNode() /var/www/store/vendor/phpstan/phpstan/src/Analyser/Analyser.php:145
0.0586 7920696 20. PHPStan\Reflection\ClassReflection->getMethod() /var/www/store/vendor/phpstan/phpstan/src/Rules/Classes/InstantiationRule.php:114
0.0586 7921016 21. PHPStan\Reflection\Php\PhpClassReflectionExtension->getMethod() /var/www/store/vendor/phpstan/phpstan/src/Reflection/ClassReflection.php:108
0.0586 7921016 22. PHPStan\Reflection\Php\PhpClassReflectionExtension->createMethods() /var/www/store/vendor/phpstan/phpstan/src/Reflection/Php/PhpClassReflectionExtension.php:127
0.0589 7936832 23. PHPStan\Type\FileTypeMapper->getTypeMap() /var/www/store/vendor/phpstan/phpstan/src/Reflection/Php/PhpClassReflectionExtension.php:171
0.0591 7937152 24. PHPStan\Type\FileTypeMapper->createTypeMap() /var/www/store/vendor/phpstan/phpstan/src/Type/FileTypeMapper.php:42
0.0591 7938600 25. PHPStan\Parser\CachedParser->parseFile() /var/www/store/vendor/phpstan/phpstan/src/Type/FileTypeMapper.php:71
0.0591 7938600 26. PHPStan\Parser\DirectParser->parseFile() /var/www/store/vendor/phpstan/phpstan/src/Parser/CachedParser.php:29
0.0591 7938600 27. file_get_contents() /var/www/store/vendor/phpstan/phpstan/src/Parser/DirectParser.php:32
------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Line CouchbaseBasketRepository.php
------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Internal error: Argument 1 passed to PHPStan\Parser\DirectParser::parseString() must be of the type string, boolean given, called in /var/www/store/vendor/phpstan/phpstan/src/Parser/DirectParser.php on
line 32
------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[ERROR] Found 1 error
If I were to use \Couchbase\Cluster instead of \CouchbaseCluster, as stated in /opt/phpstorm/plugins/php/lib/php.jar!/stubs/couchbase/toplevel.php:23
class_alias("Couchbase\\Cluster", "CouchbaseCluster");
I'd get "only" class not found error, as shown below.
------ -------------------------------------------------------------------------
Line src/CouchbaseClusterFactory.php
------ -------------------------------------------------------------------------
17 Return typehint of method MyNamespace\CouchbaseClusterFactory::create() has invalid type Couchbase\Cluster.
19 Instantiated class Couchbase\Cluster not found.
------ -------------------------------------------------------------------------
[ERROR] Found 2 errors
But my code would not work since it is not actually supported by my Couchbase extension.
Is there a way to support working with classes from extensions or do I have to exclude the factory from analysis?
Thank you