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

Failure with phpstan/phpstan-phpunit and PHPStan cache usage #297

Open
Wohlie opened this issue Mar 22, 2023 · 19 comments
Open

Failure with phpstan/phpstan-phpunit and PHPStan cache usage #297

Wohlie opened this issue Mar 22, 2023 · 19 comments

Comments

@Wohlie
Copy link

Wohlie commented Mar 22, 2023

Hi, I'm using this extension together with phpstan/phpstan-phpunit.

bitexpert/phpstan-magento         v0.29.0 PHPStan Magento Extension
phpstan/phpstan                   1.10.7  PHPStan - PHP Static Analysis Tool
phpstan/phpstan-phpunit           1.3.10  PHPUnit extensions and rules for PHPStan

Without PHPStan cache, everything works fine. If I enable PHPStan cache, I receive get the following error on the second run, where that cache is used:

In ExtensionInterfaceAutoloader.php line 93:
                                                                                                            
  [InvalidArgumentException]                                                                                
  PHPStan\PhpDoc\PHPUnit\MockObjectTypeNodeResolverInterface does not exist and has no extension interface  
                                                                                                            

Exception trace:
  at /opt/composer/vendor/bitexpert/phpstan-magento/src/bitExpert/PHPStan/Magento/Autoload/ExtensionInterfaceAutoloader.php:93
 bitExpert\PHPStan\Magento\Autoload\ExtensionInterfaceAutoloader->getFileContents() at /opt/composer/vendor/bitexpert/phpstan-magento/src/bitExpert/PHPStan/Magento/Autoload/ExtensionInterfaceAutoloader.php:69
 bitExpert\PHPStan\Magento\Autoload\ExtensionInterfaceAutoloader->autoload() at n/a:n/a
 ReflectionClass->__construct() at /opt/composer/vendor/bitexpert/phpstan-magento/src/bitExpert/PHPStan/Magento/Autoload/ExtensionAutoloader.php:87
 bitExpert\PHPStan\Magento\Autoload\ExtensionAutoloader->getFileContents() at /opt/composer/vendor/bitexpert/phpstan-magento/src/bitExpert/PHPStan/Magento/Autoload/ExtensionAutoloader.php:70
 bitExpert\PHPStan\Magento\Autoload\ExtensionAutoloader->autoload() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/SourceLocator/AutoloadFunctionsSourceLocator.php:41
 PHPStan\Reflection\BetterReflection\SourceLocator\AutoloadFunctionsSourceLocator->locateIdentifier() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/AggregateSourceLocator.php:26
 PHPStan\BetterReflection\SourceLocator\Type\AggregateSourceLocator->locateIdentifier() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/MemoizingSourceLocator.php:33
 PHPStan\BetterReflection\SourceLocator\Type\MemoizingSourceLocator->locateIdentifier() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Reflector/DefaultReflector.php:32
 PHPStan\BetterReflection\Reflector\DefaultReflector->reflectClass() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/Reflector/MemoizingReflector.php:45
 PHPStan\Reflection\BetterReflection\Reflector\MemoizingReflector->reflectClass() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/BetterReflectionProvider.php:149
 PHPStan\Reflection\BetterReflection\BetterReflectionProvider->hasClass() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ReflectionProvider/MemoizingReflectionProvider.php:35
 PHPStan\Reflection\ReflectionProvider\MemoizingReflectionProvider->hasClass() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/ResultCache/ResultCacheManager.php:552
 PHPStan\Analyser\ResultCache\ResultCacheManager->getProjectExtensionFiles() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/ResultCache/ResultCacheManager.php:528
 PHPStan\Analyser\ResultCache\ResultCacheManager->save() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/ResultCache/ResultCacheManager.php:363
 PHPStan\Analyser\ResultCache\ResultCacheManager->PHPStan\Analyser\ResultCache\{closure}() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/ResultCache/ResultCacheManager.php:386
 PHPStan\Analyser\ResultCache\ResultCacheManager->process() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseApplication.php:108
 PHPStan\Command\AnalyseApplication->analyse() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseCommand.php:173
 PHPStan\Command\AnalyseCommand->execute() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php:259
 _PHPStan_e0e4f009c\Symfony\Component\Console\Command\Command->run() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php:870
 _PHPStan_e0e4f009c\Symfony\Component\Console\Application->doRunCommand() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php:261
 _PHPStan_e0e4f009c\Symfony\Component\Console\Application->doRun() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php:157
 _PHPStan_e0e4f009c\Symfony\Component\Console\Application->run() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan:124
 _PHPStan_e0e4f009c\{closure}() at phar:///opt/composer/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan:125
 require() at /opt/composer/vendor/phpstan/phpstan/phpstan:8
 include() at /usr/local/bin/phpstan:120

analyse [-c|--configuration CONFIGURATION] [-l|--level LEVEL] [--no-progress] [--debug] [-a|--autoload-file AUTOLOAD-FILE] [--error-format ERROR-FORMAT] [-b|--generate-baseline [GENERATE-BASELINE]] [--allow-empty-baseline] [--memory-limit MEMORY-LIMIT] [--xdebug] [--fix] [--watch] [--pro] [--] [<paths>...]

My configuration is the following:

includes:
    - /opt/composer/vendor/bitexpert/phpstan-magento/extension.neon
    - /opt/composer/vendor/phpstan/phpstan-phpunit/extension.neon

parameters:
    level: 7
    checkMissingIterableValueType: false
    tmpDir: ./volumes/phpstan
    bootstrapFiles:
        - ./src/vendor/autoload.php
    magento:
        magentoRoot: ./src

Any thoughts?

@Wohlie Wohlie changed the title Failure with phpstan/phpstan-phpunit and PHPStan cache usage. Failure with phpstan/phpstan-phpunit and PHPStan cache usage Mar 22, 2023
@shochdoerfer
Copy link
Member

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.

@shochdoerfer
Copy link
Member

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?

@Wohlie
Copy link
Author

Wohlie commented Mar 28, 2023

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.

@shochdoerfer
Copy link
Member

@Wohlie have you been able to figure out why things are failing?

@Wohlie
Copy link
Author

Wohlie commented Apr 8, 2023

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: .

@rommelfreddy
Copy link

rommelfreddy commented May 24, 2023

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.

@shochdoerfer
Copy link
Member

@rommelfreddy please provide a proper test case so that I can reproduce the issue and debug it.

@rommelfreddy
Copy link

rommelfreddy commented May 24, 2023

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

image

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

@rommelfreddy
Copy link

rommelfreddy commented May 25, 2023

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.

@shochdoerfer
Copy link
Member

@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.

@rommelfreddy
Copy link

already tried this :D

@rommelfreddy
Copy link

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.

@rommelfreddy
Copy link

will you investigate more into this to fix this issue? it is a very annoying bug

@shochdoerfer
Copy link
Member

@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?

@rommelfreddy
Copy link

sadly not, because i can not tell to the proper way to reproduce the issue safely.

@dimitriBouteille
Copy link

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

@shochdoerfer
Copy link
Member

@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?

@dimitriBouteille
Copy link

@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:
	    - .

@dimitriBouteille
Copy link

Hello @shochdoerfer Any news ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants