Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PHPStan level 7 errors #6084

Merged
merged 6 commits into from
Dec 24, 2024
Merged
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
3 changes: 0 additions & 3 deletions src/Event/Emitter/Emitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,6 @@ public function testConsideredRisky(Code\Test $test, string $message): void;

public function testMarkedAsIncomplete(Code\Test $test, Throwable $throwable): void;

/**
* @param non-empty-string $message
*/
public function testSkipped(Code\Test $test, string $message): void;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Framework/MockObject/Generator/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ final class Generator
*
* @param class-string $type
* @param ?list<non-empty-string> $methods
* @param list<mixed> $arguments
* @param array<mixed> $arguments
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Named args cannot be a list

*
* @throws ClassIsEnumerationException
* @throws ClassIsFinalException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ final class HookedPropertyGenerator
/**
* @param class-string $className
* @param list<HookedProperty> $properties
*
* @return non-empty-string
*/
public function generate(string $className, array $properties): string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Framework/TestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function build(ReflectionClass $theClass, string $methodName, array $grou
/**
* @param non-empty-string $methodName
* @param class-string<TestCase> $className
* @param array<list<mixed>> $data
* @param array<array<mixed>> $data
* @param array{backupGlobals: ?bool, backupGlobalsExcludeList: list<string>, backupStaticProperties: ?bool, backupStaticPropertiesExcludeList: array<string,list<string>>} $backupSettings
* @param list<non-empty-string> $groups
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ final public function size(): TestSize

/**
* @internal This method is not covered by the backward compatibility promise for PHPUnit
*
* @phpstan-assert-if-true non-empty-string $this->output()
*/
final public function hasUnexpectedOutput(): bool
{
Expand Down
2 changes: 1 addition & 1 deletion src/Logging/EventLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function trace(Event $event): void
{
$telemetryInfo = $this->telemetryInfo($event);
$indentation = PHP_EOL . str_repeat(' ', strlen($telemetryInfo));
$lines = preg_split('/\r\n|\r|\n/', $event->asString());
$lines = preg_split('/\r\n|\r|\n/', $event->asString()) ?: [];

$flags = FILE_APPEND;

Expand Down
4 changes: 2 additions & 2 deletions src/Logging/JUnit/JunitXmlLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function __construct(Printer $printer, Facade $facade)

public function flush(): void
{
$this->printer->print($this->document->saveXML());
$this->printer->print($this->document->saveXML() ?: '');

$this->printer->flush();
}
Expand Down Expand Up @@ -269,7 +269,7 @@ private function handleFinish(Info $telemetryInfo, int $numberOfAssertionsPerfor
);

$this->testSuiteTests[$this->testSuiteLevel]++;
$this->testSuiteTimes[$this->testSuiteLevel] += $time;
$this->testSuiteTimes[$this->testSuiteLevel] += (int) $time;

$this->currentTestCase = null;
$this->time = null;
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/Api/Requirements.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function requirementsNotSatisfiedFor(string $className, string $methodNam

if (!extension_loaded($metadata->extension()) ||
($metadata->hasVersionRequirement() &&
!$metadata->versionRequirement()->isSatisfiedBy(phpversion($metadata->extension())))) {
!$metadata->versionRequirement()->isSatisfiedBy(phpversion($metadata->extension()) ?: ''))) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extensions might not provide version info and this line can return false

$notSatisfied[] = sprintf(
'PHP extension %s%s is required.',
$metadata->extension(),
Expand Down
3 changes: 2 additions & 1 deletion src/Metadata/CoversClassesThatExtendClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
private string $className;

/**
* @param int<0, 1> $level
* @param int<0, 1> $level
* @param class-string $className
*/
protected function __construct(int $level, string $className)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/Version/Requirement.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
abstract readonly class Requirement
{
private const string VERSION_COMPARISON = '/(?P<operator>[<>=!]{0,2})\s*(?P<version>[\d\.-]+(dev|(RC|alpha|beta)[\d\.])?)[ \t]*\r?$/m';
private const string VERSION_COMPARISON = "/(?P<operator>!=|<|<=|<>|=|==|>|>=)?\s*(?P<version>[\d\.-]+(dev|(RC|alpha|beta)[\d\.])?)[ \t]*\r?$/m";

/**
* @throws InvalidVersionOperatorException
Expand Down
4 changes: 2 additions & 2 deletions src/Runner/TestSuiteSorter.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,9 @@ private function cmpSize(Test $a, Test $b): int
* 3. If the test has dependencies but none left to do: mark done, start again from the top
* 4. When we reach the end add any leftover tests to the end. These will be marked 'skipped' during execution.
*
* @param array<DataProviderTestSuite|TestCase> $tests
* @param array<TestCase> $tests
*
* @return array<DataProviderTestSuite|TestCase>
* @return array<TestCase>
*/
private function resolveDependencies(array $tests): array
{
Expand Down
9 changes: 8 additions & 1 deletion src/TextUI/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@
private Php $php;
private bool $controlGarbageCollector;
private int $numberOfTestsBeforeGarbageCollection;

/**
* @var null|non-empty-string
*/
private ?string $generateBaseline;
private bool $debug;

Expand All @@ -179,9 +183,10 @@
* @param list<non-empty-string> $groups
* @param list<non-empty-string> $excludeGroups
* @param non-empty-list<non-empty-string> $testSuffixes
* @param null|non-empty-string $generateBaseline
* @param non-negative-int $shortenArraysForExportThreshold
*/
public function __construct(array $cliArguments, ?string $configurationFile, ?string $bootstrap, bool $cacheResult, ?string $cacheDirectory, ?string $coverageCacheDirectory, Source $source, string $testResultCacheFile, ?string $coverageClover, ?string $coverageCobertura, ?string $coverageCrap4j, int $coverageCrap4jThreshold, ?string $coverageHtml, int $coverageHtmlLowUpperBound, int $coverageHtmlHighLowerBound, string $coverageHtmlColorSuccessLow, string $coverageHtmlColorSuccessMedium, string $coverageHtmlColorSuccessHigh, string $coverageHtmlColorWarning, string $coverageHtmlColorDanger, ?string $coverageHtmlCustomCssFile, ?string $coveragePhp, ?string $coverageText, bool $coverageTextShowUncoveredFiles, bool $coverageTextShowOnlySummary, ?string $coverageXml, bool $pathCoverage, bool $ignoreDeprecatedCodeUnitsFromCodeCoverage, bool $disableCodeCoverageIgnore, bool $failOnDeprecation, bool $failOnPhpunitDeprecation, bool $failOnEmptyTestSuite, bool $failOnIncomplete, bool $failOnNotice, bool $failOnRisky, bool $failOnSkipped, bool $failOnWarning, bool $stopOnDefect, bool $stopOnDeprecation, ?string $specificDeprecationToStopOn, bool $stopOnError, bool $stopOnFailure, bool $stopOnIncomplete, bool $stopOnNotice, bool $stopOnRisky, bool $stopOnSkipped, bool $stopOnWarning, bool $outputToStandardErrorStream, int|string $columns, bool $noExtensions, ?string $pharExtensionDirectory, array $extensionBootstrappers, bool $backupGlobals, bool $backupStaticProperties, bool $beStrictAboutChangesToGlobalState, bool $colors, bool $processIsolation, bool $enforceTimeLimit, int $defaultTimeLimit, int $timeoutForSmallTests, int $timeoutForMediumTests, int $timeoutForLargeTests, bool $reportUselessTests, bool $strictCoverage, bool $disallowTestOutput, bool $displayDetailsOnIncompleteTests, bool $displayDetailsOnSkippedTests, bool $displayDetailsOnTestsThatTriggerDeprecations, bool $displayDetailsOnPhpunitDeprecations, bool $displayDetailsOnTestsThatTriggerErrors, bool $displayDetailsOnTestsThatTriggerNotices, bool $displayDetailsOnTestsThatTriggerWarnings, bool $reverseDefectList, bool $requireCoverageMetadata, bool $noProgress, bool $noResults, bool $noOutput, int $executionOrder, int $executionOrderDefects, bool $resolveDependencies, ?string $logfileTeamcity, ?string $logfileJunit, ?string $logfileTestdoxHtml, ?string $logfileTestdoxText, ?string $logEventsText, ?string $logEventsVerboseText, bool $teamCityOutput, bool $testDoxOutput, bool $testDoxOutputSummary, ?array $testsCovering, ?array $testsUsing, ?array $testsRequiringPhpExtension, ?string $filter, ?string $excludeFilter, array $groups, array $excludeGroups, int $randomOrderSeed, TestSuiteCollection $testSuite, string $includeTestSuite, string $excludeTestSuite, ?string $defaultTestSuite, array $testSuffixes, Php $php, bool $controlGarbageCollector, int $numberOfTestsBeforeGarbageCollection, ?string $generateBaseline, bool $debug, int $shortenArraysForExportThreshold)
public function __construct(array $cliArguments, ?string $configurationFile, ?string $bootstrap, bool $cacheResult, ?string $cacheDirectory, ?string $coverageCacheDirectory, Source $source, string $testResultCacheFile, ?string $coverageClover, ?string $coverageCobertura, ?string $coverageCrap4j, int $coverageCrap4jThreshold, ?string $coverageHtml, int $coverageHtmlLowUpperBound, int $coverageHtmlHighLowerBound, string $coverageHtmlColorSuccessLow, string $coverageHtmlColorSuccessMedium, string $coverageHtmlColorSuccessHigh, string $coverageHtmlColorWarning, string $coverageHtmlColorDanger, ?string $coverageHtmlCustomCssFile, ?string $coveragePhp, ?string $coverageText, bool $coverageTextShowUncoveredFiles, bool $coverageTextShowOnlySummary, ?string $coverageXml, bool $pathCoverage, bool $ignoreDeprecatedCodeUnitsFromCodeCoverage, bool $disableCodeCoverageIgnore, bool $failOnDeprecation, bool $failOnPhpunitDeprecation, bool $failOnEmptyTestSuite, bool $failOnIncomplete, bool $failOnNotice, bool $failOnRisky, bool $failOnSkipped, bool $failOnWarning, bool $stopOnDefect, bool $stopOnDeprecation, ?string $specificDeprecationToStopOn, bool $stopOnError, bool $stopOnFailure, bool $stopOnIncomplete, bool $stopOnNotice, bool $stopOnRisky, bool $stopOnSkipped, bool $stopOnWarning, bool $outputToStandardErrorStream, int $columns, bool $noExtensions, ?string $pharExtensionDirectory, array $extensionBootstrappers, bool $backupGlobals, bool $backupStaticProperties, bool $beStrictAboutChangesToGlobalState, bool $colors, bool $processIsolation, bool $enforceTimeLimit, int $defaultTimeLimit, int $timeoutForSmallTests, int $timeoutForMediumTests, int $timeoutForLargeTests, bool $reportUselessTests, bool $strictCoverage, bool $disallowTestOutput, bool $displayDetailsOnIncompleteTests, bool $displayDetailsOnSkippedTests, bool $displayDetailsOnTestsThatTriggerDeprecations, bool $displayDetailsOnPhpunitDeprecations, bool $displayDetailsOnTestsThatTriggerErrors, bool $displayDetailsOnTestsThatTriggerNotices, bool $displayDetailsOnTestsThatTriggerWarnings, bool $reverseDefectList, bool $requireCoverageMetadata, bool $noProgress, bool $noResults, bool $noOutput, int $executionOrder, int $executionOrderDefects, bool $resolveDependencies, ?string $logfileTeamcity, ?string $logfileJunit, ?string $logfileTestdoxHtml, ?string $logfileTestdoxText, ?string $logEventsText, ?string $logEventsVerboseText, bool $teamCityOutput, bool $testDoxOutput, bool $testDoxOutputSummary, ?array $testsCovering, ?array $testsUsing, ?array $testsRequiringPhpExtension, ?string $filter, ?string $excludeFilter, array $groups, array $excludeGroups, int $randomOrderSeed, TestSuiteCollection $testSuite, string $includeTestSuite, string $excludeTestSuite, ?string $defaultTestSuite, array $testSuffixes, Php $php, bool $controlGarbageCollector, int $numberOfTestsBeforeGarbageCollection, ?string $generateBaseline, bool $debug, int $shortenArraysForExportThreshold)
{
$this->cliArguments = $cliArguments;
$this->configurationFile = $configurationFile;
Expand Down Expand Up @@ -1288,6 +1293,8 @@ public function hasGenerateBaseline(): bool

/**
* @throws NoBaselineException
*
* @return non-empty-string
*/
public function generateBaseline(): string
{
Expand Down
2 changes: 1 addition & 1 deletion src/TextUI/Output/TestDox/ResultPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private function prefixLines(string $prefix, string $message): string
PHP_EOL,
array_map(
static fn (string $line) => ' ' . $prefix . ($line ? ' ' . $line : ''),
preg_split('/\r\n|\r|\n/', $message),
preg_split('/\r\n|\r|\n/', $message) ?: [],
),
);
}
Expand Down
Loading