mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 21:38:22 +01:00
use phpstan paths
This commit is contained in:
parent
0b6860ef16
commit
ceb946cc8b
2
.gitignore
vendored
2
.gitignore
vendored
@ -13,3 +13,5 @@ rector-symfony.yml
|
||||
|
||||
# often customized locally - example on Github is just fine
|
||||
create-rector.yml
|
||||
phpstan-dependencies.json
|
||||
phpstan-paths.txt
|
||||
|
@ -31,7 +31,7 @@ script:
|
||||
- |
|
||||
if [[ $STATIC_ANALYSIS == true ]]; then
|
||||
composer check-cs
|
||||
composer phpstan
|
||||
composer phpstan-ci
|
||||
fi
|
||||
|
||||
# Rector demo run
|
||||
|
@ -100,7 +100,11 @@
|
||||
"vendor/bin/ecs check bin packages src tests --fix",
|
||||
"bin/clean_trailing_spaces.sh"
|
||||
],
|
||||
"phpstan": "vendor/bin/phpstan analyse packages src tests",
|
||||
"phpstan-ci": "vendor/bin/phpstan analyse packages src tests",
|
||||
"phpstan": [
|
||||
"php utils/phpstan/generate-paths.php",
|
||||
"vendor/bin/phpstan analyse --paths-file phpstan-paths.txt"
|
||||
],
|
||||
"docs": "bin/rector generate-docs > docs/AllRectorsOverview.md"
|
||||
},
|
||||
"scripts-descriptions": {
|
||||
|
@ -9,6 +9,7 @@ parameters:
|
||||
level: 7
|
||||
|
||||
excludes_analyse:
|
||||
- "utils/phpstan/generate-paths.php"
|
||||
# test files
|
||||
- '*packages/NodeTypeResolver/tests/Source/AnotherClass.php'
|
||||
- '*tests/Rector/MethodCall/MethodNameReplacerRector/**/SomeClass.php'
|
||||
|
79
utils/phpstan/generate-paths.php
Executable file
79
utils/phpstan/generate-paths.php
Executable file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
// experimental, phpstan 0.10.7
|
||||
// @todo refactor to classes later, if proven working
|
||||
|
||||
use Nette\Utils\FileSystem;
|
||||
use Nette\Utils\Json;
|
||||
use Nette\Utils\Strings;
|
||||
use Symfony\Component\Process\Process;
|
||||
use Symplify\PackageBuilder\Console\Style\SymfonyStyleFactory;
|
||||
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
$phpstanDependencies = __DIR__ . '/../../phpstan-dependencies.json';
|
||||
$symfonyStyle = (new SymfonyStyleFactory())->create();
|
||||
|
||||
// prepare dependencies.json
|
||||
if (! file_exists($phpstanDependencies)) {
|
||||
$process = Process::fromShellCommandline('vendor/bin/phpstan dump-deps src packages > phpstan-dependencies.json');
|
||||
$symfonyStyle->note('Dumping dependencies (will take ~10 s)');
|
||||
$process->run();
|
||||
}
|
||||
|
||||
$fileDependenciesJson = Json::decode(FileSystem::read($phpstanDependencies), Json::FORCE_ARRAY);
|
||||
|
||||
$changedFiles = resolveChangedFiles();
|
||||
|
||||
$filesToCheck = [];
|
||||
foreach ($changedFiles as $changedFile) {
|
||||
$changedFile = getcwd() . '/' . $changedFile;
|
||||
if (isset($fileDependenciesJson[$changedFile])) {
|
||||
$filesToCheck = array_merge($filesToCheck, $fileDependenciesJson[$changedFile], [$changedFile]);
|
||||
}
|
||||
}
|
||||
|
||||
$newFiles = resolveNewFiles();
|
||||
|
||||
$filesToCheck = array_merge($filesToCheck, $newFiles);
|
||||
$filesToCheckString = implode(PHP_EOL, $filesToCheck);
|
||||
|
||||
FileSystem::write('phpstan-paths.txt', $filesToCheckString);
|
||||
|
||||
$symfonyStyle->success(sprintf('%d paths generated to "phpstan-paths.txt"', count($filesToCheck)));
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
function resolveChangedFiles(): array
|
||||
{
|
||||
$process = Process::fromShellCommandline('git status -s');
|
||||
$process->run();
|
||||
|
||||
$gitStatusOutput = $process->getOutput();
|
||||
|
||||
$files = [];
|
||||
foreach (Strings::matchAll($gitStatusOutput, '# ([\w\/]+\.php)#m') as $match) {
|
||||
$files[] = $match[1];
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
function resolveNewFiles(): array
|
||||
{
|
||||
$process = Process::fromShellCommandline('git status -s');
|
||||
$process->run();
|
||||
|
||||
$gitStatusOutput = $process->getOutput();
|
||||
|
||||
$files = [];
|
||||
foreach (Strings::matchAll($gitStatusOutput, '#\?\? ([\w\/]+)#m') as $match) {
|
||||
$files[] = getcwd() . '/' . $match[1];
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user