Skip to content

Commit

Permalink
Detect large .php baseline file in analysed paths and warn about poss…
Browse files Browse the repository at this point in the history
…ible PHPStan slowdown
  • Loading branch information
ondrejmirtes committed Mar 24, 2023
1 parent a7fe14c commit d6d9ef7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ parametersSchema:
additionalConfigFiles: arrayOf(string())
generateBaselineFile: schema(string(), nullable())
analysedPaths: listOf(string())
allConfigFiles: listOf(string())
composerAutoloaderProjectPaths: listOf(string())
analysedPathsFromConfig: listOf(string())
usedLevel: string()
Expand Down
24 changes: 24 additions & 0 deletions src/Command/AnalyseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use PHPStan\File\FileWriter;
use PHPStan\File\ParentDirectoryRelativePathHelper;
use PHPStan\File\PathNotFoundException;
use PHPStan\File\RelativePathHelper;
use PHPStan\Internal\BytesHelper;
use PHPStan\ShouldNotHappenException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -23,9 +25,11 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\StreamOutput;
use Throwable;
use function array_intersect;
use function array_map;
use function count;
use function dirname;
use function filesize;
use function fopen;
use function get_class;
use function implode;
Expand Down Expand Up @@ -225,6 +229,26 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return $inceptionResult->handleReturn(0, null);
}

$analysedConfigFiles = array_intersect($files, $container->getParameter('allConfigFiles'));
foreach ($analysedConfigFiles as $analysedConfigFile) {
$fileSize = @filesize($analysedConfigFile);
if ($fileSize === false) {
continue;
}

if ($fileSize <= 512 * 1024) {
continue;
}

/** @var RelativePathHelper $relativePathHelper */
$relativePathHelper = $container->getService('relativePathHelper');
$inceptionResult->getErrorOutput()->getStyle()->warning(sprintf(
'Configuration file %s (%s) is too big and might slow down PHPStan. Consider adding it to excludePaths.',
$relativePathHelper->getRelativePath($analysedConfigFile),
BytesHelper::bytes($fileSize),
));
}

$application = $container->getByType(AnalyseApplication::class);

$debug = $input->getOption('debug');
Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/ContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public function create(
'cliArgumentsVariablesRegistered' => ini_get('register_argc_argv') === '1',
'tmpDir' => $tempDirectory,
'additionalConfigFiles' => $additionalConfigFiles,
'allConfigFiles' => $allConfigFiles,
'composerAutoloaderProjectPaths' => $composerAutoloaderProjectPaths,
'generateBaselineFile' => $generateBaselineFile,
'usedLevel' => $usedLevel,
Expand Down

0 comments on commit d6d9ef7

Please sign in to comment.