composer require --dev phpstan/phpstan
- Add composer patch https://github.com/phpstan/phpstan/pull/1080.patch
- Put this files to your project in
phpstan
directory - Run it:
./bin/phpstan analyse -c ./phpstan/phpstan.neon -l max docroot/modules/custom/
Last active
December 3, 2018 16:02
-
-
Save zviryatko/505428ecb085a6f541f83137d208b560 to your computer and use it in GitHub Desktop.
phpstan for Drupal 8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* Improve phpstan's excludes_analyse parameter to support file masks. | |
*/ | |
/** @var \Nette\DI\Container $container */ | |
$excludes = []; | |
foreach ($container->parameters['excludes_analyse'] as $exclude) { | |
if (strpos($exclude, '*') === FALSE) { | |
continue; | |
} | |
$excludes = array_merge($excludes, glob($exclude)); | |
} | |
$container->parameters['excludes_analyse'] = array_merge($container->parameters['excludes_analyse'], array_unique($excludes)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* Bootstrap drupal to allow autoload from modules src directory. | |
*/ | |
use Drupal\Component\Utility\NestedArray; | |
use Drupal\Core\Config\FileStorage; | |
use Drupal\Core\DrupalKernel; | |
use Drupal\Core\Site\Settings; | |
use Symfony\Component\HttpFoundation\Request; | |
foreach (spl_autoload_functions() as list($autoloader)) { | |
if ($autoloader instanceof \Composer\Autoload\ClassLoader) { | |
break; | |
} | |
} | |
$request = Request::createFromGlobals(); | |
chdir(dirname(__DIR__) . '/docroot'); | |
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod', FALSE, dirname(__DIR__) . '/docroot'); | |
new Settings(NestedArray::mergeDeepArray([ | |
Settings::getAll(), | |
[ | |
'bootstrap_config_storage' => function () { | |
return new FileStorage(config_get_config_directory(CONFIG_SYNC_DIRECTORY)); | |
}, | |
'container_yamls' => [DRUPAL_ROOT . '/sites/development.services.yml'], | |
'cache' => [ | |
'bins' => [ | |
'bootstrap' => 'cache.backend.null', | |
'config' => 'cache.backend.null', | |
'render' => 'cache.backend.null', | |
'discovery' => 'cache.backend.null', | |
'default' => 'cache.backend.null', | |
'dynamic_page_cache' => 'cache.backend.null', | |
], | |
], | |
] | |
])); | |
$kernel->invalidateContainer(); | |
$kernel->boot(); | |
$kernel->preHandle($request); | |
chdir(dirname(__DIR__)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parameters: | |
bootstrap: %currentWorkingDirectory%/phpstan/bootstrap.php | |
fileExtensions: | |
- php | |
- module | |
- inc | |
autoload_directories: | |
- %currentWorkingDirectory%/vendor | |
autoload_files: | |
- %currentWorkingDirectory%/phpstan/autoload-fix.php | |
ignoreErrors: | |
- '#Function [a-zA-Z0-9\\_]+ not found.#' | |
excludes_analyse: | |
- %currentWorkingDirectory%/docroot/docroot/core/tests | |
- %currentWorkingDirectory%/docroot/modules/contrib/*/tests/* | |
- %currentWorkingDirectory%/docroot/modules/contrib/*/src/Tests/* | |
- %currentWorkingDirectory%/docroot/modules/contrib/**/test/* | |
- %currentWorkingDirectory%/vendor/*/*/scenarios | |
- %currentWorkingDirectory%/vendor/*/*/examples/* | |
- %currentWorkingDirectory%/vendor/*/*/tests/* | |
- %currentWorkingDirectory%/vendor/*/*/Tests/* | |
- %currentWorkingDirectory%/vendor/squizlabs/php_codesniffer | |
- %currentWorkingDirectory%/vendor/drupal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment