Skip to content

Commit

Permalink
fix: constants
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Jul 22, 2024
1 parent 58a347f commit 41fa4d2
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function fromPHPStanErrors(string $file, array $phpstanErrors, arr
$filter = static fn (PHPStanError $error): bool => str_contains($error->getMessage(), 'property types')
|| str_contains($error->getMessage(), 'param types')
|| str_contains($error->getMessage(), 'return types')
|| str_contains($error->getMessage(), 'constant types');
|| (self::supportsConstantTypes() && str_contains($error->getMessage(), 'constant types'));

$phpstanErrors = array_filter($phpstanErrors, $filter);
$phpstanErrorsIgnored = array_filter($phpstanErrorsIgnored, $filter);
Expand Down Expand Up @@ -78,7 +78,7 @@ public static function fromPHPStanErrors(string $file, array $phpstanErrors, arr
$returnTypeCoverage = (int) explode(' ', explode('only ', $message)[1])[2];
}

if (self::supportsConstantTypes() && str_contains($error->getMessage(), 'constant types')) {
if (str_contains($error->getMessage(), 'constant types')) {
$constantsCoverage = (int) explode(' ', explode('only ', $message)[1])[2];
}
}
Expand All @@ -105,6 +105,7 @@ public static function supportsConstantTypes(): bool
}

$rootPath = TestSuite::getInstance()->rootPath;

$fallback = version_compare(PHP_VERSION, '8.3.0', '>=');

$composerJson = json_decode(file_get_contents($rootPath.'/composer.json'), true);
Expand All @@ -119,7 +120,7 @@ public static function supportsConstantTypes(): bool

$phpVersion = ltrim($composerJson['require']['php'], '^>=~');

$isOwnPackage = $composerJson['name'] ?? '' === 'pestphp/pest-plugin-type-coverage';
$isOwnPackage = ($composerJson['name'] ?? '') === 'pestphp/pest-plugin-type-coverage';

return version_compare($phpVersion, '8.3.0', '>=') || $isOwnPackage;
}
Expand Down

0 comments on commit 41fa4d2

Please sign in to comment.