Skip to content

Commit

Permalink
Fix PHPStan level 7 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Dec 14, 2024
1 parent 9b98888 commit 81f7b5a
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 13 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class HookedPropertyGenerator
* @param class-string $className
* @param list<HookedProperty> $properties
*
* @return non-empty-string
* @return 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()) ?: ''))) {
$notSatisfied[] = sprintf(
'PHP extension %s%s is required.',
$metadata->extension(),
Expand Down
1 change: 1 addition & 0 deletions src/Metadata/CoversClassesThatExtendClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

/**
* @param 0|1 $level
* @param class-string $className
*/
protected function __construct(int $level, string $className)
{
Expand Down
6 changes: 2 additions & 4 deletions 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 VERSION_COMPARISON = '/(?P<operator>[<>=!]{0,2})\s*(?P<version>[\d\.-]+(dev|(RC|alpha|beta)[\d\.])?)[ \t]*\r?$/m';
private const VERSION_COMPARISON = "/(?P<operator>!=|<|<=|<>|=|==|>|>=)\s*(?P<version>[\d\.-]+(dev|(RC|alpha|beta)[\d\.])?)[ \t]*\r?$/m";

/**
* @throws InvalidVersionOperatorException
Expand All @@ -41,9 +41,7 @@ public static function from(string $versionRequirement): self
if (preg_match(self::VERSION_COMPARISON, $versionRequirement, $matches)) {
return new ComparisonRequirement(
$matches['version'],
new VersionComparisonOperator(
!empty($matches['operator']) ? $matches['operator'] : '>=',
),
new VersionComparisonOperator($matches['operator']),
);
}
}
Expand Down

0 comments on commit 81f7b5a

Please sign in to comment.