Skip to content

Phpstan first batch of fixes#1075

Merged
rthideaway merged 51 commits intodrupal-graphql:8.x-4.xfrom
Dylan203:fix/phpstan-iteration-1
Sep 10, 2020
Merged

Phpstan first batch of fixes#1075
rthideaway merged 51 commits intodrupal-graphql:8.x-4.xfrom
Dylan203:fix/phpstan-iteration-1

Conversation

@Dylan203
Copy link
Copy Markdown
Contributor

No description provided.

Comment thread src/Controller/ExplorerController.php Outdated
* @codeCoverageIgnore
*/
public function __construct(UrlGeneratorInterface $urlGenerator, Introspection $introspection, SchemaPluginManager $pluginManager) {
public final function __construct(UrlGeneratorInterface $urlGenerator, Introspection $introspection, SchemaPluginManager $pluginManager) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in drupal we don't have final constructors. What is the error message from phstan that you get for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsafe usage of new static().
💡 Consider making the class or the constructor final.

Copy link
Copy Markdown
Contributor

@klausi klausi Aug 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes, that is not a best practice in Drupal, so we should not fix that.
Use this exception:

# new static() is a best practice in Drupal, so we cannot fix that.
- "#^Unsafe usage of new static\\(\\)\\.$#"

Comment thread phpstan.neon Outdated
paths:
- ../../../graphql
excludes_analyse:
- ../../../graphql/src/Entity/Server.php #Class GraphQL\Executor\ExecutionResult not found.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you get this error because the onyx graphql vendor library might be missing locally?

I think you need the same setup as in travis CI: a drupal 8 checkout where this graphql module is in the modules folder + the composer dependencies installed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm ich schaus mir nochmal an.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hab jetzt nochmal alles neu installiert, kriege immer noch diesen Error

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weiters kommt das immer ganz unten als Error auf:

Child process error (exit code 255): PHP Fatal error: During class fetch: Uncaught PHPStan\Broker\ClassAutoloadingException: Class Drupal\typed_data\DataFetcherTrait not found. in
phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/src/Reflection/Runtime/RuntimeReflectionProvider.php:125
Stack trace:
#0 [internal function]: PHPStan\Reflection\Runtime\RuntimeReflectionProvider->PHPStan\Reflection\Runtime{closure}()
#1 /home/dylan/Drupal8-Template/web/modules/graphql/src/GraphQL/Resolver/Path.php(18): spl_autoload_call()
#2 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/vendor/composer/ClassLoader.php(444): include('/home/dylan/Dru...')
#3 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/vendor/composer/ClassLoader.php(322): Composer\Autoload\includeFile()
#4 [internal function]: Composer\Autoload\ClassLoader->loadClass()
#5 [internal function]: spl_autoload_call()
#6 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/src/Reflection/Runtime/RuntimeReflectionProvider.php(129): class_exists()
#7 p in /home/dylan/Drupal8-Template/web/modules/graphql/src/GraphQL/Resolver/Path.php on line 18
Fatal error: During class fetch: Uncaught PHPStan\Broker\ClassAutoloadingException: Class Drupal\typed_data\DataFetcherTrait not found. in
phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/src/Reflection/Runtime/RuntimeReflectionProvider.php:125
Stack trace:
#0 [internal function]: PHPStan\Reflection\Runtime\RuntimeReflectionProvider->PHPStan\Reflection\Runtime{closure}()
#1 /home/dylan/Drupal8-Template/web/modules/graphql/src/GraphQL/Resolver/Path.php(18): spl_autoload_call()
#2 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/vendor/composer/ClassLoader.php(444): include('/home/dylan/Dru...')
#3 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/vendor/composer/ClassLoader.php(322): Composer\Autoload\includeFile()
#4 [internal function]: Composer\Autoload\ClassLoader->loadClass()
#5 [internal function]: spl_autoload_call()
#6 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/src/Reflection/Runtime/RuntimeReflectionProvider.php(129): class_exists()
#7 p in /home/dylan/Drupal8-Template/web/modules/graphql/src/GraphQL/Resolver/Path.php on line 18

 Child process error (exit code 255): PHP Fatal error:  During class fetch: Uncaught PHPStan\Broker\ClassAutoloadingException: Class Drupal\typed_data\DataFetcherTrait not found. in                 
 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/src/Reflection/Runtime/RuntimeReflectionProvider.php:125                                                                          
 Stack trace:                                                                                                                                                                                         
 #0 [internal function]: PHPStan\Reflection\Runtime\RuntimeReflectionProvider->PHPStan\Reflection\Runtime\{closure}()                                                                                 
 #1 /home/dylan/Drupal8-Template/web/modules/graphql/src/GraphQL/Resolver/Path.php(18): spl_autoload_call()                                                                                           
 #2 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/vendor/composer/ClassLoader.php(444): include('/home/dylan/Dru...')                                                            
 #3 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/vendor/composer/ClassLoader.php(322): Composer\Autoload\includeFile()                                                          
 #4 [internal function]: Composer\Autoload\ClassLoader->loadClass()                                                                                                                                   
 #5 [internal function]: spl_autoload_call()                                                                                                                                                          
 #6 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/src/Reflection/Runtime/RuntimeReflectionProvider.php(129): class_exists()                                                      
 #7 p in /home/dylan/Drupal8-Template/web/modules/graphql/src/GraphQL/Resolver/Path.php on line 18                                                                                                    
 Fatal error: During class fetch: Uncaught PHPStan\Broker\ClassAutoloadingException: Class Drupal\typed_data\DataFetcherTrait not found. in                                                           
 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/src/Reflection/Runtime/RuntimeReflectionProvider.php:125                                                                          
 Stack trace:                                                                                                                                                                                         
 #0 [internal function]: PHPStan\Reflection\Runtime\RuntimeReflectionProvider->PHPStan\Reflection\Runtime\{closure}()                                                                                 
 #1 /home/dylan/Drupal8-Template/web/modules/graphql/src/GraphQL/Resolver/Path.php(18): spl_autoload_call()                                                                                           
 #2 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/vendor/composer/ClassLoader.php(444): include('/home/dylan/Dru...')                                                            
 #3 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/vendor/composer/ClassLoader.php(322): Composer\Autoload\includeFile()                                                          
 #4 [internal function]: Composer\Autoload\ClassLoader->loadClass()                                                                                                                                   
 #5 [internal function]: spl_autoload_call()                                                                                                                                                          
 #6 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/src/Reflection/Runtime/RuntimeReflectionProvider.php(129): class_exists()                                                      
 #7 p in /home/dylan/Drupal8-Template/web/modules/graphql/src/GraphQL/Resolver/Path.php on line 18                                                                                                    
                                                                                                                                                                                                      
 Child process error (exit code 255): PHP Fatal error:  During class fetch: Uncaught PHPStan\Broker\ClassAutoloadingException: Class Drupal\typed_data\DataFetcherTrait not found. in                 
 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/src/Reflection/Runtime/RuntimeReflectionProvider.php:125                                                                          
 Stack trace:                                                                                                                                                                                         
 #0 [internal function]: PHPStan\Reflection\Runtime\RuntimeReflectionProvider->PHPStan\Reflection\Runtime\{closure}()                                                                                 
 #1 /home/dylan/Drupal8-Template/web/modules/graphql/src/Plugin/GraphQL/DataProducer/TypedData/PropertyPath.php(36): spl_autoload_call()                                                              
 #2 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/vendor/composer/ClassLoader.php(444): include('/home/dylan/Dru...')                                                            
 #3 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/vendor/composer/ClassLoader.php(322): Composer\Autoload\includeFile()                                                          
 #4 [internal function]: Composer\Autoload\ClassLoader->loadClass()                                                                                                                                   
 #5 [internal function]: spl_autoload_call()                                                                                                                                                          
 #6 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/src/Reflection/Runtime/RuntimeReflectionProvider. in                                                                           
 /home/dylan/Drupal8-Template/web/modules/graphql/src/Plugin/GraphQL/DataProducer/TypedData/PropertyPath.php on line 36                                                                               
 Fatal error: During class fetch: Uncaught PHPStan\Broker\ClassAutoloadingException: Class Drupal\typed_data\DataFetcherTrait not found. in                                                           
 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/src/Reflection/Runtime/RuntimeReflectionProvider.php:125                                                                          
 Stack trace:                                                                                                                                                                                         
 #0 [internal function]: PHPStan\Reflection\Runtime\RuntimeReflectionProvider->PHPStan\Reflection\Runtime\{closure}()                                                                                 
 #1 /home/dylan/Drupal8-Template/web/modules/graphql/src/Plugin/GraphQL/DataProducer/TypedData/PropertyPath.php(36): spl_autoload_call()                                                              
 #2 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/vendor/composer/ClassLoader.php(444): include('/home/dylan/Dru...')                                                            
 #3 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/vendor/composer/ClassLoader.php(322): Composer\Autoload\includeFile()                                                          
 #4 [internal function]: Composer\Autoload\ClassLoader->loadClass()                                                                                                                                   
 #5 [internal function]: spl_autoload_call()                                                                                                                                                          
 #6 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/src/Reflection/Runtime/RuntimeReflectionProvider. in                                                                           
 /home/dylan/Drupal8-Template/web/modules/graphql/src/Plugin/GraphQL/DataProducer/TypedData/PropertyPath.php on line 36                                                                               
                                                                                                                                                                                                      
 Child process error (exit code 255): PHP Fatal error:  Declaration of Drupal\KernelTests\KernelTestBase::setUpBeforeClass() must be compatible with PHPUnit\Framework\TestCase::setUpBeforeClass():  
 void in /home/dylan/Drupal8-Template/web/core/tests/Drupal/KernelTests/KernelTestBase.php on line 227                                                                                                
 Fatal error: Declaration of Drupal\KernelTests\KernelTestBase::setUpBeforeClass() must be compatible with PHPUnit\Framework\TestCase::setUpBeforeClass(): void in                                    
 /home/dylan/Drupal8-Template/web/core/tests/Drupal/KernelTests/KernelTestBase.php on line 227                                                                                                        
                                                                                                                                                                                                      
 Child process error (exit code 255): PHP Fatal error:  During class fetch: Uncaught PHPStan\Broker\ClassAutoloadingException: Class Drupal\typed_data\DataFetcherTrait not found. in                 
 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/src/Reflection/Runtime/RuntimeReflectionProvider.php:125                                                                          
 Stack trace:                                                                                                                                                                                         
 #0 [internal function]: PHPStan\Reflection\Runtime\RuntimeReflectionProvider->PHPStan\Reflection\Runtime\{closure}()                                                                                 
 #1 /home/dylan/Drupal8-Template/web/modules/graphql/src/GraphQL/ResolverBuilder.php(22): spl_autoload_call()                                                                                         
 #2 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/vendor/composer/ClassLoader.php(444): include('/home/dylan/Dru...')                                                            
 #3 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/vendor/composer/ClassLoader.php(322): Composer\Autoload\includeFile()                                                          
 #4 [internal function]: Composer\Autoload\ClassLoader->loadClass()                                                                                                                                   
 #5 [internal function]: spl_autoload_call()                                                                                                                                                          
 #6 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/src/Reflection/Runtime/RuntimeReflectionProvider.php(129): class_exists()                                                      
 #7 in /home/dylan/Drupal8-Template/web/modules/graphql/src/GraphQL/ResolverBuilder.php on line 22                                                                                                    
 Fatal error: During class fetch: Uncaught PHPStan\Broker\ClassAutoloadingException: Class Drupal\typed_data\DataFetcherTrait not found. in                                                           
 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/src/Reflection/Runtime/RuntimeReflectionProvider.php:125                                                                          
 Stack trace:                                                                                                                                                                                         
 #0 [internal function]: PHPStan\Reflection\Runtime\RuntimeReflectionProvider->PHPStan\Reflection\Runtime\{closure}()                                                                                 
 #1 /home/dylan/Drupal8-Template/web/modules/graphql/src/GraphQL/ResolverBuilder.php(22): spl_autoload_call()                                                                                         
 #2 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/vendor/composer/ClassLoader.php(444): include('/home/dylan/Dru...')                                                            
 #3 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/vendor/composer/ClassLoader.php(322): Composer\Autoload\includeFile()                                                          
 #4 [internal function]: Composer\Autoload\ClassLoader->loadClass()                                                                                                                                   
 #5 [internal function]: spl_autoload_call()                                                                                                                                                          
 #6 phar:///home/dylan/Drupal8-Template/vendor/phpstan/phpstan/phpstan/src/Reflection/Runtime/RuntimeReflectionProvider.php(129): class_exists()                                                      
 #7 in /home/dylan/Drupal8-Template/web/modules/graphql/src/GraphQL/ResolverBuilder.php on line 22     

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to install the dependencies of graphql module, see https://github.com/drupal-graphql/graphql/blob/8.x-4.x/.travis.yml#L90

composer require webonyx/graphql-php:^0.13.1 drupal/typed_data:^1.0

Comment thread .travis.yml Outdated
# Install Phpstan to check for Drupal standards
- composer global require mglaman/phpstan-drupal ^0.12.3
- composer global require phpstan/phpstan-deprecation-rules ^0.12.2
- composer global require phpunit/phpunit
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line is not needed

Comment thread .travis.yml Outdated

# Install Phpstan to check for Drupal standards
- composer global require mglaman/phpstan-drupal ^0.12.3
- composer global require phpstan/phpstan-deprecation-rules ^0.12.2
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those 2 lines can be summarized into 1. We should also run it the same way as above for webonyx/graphql-php

Comment thread .travis.yml Outdated
fi

# Run Phpstan
- cd $DRUPAL_BUILD_DIR && ../vendor/bin/phpstan analyse -c /modules/graphql/phpstan.neon
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to run phpstan in the graphql module directory, like we do with phpcs above

@rthideaway rthideaway requested a review from klausi September 9, 2020 20:50
@rthideaway rthideaway self-assigned this Sep 9, 2020
Copy link
Copy Markdown
Contributor

@klausi klausi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow nice, thanks for finishing this up Rado!!!!

Not that of a big change and almost everything looks good to me. 2 minor comments for the config file, but then we can merge this.

I saw that we forgot to add the fileExtensions config https://phpstan.org/config-reference#analysed-files . We don't have much code in module files, so should not be a big difference. We can do this here or in a follow-up.

Comment thread phpstan.neon Outdated
level: 1
customRulesetUsed: true
paths:
- ../graphql
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just use "."?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually I was looking at this as well :D wanted to fix it and forgot about it, will adjust it

Comment thread phpstan.neon Outdated
ignoreErrors:
# @todo Ignore phpstan-drupal extension's rules for now, activate later.
- '#\Drupal calls should be avoided in classes, use dependency injection instead#'
# We have a hacked Symfony 4 event component (instead of 3) because of
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy/paste error for this comment?

@rthideaway rthideaway merged commit dad9d59 into drupal-graphql:8.x-4.x Sep 10, 2020
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

Successfully merging this pull request may close these issues.

3 participants