Comments (19)
Thanks for opening your first issue here!
Weird problem, not exactly sure what is going on. Somehow the Extension Attribute Autoloaders get triggered even though the classname PHPStan\PhpDoc\PHPUnit\MockObjectTypeNodeResolverInterface
does not match the regex in both autoloaders.
Let me try to run a few tests to see if I can reproduce the problem somehow.
from phpstan-magento.
Hi @shochdoerfer, thanks for your hint about ./volumes/phpstan
and caching behavior about PHPStan. But the default caching behavior of PHPStan will not take into account, because it will run in docker. So I need to change the cache path. But I can try, what's happened, if I use a volume on PHPStan default cache folder. I will also check the behavior without docker.
from phpstan-magento.
Sadly, I can't reproduce your issue so far. I installed the PHPUnit extension in a test project and with or without the tmpDir setting, PHPStan works fine when I execute it multiple times in a row.
What confuses me a bit is that you write it fails when you enable the cache. PHPStan always uses a file cache. If you do not define the tmpDir
setting it will default to /tmp
. Could this be a problem with your ./volumes/phpstan
path?
Any chance that you can share a reproducible test case with me?
from phpstan-magento.
@Wohlie have you been able to figure out why things are failing?
from phpstan-magento.
Hi @shochdoerfer, I have tested without overriding the cache directory and have the same problem. If I change the config magentoRoot
to a path that not exists, I don't get this error, but PHPStan also will not understand Magento framework.
Here is my example. Make sure you mount Magento root folder to /var/www/default/src
.
docker-entrypoint.sh
#!/usr/bin/env bash
phpstan analyze vendor/magento/language-de_de
phpstan analyze vendor/magento/language-de_de
Dockerfile
FROM composer:2.2 as composer
FROM php:8.1-alpine
COPY --from=composer /usr/bin/composer /usr/local/bin/composer
ARG COMPOSER_ALLOW_SUPERUSER=1
ARG COMPOSER_HOME="/opt/composer"
ARG COMPOSER_BIN_DIR="/usr/local/bin"
ARG COMPOSER_CACHE_DIR="/var/cache/composer"
RUN echo 'memory_limit = 1G' > /usr/local/etc/php/conf.d/99-memory-limit.ini
RUN --mount=target=/var/cache,type=cache,sharing=locked \
apk add bash git
RUN --mount=target=/var/cache,type=cache,sharing=locked \
composer global require \
phpstan/phpstan \
bitexpert/phpstan-magento \
phpstan/phpstan-phpunit
RUN mkdir -p "/var/www/default/src"
WORKDIR /var/www/default/src
COPY docker-entrypoint.sh /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]
RUN addgroup -g 1000 -S non-root \
&& adduser -u 1000 -S non-root -G non-root -s /bin/bash
USER non-root
Place this phpstan.neon
in the Magento root folder.
includes:
- /opt/composer/vendor/bitexpert/phpstan-magento/extension.neon
- /opt/composer/vendor/phpstan/phpstan-phpunit/extension.neon
parameters:
level: 7
checkMissingIterableValueType: false
magento:
magentoRoot: .
from phpstan-magento.
can confirm this issue by using rector/rector and symplify/easy-coding-standard.
Also debugged a little bit, but didn't find the issue.
i'll have another look into this issue, if i'll find the time for it.
from phpstan-magento.
@rommelfreddy please provide a proper test case so that I can reproduce the issue and debug it.
from phpstan-magento.
digged a little bit deeper.
found out that the error got triggered by
/vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/SourceStubber/PhpStormStubs/CachingVisitor.php
Line 159
but do not have any idea what the context is. and also no clue who is calling this.
maybe it is a issue in rector. The same error has been already reported in the rector repo: rectorphp/rector#7430
but they already closed the issue.
i am using the latest versions of
- bitExpert/phpstan-magento
- rector/rector/
- phpstan/phpstan
- magento/ce
from phpstan-magento.
The issue which will happen is that the cache-folder can not created.
The error, which got printed is not the actual error.
The printed error does already occurs before trying to create the cache-dir (Class FileStorageCache).
The method error_get_last
will return the printed error, but this is not the error, why the cache-folder got not created.
Sadly i didn't figured out why the cache-folder got not created.
But maybe by the following issue:
If I have the following class, the error exists for me.
<?php
class MyClass
{
/**
* @var StoreFactory
*/
private $myFactory;
}
Please notice, that i missed the import or the FQCN for the factory.
If I have the following class, the error disappears.
<?php
class MyClass
{
/**
* @var \Magento\Store\Model\StoreFactory
*/
private $myFactory;
}
In my case the missing import is in a third-party package, so i only could fix the issue via composer-patches.
One addition:
it seems like that there are also general problems with the factory an bitexpert/phpstan-magento.
Did not figured out yet.
from phpstan-magento.
@rommelfreddy thx for digging deeper, "interesting" behavior. Not exactly sure why the cache file can't get written in your case. Maybe it's an idea to do an additional file_exists() check before requiring the file.
from phpstan-magento.
already tried this :D
from phpstan-magento.
need to correct me. The factory in my example does already exist as defined class (not autogenerated) in the same namespace (so also in the same folder).
It seems like, that there is something wrong with generating the factories.
Sadly i am not able to use xdebug within this scope. don't know why.
from phpstan-magento.
will you investigate more into this to fix this issue? it is a very annoying bug
from phpstan-magento.
@rommelfreddy my bad was quite busy with other stuff and lost track of this issue. Any chance you can provide me with a simple demo project to be able to reproduce the issue?
from phpstan-magento.
sadly not, because i can not tell to the proper way to reproduce the issue safely.
from phpstan-magento.
Hello, I have an issue with FileCacheStorage with rector and phpstan :(
- Rector version : 0.17.12
- PHP version : 8.1
- PHPStan version : 1.10.29
- bitexpert/phpstan-magento version : 0.30.1
I have this error when I run rector :
Could not process
"/home/***/Service/TransactionUrlsGen
erator.php" file, due to:
"System error: "Failed to create directory "cache/PHPStan" (Constant FILE_BINARY is deprecated)."
When I look the logs, I see that the problem comes from this module :
Full error trace
Could not process
"/home/***/Service/TransactionUrlsGen
erator.php" file, due to:
"System error: "Failed to create directory "cache/PHPStan" (Constant FILE_BINARY is deprecated)."
Stack trace:
#0 vendor/bitexpert/phpstan-magento/src/bitExpert/PHPStan/Magento/Autoload/Cache/FileCacheStorage.php(61):
bitExpert\PHPStan\Magento\Autoload\Cache\FileCacheStorage->makeDir()
#1 phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Cache/Cache.php(28):
bitExpert\PHPStan\Magento\Autoload\Cache\FileCacheStorage->save()
#2 vendor/bitexpert/phpstan-magento/src/bitExpert/PHPStan/Magento/Autoload/FactoryAutoloader.php(53):
PHPStan\Cache\Cache->save()
#3
phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/SourceLocator/A
utoloadSourceLocator.php(272): bitExpert\PHPStan\Magento\Autoload\FactoryAutoloader->autoload()
#4
phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/SourceLocator/F
ileReadTrapStreamWrapper.php(62):
PHPStan\Reflection\BetterReflection\SourceLocator\AutoloadSourceLocator::PHPStan\Reflection\BetterReflection\So
urceLocator\{closure}()
#5
phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/SourceLocator/A
utoloadSourceLocator.php(284):
PHPStan\Reflection\BetterReflection\SourceLocator\FileReadTrapStreamWrapper::withStreamWrapperOverride()
#6
phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/SourceLocator/A
utoloadSourceLocator.php(119):
PHPStan\Reflection\BetterReflection\SourceLocator\AutoloadSourceLocator->locateClassByName()
#7
phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Sourc
eLocator/Type/AggregateSourceLocator.php(26):
PHPStan\Reflection\BetterReflection\SourceLocator\AutoloadSourceLocator->locateIdentifier()
#8
phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Sourc
eLocator/Type/MemoizingSourceLocator.php(33):
PHPStan\BetterReflection\SourceLocator\Type\AggregateSourceLocator->locateIdentifier()
#9
phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Sourc
eLocator/Type/AggregateSourceLocator.php(26):
PHPStan\BetterReflection\SourceLocator\Type\MemoizingSourceLocator->locateIdentifier()
#10
phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Sourc
eLocator/Type/MemoizingSourceLocator.php(33):
PHPStan\BetterReflection\SourceLocator\Type\AggregateSourceLocator->locateIdentifier()
#11
phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Refle
ctor/DefaultReflector.php(32):
PHPStan\BetterReflection\SourceLocator\Type\MemoizingSourceLocator->locateIdentifier()
#12
phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/Reflector/Memoi
zingReflector.php(45): PHPStan\BetterReflection\Reflector\DefaultReflector->reflectClass()
#13
phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/BetterReflectio
nProvider.php(147): PHPStan\Reflection\BetterReflection\Reflector\MemoizingReflector->reflectClass()
#14
phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ReflectionProvider/MemoizingRefl
ectionProvider.php(35): PHPStan\Reflection\BetterReflection\BetterReflectionProvider->hasClass()
#15 phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Type/ObjectType.php(1122):
PHPStan\Reflection\ReflectionProvider\MemoizingReflectionProvider->hasClass()
#16 phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Type/ObjectType.php(547):
PHPStan\Type\ObjectType->getClassReflection()
#17 phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(3441):
PHPStan\Type\ObjectType->hasMethod()
#18 phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(3460):
PHPStan\Analyser\MutatingScope->filterTypeWithMethod()
#19 phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1376):
PHPStan\Analyser\MutatingScope->methodCallReturnType()
#20 phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1382):
PHPStan\Analyser\MutatingScope->PHPStan\Analyser\{closure}()
#21 phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(564):
PHPStan\Analyser\MutatingScope->resolveType()
#22 phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(761):
PHPStan\Analyser\MutatingScope->getType()
#23 phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(564):
PHPStan\Analyser\MutatingScope->resolveType()
#24 phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1545):
PHPStan\Analyser\MutatingScope->getType()
#25 phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(598):
PHPStan\Analyser\NodeScopeResolver->findEarlyTerminatingExpr()
#26 phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(384):
PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#27 phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(557):
PHPStan\Analyser\NodeScopeResolver->processStmtNodes()
#28 phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(384):
PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#29 phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(640):
PHPStan\Analyser\NodeScopeResolver->processStmtNodes()
#30 phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(384):
PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#31 phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(612):
PHPStan\Analyser\NodeScopeResolver->processStmtNodes()
#32 phar://vendor/rector/rector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(353):
PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#33 vendor/rector/rector/packages/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php(378):
PHPStan\Analyser\NodeScopeResolver->processNodes()
#34 vendor/rector/rector/packages/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php(252):
Rector\NodeTypeResolver\PHPStan\Scope\PHPStanNodeScopeResolver->processNodesWithDependentFiles()
#35 vendor/rector/rector/packages/NodeTypeResolver/NodeScopeAndMetadataDecorator.php(56):
Rector\NodeTypeResolver\PHPStan\Scope\PHPStanNodeScopeResolver->processNodes()
#36 vendor/rector/rector/src/Application/FileProcessor.php(39):
Rector\NodeTypeResolver\NodeScopeAndMetadataDecorator->decorateNodesFromFile()
#37 vendor/rector/rector/src/Application/FileProcessor/PhpFileProcessor.php(150):
Rector\Core\Application\FileProcessor->parseFileInfoToLocalCache()
#38 vendor/rector/rector/src/Application/FileProcessor/PhpFileProcessor.php(90):
Rector\Core\Application\FileProcessor\PhpFileProcessor->parseFileAndDecorateNodes()
#39 vendor/rector/rector/src/Application/ApplicationFileProcessor.php(176):
Rector\Core\Application\FileProcessor\PhpFileProcessor->process()
#40 vendor/rector/rector/src/Application/ApplicationFileProcessor.php(149):
Rector\Core\Application\ApplicationFileProcessor->processFile()
#41 vendor/rector/rector/packages/Parallel/WorkerRunner.php(65):
Rector\Core\Application\ApplicationFileProcessor->processFiles()
#42 vendor/rector/rector/vendor/evenement/evenement/src/EventEmitterTrait.php(111):
Rector\Parallel\WorkerRunner->Rector\Parallel\{closure}()
#43 vendor/rector/rector/vendor/clue/ndjson-react/src/Decoder.php(117):
RectorPrefix202308\Evenement\EventEmitter->emit()
#44 vendor/rector/rector/vendor/evenement/evenement/src/EventEmitterTrait.php(111):
RectorPrefix202308\Clue\React\NDJson\Decoder->handleData()
#45 vendor/rector/rector/vendor/react/stream/src/Util.php(62):
RectorPrefix202308\Evenement\EventEmitter->emit()
#46 vendor/rector/rector/vendor/evenement/evenement/src/EventEmitterTrait.php(111):
RectorPrefix202308\React\Stream\Util::RectorPrefix202308\React\Stream\{closure}()
#47 vendor/rector/rector/vendor/react/stream/src/DuplexResourceStream.php(154):
RectorPrefix202308\Evenement\EventEmitter->emit()
#48 vendor/rector/rector/vendor/react/event-loop/src/StreamSelectLoop.php(201):
RectorPrefix202308\React\Stream\DuplexResourceStream->handleData()
#49 vendor/rector/rector/vendor/react/event-loop/src/StreamSelectLoop.php(173):
RectorPrefix202308\React\EventLoop\StreamSelectLoop->waitForStreamActivity()
#50 vendor/rector/rector/src/Console/Command/WorkerCommand.php(73):
RectorPrefix202308\React\EventLoop\StreamSelectLoop->run()
#51 vendor/rector/rector/vendor/symfony/console/Command/Command.php(327):
Rector\Core\Console\Command\WorkerCommand->execute()
#52 vendor/rector/rector/vendor/symfony/console/Application.php(944):
RectorPrefix202308\Symfony\Component\Console\Command\Command->run()
#53 vendor/rector/rector/vendor/symfony/console/Application.php(326):
RectorPrefix202308\Symfony\Component\Console\Application->doRunCommand()
#54 vendor/rector/rector/src/Console/ConsoleApplication.php(65):
RectorPrefix202308\Symfony\Component\Console\Application->doRun()
#55 vendor/rector/rector/vendor/symfony/console/Application.php(212):
Rector\Core\Console\ConsoleApplication->doRun()
#56 vendor/rector/rector/bin/rector.php(132): RectorPrefix202308\Symfony\Component\Console\Application->run()
#57 vendor/rector/rector/bin/rector(5): require_once('...')
#58 {main}". On line: 107
from phpstan-magento.
@dimitriBouteille thx for reporting this. Any chance you could provide me with more details and a demo project which allows me to reproduce the issue? I haven't yet used Rector, and I am not sure if you are running Rector (wich runs PHPStan?) or if you just have Rector installed and you run PHPStan. The more I understand, the better I can debug the issue and hopefully provide a fix.
Not sure why the cache directory could not be created. Are you running your setup also in Docker?
from phpstan-magento.
@shochdoerfer Thanks for the quick response:)
I can’t share the source code of the project, it’s a private project.
To bring information, I installed rector in addition to phpstan and the Magento extension. It is when I execute php vendor/bin/rector process
that I have the error and I do not know why it launches phpstan ... I request additional information in this issue: rectorphp/rector#8139
I don’t use Docker.
Do you know if it is possible to disable the cache while waiting for a fix?
If it helps, here is the phpstan configuration and rector :
rector.php
return static function (\Rector\Config\RectorConfig $rectorConfig): void {
$rectorConfig
->paths([
__DIR__ . '/Api',
__DIR__ . '/Block',
__DIR__ . '/Controller',
__DIR__ . '/Cron',
__DIR__ . '/Gateway',
__DIR__ . '/Helper',
__DIR__ . '/Logger',
__DIR__ . '/Model',
__DIR__ . '/Ui',
]);
$rectorConfig->cacheDirectory(__DIR__ . '/var/cache/rector');
$rectorConfig->containerCacheDirectory(__DIR__);
$rectorConfig->phpVersion(\Rector\Core\ValueObject\PhpVersion::PHP_81);
$rectorConfig->importShortClasses(false);
// register single rule
$rectorConfig
->rule(\Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector::class);
// ??
$rectorConfig->skip([
\Rector\CodeQuality\Rector\Array_\CallableThisArrayToAnonymousFunctionRector::class,
]);
// here we can define, what sets of rules will be applied
// tip: use "SetList" class to autocomplete sets with your IDE
$rectorConfig->sets([
\Rector\Set\ValueObject\SetList::CODE_QUALITY,
]);
};
phpstan.neon
parameters:
level: 5
excludePaths:
- vendor
- etc
- view
- doc
- rector.php
ignoreErrors:
-
message: '#Use service contracts to persist entities in favour of Magento\\Quote\\Model\\QuoteIdMask::load\(\) method#'
-
message: '#Parameter \#1 \$prefix of method Magento\\Framework\\View\\Page\\Title::prepend\(\) expects string, Magento\\Framework\\Phrase given.#'
-
message: '#Parameter \#1 \$message of method Magento\\Framework\\Message\\ManagerInterface::addErrorMessage\(\) expects string, Magento\\Framework\\Phrase given.#'
-
message: '#Parameter \#1 \$modelId of method Magento\\Framework\\Model\\AbstractModel::load\(\) expects int, string given.#'
paths:
- .
from phpstan-magento.
Hello @shochdoerfer Any news ?
from phpstan-magento.
Related Issues (20)
- Missing check when using factory constant HOT 1
- No coverage data is *not* sent to Coveralls
- Certain CI steps run several times without additional result HOT 1
- Move stubs out of src/ HOT 6
- DateTimeFactory Issue; HOT 6
- Use Magento root for TestFrameworkAutoloader HOT 8
- Project config file at path app/code/Vendor/Module does not exist. HOT 5
- Factory generation misnames output class HOT 4
- Current release version not updated HOT 5
- Wrong directory used as "magentoRoot" when current working direcory is not magento root HOT 2
- private string $magentoRoot; not work in PHP 7.2 HOT 4
- Generated class ProductExtension is passed on incorrectly to phpstan HOT 30
- Missing Interface class HOT 9
- Add support for PHP 8.2 HOT 3
- Compatibility with PHPstan 1.10.x HOT 4
- Version 0.30.0 fails with errors about unexpected items in parameters HOT 4
- Extend ci_neon_lint script to validate parametersSchema
- Incompatibility with phpstan & rector and 2.4.6 HOT 1
- Internal error: Class\Foo does not exist and has no extension interface in file class.php HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phpstan-magento.