Skip to content

Commit 6f9f9aa

Browse files
committed
CommandHelper - executing bootstrap file extracted into a private method
1 parent bf94fac commit 6f9f9aa

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

src/Command/CommandHelper.php

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Nette\Utils\Validators;
1212
use PHPStan\Command\Symfony\SymfonyOutput;
1313
use PHPStan\Command\Symfony\SymfonyStyle;
14+
use PHPStan\DependencyInjection\Container;
1415
use PHPStan\DependencyInjection\ContainerFactory;
1516
use PHPStan\DependencyInjection\LoaderFactory;
1617
use PHPStan\DependencyInjection\NeonAdapter;
@@ -309,23 +310,7 @@ public static function begin(
309310

310311
$bootstrapFile = $container->getParameter('bootstrap');
311312
if ($bootstrapFile !== null) {
312-
if (!is_file($bootstrapFile)) {
313-
$errorOutput->writeLineFormatted(sprintf('Bootstrap file %s does not exist.', $bootstrapFile));
314-
throw new \PHPStan\Command\InceptionNotSuccessfulException();
315-
}
316-
try {
317-
(static function (string $file) use ($container): void {
318-
require_once $file;
319-
})($bootstrapFile);
320-
} catch (\Throwable $e) {
321-
$errorOutput->writeLineFormatted(sprintf('%s thrown in %s on line %d while loading bootstrap file %s: %s', get_class($e), $e->getFile(), $e->getLine(), $bootstrapFile, $e->getMessage()));
322-
323-
if ($debugEnabled) {
324-
$errorOutput->writeLineFormatted($e->getTraceAsString());
325-
}
326-
327-
throw new \PHPStan\Command\InceptionNotSuccessfulException();
328-
}
313+
self::executeBootstrapFile($bootstrapFile, $container, $errorOutput, $debugEnabled);
329314
}
330315

331316
/** @var FileFinder $fileFinder */
@@ -351,6 +336,32 @@ public static function begin(
351336
);
352337
}
353338

339+
private static function executeBootstrapFile(
340+
string $file,
341+
Container $container,
342+
Output $errorOutput,
343+
bool $debugEnabled
344+
): void
345+
{
346+
if (!is_file($file)) {
347+
$errorOutput->writeLineFormatted(sprintf('Bootstrap file %s does not exist.', $file));
348+
throw new \PHPStan\Command\InceptionNotSuccessfulException();
349+
}
350+
try {
351+
(static function (string $file) use ($container): void {
352+
require_once $file;
353+
})($file);
354+
} catch (\Throwable $e) {
355+
$errorOutput->writeLineFormatted(sprintf('%s thrown in %s on line %d while loading bootstrap file %s: %s', get_class($e), $e->getFile(), $e->getLine(), $file, $e->getMessage()));
356+
357+
if ($debugEnabled) {
358+
$errorOutput->writeLineFormatted($e->getTraceAsString());
359+
}
360+
361+
throw new \PHPStan\Command\InceptionNotSuccessfulException();
362+
}
363+
}
364+
354365
private static function setUpSignalHandler(Output $output, ?string $memoryLimitFile): void
355366
{
356367
if (!function_exists('pcntl_signal')) {

0 commit comments

Comments
 (0)