-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PHP 8.4 - report deprecated implicitly nullable parameter types
- Loading branch information
1 parent
9a88a77
commit 9bd027c
Showing
8 changed files
with
237 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Node\Printer; | ||
|
||
use PhpParser\Node; | ||
use PHPStan\ShouldNotHappenException; | ||
use function array_map; | ||
use function implode; | ||
|
||
final class NodeTypePrinter | ||
{ | ||
|
||
public static function printType(Node\Name|Node\Identifier|Node\ComplexType|null $type): ?string | ||
{ | ||
if ($type === null) { | ||
return null; | ||
} | ||
|
||
if ($type instanceof Node\NullableType) { | ||
return '?' . self::printType($type->type); | ||
} | ||
|
||
if ($type instanceof Node\UnionType) { | ||
return implode('|', array_map(static function ($innerType): string { | ||
$printedType = self::printType($innerType); | ||
if ($printedType === null) { | ||
throw new ShouldNotHappenException(); | ||
} | ||
|
||
return $printedType; | ||
}, $type->types)); | ||
} | ||
|
||
if ($type instanceof Node\IntersectionType) { | ||
return implode('&', array_map(static function ($innerType): string { | ||
$printedType = self::printType($innerType); | ||
if ($printedType === null) { | ||
throw new ShouldNotHappenException(); | ||
} | ||
|
||
return $printedType; | ||
}, $type->types)); | ||
} | ||
|
||
if ($type instanceof Node\Identifier || $type instanceof Node\Name) { | ||
return $type->toString(); | ||
} | ||
|
||
throw new ShouldNotHappenException(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
tests/PHPStan/Rules/Functions/data/closure-implicitly-nullable.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php // lint >= 8.0 | ||
|
||
namespace ClosureImplicitNullable; | ||
|
||
class Foo | ||
{ | ||
|
||
public function doFoo(): void | ||
{ | ||
$c = function ( | ||
$a = null, | ||
int $b = 1, | ||
int $c = null, | ||
mixed $d = null, | ||
int|string $e = null, | ||
int|string|null $f = null, | ||
\stdClass $g = null, | ||
?\stdClass $h = null, | ||
): void { | ||
|
||
}; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
tests/PHPStan/Rules/Methods/data/method-implicitly-nullable.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace MethodImplicitNullable; | ||
|
||
use stdClass; | ||
|
||
class Foo | ||
{ | ||
|
||
public function doFoo( | ||
$a = null, | ||
int $b = 1, | ||
int $c = null, | ||
mixed $d = null, | ||
int|string $e = null, | ||
int|string|null $f = null, | ||
stdClass $g = null, | ||
?stdClass $h = null, | ||
): void | ||
{ | ||
} | ||
|
||
} |