Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions src/Command/AnalyseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$tmpFile = $input->getOption('tmp-file');
$insteadOfFile = $input->getOption('instead-of');
$errorFormat = $input->getOption('error-format');

if (
!is_array($paths)
Expand All @@ -170,6 +171,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
|| (!is_string($level) && $level !== null)
|| (!is_string($tmpFile) && $tmpFile !== null)
|| (!is_string($insteadOfFile) && $insteadOfFile !== null)
|| (!is_string($errorFormat) && $errorFormat !== null)
|| (!is_bool($allowXdebug))
) {
throw new ShouldNotHappenException();
Expand All @@ -191,6 +193,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$tmpFile,
$insteadOfFile,
true,
$errorFormat,
);
} catch (InceptionNotSuccessfulException $e) {
return 1;
Expand Down Expand Up @@ -226,21 +229,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$errorOutput = $inceptionResult->getErrorOutput();
$errorFormat = $input->getOption('error-format');

if (!is_string($errorFormat) && $errorFormat !== null) {
throw new ShouldNotHappenException();
}

if ($errorFormat === null) {
$errorFormat = $inceptionResult->getContainer()->getParameter('errorFormat');
}
$container = $inceptionResult->getContainer();

$errorFormat = $container->getParameter('errorFormat');
if ($errorFormat === null) {
$errorFormat = 'table';
}

$container = $inceptionResult->getContainer();
$errorFormatterServiceName = sprintf('errorFormatter.%s', $errorFormat);
if (!$container->hasService($errorFormatterServiceName)) {
$errorOutput->writeLineFormatted(sprintf(
Expand Down
3 changes: 2 additions & 1 deletion src/Command/CommandHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public static function begin(
?string $singleReflectionFile,
?string $singleReflectionInsteadOfFile,
bool $cleanupContainerCache,
?string $errorFormat = null,
): InceptionResult
{
$stdOutput = new SymfonyOutput($output, new SymfonyStyle(new ErrorsConsoleStyle($input, $output)));
Expand Down Expand Up @@ -386,7 +387,7 @@ public static function begin(
}

try {
$container = $containerFactory->create($tmpDir, $additionalConfigFiles, $paths, $composerAutoloaderProjectPaths, $analysedPathsFromConfig, $level ?? self::DEFAULT_LEVEL, $generateBaselineFile, $autoloadFile, $singleReflectionFile, $singleReflectionInsteadOfFile);
$container = $containerFactory->create($tmpDir, $additionalConfigFiles, $paths, $composerAutoloaderProjectPaths, $analysedPathsFromConfig, $level ?? self::DEFAULT_LEVEL, $generateBaselineFile, $autoloadFile, $singleReflectionFile, $singleReflectionInsteadOfFile, $errorFormat);
} catch (InvalidConfigurationException | AssertionException $e) {
$errorOutput->writeLineFormatted('<error>Invalid configuration:</error>');
$errorOutput->writeLineFormatted($e->getMessage());
Expand Down
9 changes: 7 additions & 2 deletions src/DependencyInjection/ContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public function create(
?string $cliAutoloadFile = null,
?string $singleReflectionFile = null,
?string $singleReflectionInsteadOfFile = null,
?string $errorFormat = null,
): Container
{
[$allConfigFiles, $projectConfig] = $this->detectDuplicateIncludedFiles(
Expand Down Expand Up @@ -146,12 +147,16 @@ public function create(
'cliAutoloadFile' => $cliAutoloadFile,
'env' => getenv(),
]);
$configurator->addDynamicParameters([
$dynamicParameters = [
'singleReflectionFile' => $singleReflectionFile,
'singleReflectionInsteadOfFile' => $singleReflectionInsteadOfFile,
'analysedPaths' => $analysedPaths,
'analysedPathsFromConfig' => $analysedPathsFromConfig,
]);
];
if ($errorFormat !== null) {
$dynamicParameters['errorFormat'] = $errorFormat;
}
$configurator->addDynamicParameters($dynamicParameters);
$configurator->addConfig($this->configDirectory . '/config.neon');
foreach ($additionalConfigFiles as $additionalConfigFile) {
$configurator->addConfig($additionalConfigFile);
Expand Down
43 changes: 43 additions & 0 deletions tests/PHPStan/Command/CommandHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@
null,
[],
$configFile,
null,

Check failure on line 307 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, ubuntu-latest)

Method PHPStan\Command\CommandHelperTest::testErrorFormatFromCli() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 307 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, ubuntu-latest)

Method PHPStan\Command\CommandHelperTest::testErrorFormatFromCli() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 307 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, ubuntu-latest)

Method PHPStan\Command\CommandHelperTest::testErrorFormatFromCli() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 307 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, windows-latest)

Method PHPStan\Command\CommandHelperTest::testErrorFormatFromCli() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 307 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, windows-latest)

Method PHPStan\Command\CommandHelperTest::testErrorFormatFromCli() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 307 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, windows-latest)

Method PHPStan\Command\CommandHelperTest::testErrorFormatFromCli() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.
'0',
false,
false,
Expand All @@ -319,4 +319,47 @@
}
}

public function testErrorFormatFromCli(): void
{
$result = CommandHelper::begin(

Check failure on line 324 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.2)

Method PHPStan\Command\CommandHelperTest::testErrorFormatFromCli() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 324 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.4)

Method PHPStan\Command\CommandHelperTest::testErrorFormatFromCli() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 324 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.5)

Method PHPStan\Command\CommandHelperTest::testErrorFormatFromCli() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 324 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.3)

Method PHPStan\Command\CommandHelperTest::testErrorFormatFromCli() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 324 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, ubuntu-latest)

Method PHPStan\Command\CommandHelperTest::testErrorFormatFromCli() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 324 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.5, ubuntu-latest)

Method PHPStan\Command\CommandHelperTest::testErrorFormatFromCli() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 324 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, ubuntu-latest)

Method PHPStan\Command\CommandHelperTest::testErrorFormatFromCli() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 324 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, ubuntu-latest)

Method PHPStan\Command\CommandHelperTest::testErrorFormatFromCli() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 324 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, windows-latest)

Method PHPStan\Command\CommandHelperTest::testErrorFormatFromCli() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 324 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, windows-latest)

Method PHPStan\Command\CommandHelperTest::testErrorFormatFromCli() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 324 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.5, windows-latest)

Method PHPStan\Command\CommandHelperTest::testErrorFormatFromCli() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 324 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, windows-latest)

Method PHPStan\Command\CommandHelperTest::testErrorFormatFromCli() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.
new StringInput(''),
new NullOutput(),
[__DIR__],
null,

Check failure on line 328 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, ubuntu-latest)

Method PHPStan\Command\CommandHelperTest::testErrorFormatDefault() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 328 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, ubuntu-latest)

Method PHPStan\Command\CommandHelperTest::testErrorFormatDefault() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 328 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, ubuntu-latest)

Method PHPStan\Command\CommandHelperTest::testErrorFormatDefault() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 328 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, windows-latest)

Method PHPStan\Command\CommandHelperTest::testErrorFormatDefault() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 328 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, windows-latest)

Method PHPStan\Command\CommandHelperTest::testErrorFormatDefault() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 328 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, windows-latest)

Method PHPStan\Command\CommandHelperTest::testErrorFormatDefault() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.
null,
[],
null,
null,
'0',
false,
false,
null,
null,
false,
'json',
);
$this->assertSame('json', $result->getContainer()->getParameter('errorFormat'));
}

public function testErrorFormatDefault(): void
{
$result = CommandHelper::begin(

Check failure on line 346 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.2)

Method PHPStan\Command\CommandHelperTest::testErrorFormatDefault() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 346 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.4)

Method PHPStan\Command\CommandHelperTest::testErrorFormatDefault() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 346 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.5)

Method PHPStan\Command\CommandHelperTest::testErrorFormatDefault() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 346 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.3)

Method PHPStan\Command\CommandHelperTest::testErrorFormatDefault() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 346 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, ubuntu-latest)

Method PHPStan\Command\CommandHelperTest::testErrorFormatDefault() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 346 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.5, ubuntu-latest)

Method PHPStan\Command\CommandHelperTest::testErrorFormatDefault() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 346 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, ubuntu-latest)

Method PHPStan\Command\CommandHelperTest::testErrorFormatDefault() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 346 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, ubuntu-latest)

Method PHPStan\Command\CommandHelperTest::testErrorFormatDefault() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 346 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, windows-latest)

Method PHPStan\Command\CommandHelperTest::testErrorFormatDefault() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 346 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, windows-latest)

Method PHPStan\Command\CommandHelperTest::testErrorFormatDefault() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 346 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.5, windows-latest)

Method PHPStan\Command\CommandHelperTest::testErrorFormatDefault() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.

Check failure on line 346 in tests/PHPStan/Command/CommandHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, windows-latest)

Method PHPStan\Command\CommandHelperTest::testErrorFormatDefault() throws checked exception PHPStan\Command\InceptionNotSuccessfulException but it's missing from the PHPDoc `@throws` tag.
new StringInput(''),
new NullOutput(),
[__DIR__],
null,
null,
[],
null,
null,
'0',
false,
false,
null,
null,
false,
);
$this->assertNull($result->getContainer()->getParameter('errorFormat'));
}

}
Loading