Skip to content

Commit e48f3f1

Browse files
veeweeondrejmirtes
authored andcommitted
Use NullishType::class and fix CS violations
- Restore NullishType::class instead of string literal - Add baseline ignores for older PSL versions without NullishType - Fix CS: add use statements for NullishType and class_exists in test
1 parent 5e8a5a9 commit e48f3f1

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

phpstan-baseline-psl-1.neon

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,15 @@ parameters:
1111
identifier: argument.type
1212
count: 1
1313
path: src/Option/OptionFilterReturnTypeExtension.php
14+
15+
-
16+
message: '#^Class Psl\\Type\\Internal\\NullishType not found\.$#'
17+
identifier: class.notFound
18+
count: 1
19+
path: src/Type/TypeShapeReturnTypeExtension.php
20+
21+
-
22+
message: '#^Parameter \#1 \$ancestorClassName of method PHPStan\\Type\\Type\:\:getTemplateType\(\) expects class\-string, string given\.$#'
23+
identifier: argument.type
24+
count: 1
25+
path: src/Type/TypeShapeReturnTypeExtension.php

src/Type/TypeShapeReturnTypeExtension.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PHPStan\Type\Generic\GenericObjectType;
1313
use PHPStan\Type\Type;
1414
use PHPStan\Type\TypeCombinator;
15+
use Psl\Type\Internal\NullishType;
1516
use Psl\Type\Internal\OptionalType;
1617
use Psl\Type\TypeInterface;
1718
use function count;
@@ -70,7 +71,7 @@ private function createResult(ConstantArrayType $arrayType): Type
7071
*/
7172
private function extractNullish(Type $type): array
7273
{
73-
$nullishType = $type->getTemplateType('Psl\Type\Internal\NullishType', 'T');
74+
$nullishType = $type->getTemplateType(NullishType::class, 'T');
7475
if ($nullishType instanceof ErrorType) {
7576
return [$type, false];
7677
}

tests/Type/PslTypeSpecifyingExtensionTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use Composer\InstalledVersions;
66
use Composer\Semver\VersionParser;
77
use PHPStan\Testing\TypeInferenceTestCase;
8+
use Psl\Type\Internal\NullishType;
9+
use function class_exists;
810

911
class PslTypeSpecifyingExtensionTest extends TypeInferenceTestCase
1012
{
@@ -17,7 +19,7 @@ public function dataFileAsserts(): iterable
1719
yield from $this->gatherAssertTypes(__DIR__ . '/data/coerce.php');
1820
yield from $this->gatherAssertTypes(__DIR__ . '/data/assert.php');
1921
yield from $this->gatherAssertTypes(__DIR__ . '/data/matches.php');
20-
if (class_exists(\Psl\Type\Internal\NullishType::class)) {
22+
if (class_exists(NullishType::class)) {
2123
yield from $this->gatherAssertTypes(__DIR__ . '/data/nullishCoerce.php');
2224
yield from $this->gatherAssertTypes(__DIR__ . '/data/nullishAssert.php');
2325
yield from $this->gatherAssertTypes(__DIR__ . '/data/nullishMatches.php');

0 commit comments

Comments
 (0)