Phpstan first batch of fixes#1075
Conversation
| * @codeCoverageIgnore | ||
| */ | ||
| public function __construct(UrlGeneratorInterface $urlGenerator, Introspection $introspection, SchemaPluginManager $pluginManager) { | ||
| public final function __construct(UrlGeneratorInterface $urlGenerator, Introspection $introspection, SchemaPluginManager $pluginManager) { |
There was a problem hiding this comment.
in drupal we don't have final constructors. What is the error message from phstan that you get for this?
There was a problem hiding this comment.
Unsafe usage of new static().
💡 Consider making the class or the constructor final.
There was a problem hiding this comment.
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\\(\\)\\.$#"
| paths: | ||
| - ../../../graphql | ||
| excludes_analyse: | ||
| - ../../../graphql/src/Entity/Server.php #Class GraphQL\Executor\ExecutionResult not found. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Hmm ich schaus mir nochmal an.
There was a problem hiding this comment.
Hab jetzt nochmal alles neu installiert, kriege immer noch diesen Error
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
| # 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 |
|
|
||
| # 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 |
There was a problem hiding this comment.
those 2 lines can be summarized into 1. We should also run it the same way as above for webonyx/graphql-php
| fi | ||
|
|
||
| # Run Phpstan | ||
| - cd $DRUPAL_BUILD_DIR && ../vendor/bin/phpstan analyse -c /modules/graphql/phpstan.neon |
There was a problem hiding this comment.
we need to run phpstan in the graphql module directory, like we do with phpcs above
klausi
left a comment
There was a problem hiding this comment.
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.
| level: 1 | ||
| customRulesetUsed: true | ||
| paths: | ||
| - ../graphql |
There was a problem hiding this comment.
actually I was looking at this as well :D wanted to fix it and forgot about it, will adjust it
| 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 |
There was a problem hiding this comment.
Copy/paste error for this comment?
No description provided.