From ece4547a94540dd96d76f61c630f46d25332da00 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 10 Sep 2022 09:03:49 +0200 Subject: [PATCH 1/7] PHP 8.2 | Tokenizer/PHP: allow for true in union types Previously, `false` and `null` were already allowed in union types. As of PHP 8.2, `true` has been added to the supported types in PHP and can also be used in union types. Also see: https://3v4l.org/ZpfID This commit adjusts the Tokenizer to correctly retokenize the `T_BITWISE_OR` character to `T_UNION_TYPE` when `true` is included in a union type. Includes unit tests. Refs: * https://wiki.php.net/rfc/true-type --- src/Tokenizers/PHP.php | 1 + tests/Core/Tokenizer/BitwiseOrTest.inc | 9 +++++++++ tests/Core/Tokenizer/BitwiseOrTest.php | 3 +++ 3 files changed, 13 insertions(+) diff --git a/src/Tokenizers/PHP.php b/src/Tokenizers/PHP.php index badc9d972b..7321e8be42 100644 --- a/src/Tokenizers/PHP.php +++ b/src/Tokenizers/PHP.php @@ -2938,6 +2938,7 @@ protected function processAdditional() T_PARENT => T_PARENT, T_STATIC => T_STATIC, T_FALSE => T_FALSE, + T_TRUE => T_TRUE, T_NULL => T_NULL, T_NAMESPACE => T_NAMESPACE, T_NS_SEPARATOR => T_NS_SEPARATOR, diff --git a/tests/Core/Tokenizer/BitwiseOrTest.inc b/tests/Core/Tokenizer/BitwiseOrTest.inc index bfdbdc18c1..843f6c57d7 100644 --- a/tests/Core/Tokenizer/BitwiseOrTest.inc +++ b/tests/Core/Tokenizer/BitwiseOrTest.inc @@ -129,6 +129,15 @@ $obj->fn($something | $else); /* testTypeUnionNonArrowFunctionDeclaration */ function &fn(int|false $something) {} +/* testTypeUnionPHP82TrueFirst */ +function trueTypeParam(true|null $param) {} + +/* testTypeUnionPHP82TrueMiddle */ +function trueTypeReturn($param): array|true|null {} + +/* testTypeUnionPHP82TrueLast */ +$closure = function ($param): array|true {} + /* testLiveCoding */ // Intentional parse error. This has to be the last test in the file. return function( type| diff --git a/tests/Core/Tokenizer/BitwiseOrTest.php b/tests/Core/Tokenizer/BitwiseOrTest.php index e96b7840ad..aad4474049 100644 --- a/tests/Core/Tokenizer/BitwiseOrTest.php +++ b/tests/Core/Tokenizer/BitwiseOrTest.php @@ -130,6 +130,9 @@ public function dataTypeUnion() ['/* testTypeUnionArrowParam */'], ['/* testTypeUnionArrowReturnType */'], ['/* testTypeUnionNonArrowFunctionDeclaration */'], + ['/* testTypeUnionPHP82TrueFirst */'], + ['/* testTypeUnionPHP82TrueMiddle */'], + ['/* testTypeUnionPHP82TrueLast */'], ]; }//end dataTypeUnion() From c709801b86d1529bf3733f4a0876730c648de5ed Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 10 Sep 2022 09:07:29 +0200 Subject: [PATCH 2/7] PHP 8.2 | File::getMethodProperties(): allow for true in types As of PHP 8.2, `true`, `false` and `null` will be allowed as stand-alone types. `true` can now also be used in union types (was already allowed for `false` and `null`). The `true` and the `false` types are allowed to be nullable, the `null` type is not (but that's not the concern of this method). Also see: https://3v4l.org/ZpfID This commit adjusts the `File::getMethodProperties()` method to take `true` into account. `false` and `null` were already handled due to these previously already being allowed in union types. Includes unit tests. Refs: * https://wiki.php.net/rfc/null-false-standalone-types * https://wiki.php.net/rfc/true-type --- src/Files/File.php | 1 + tests/Core/File/GetMethodPropertiesTest.inc | 11 ++++- tests/Core/File/GetMethodPropertiesTest.php | 46 +++++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/Files/File.php b/src/Files/File.php index 0945b7c3d2..477d36a7df 100644 --- a/src/Files/File.php +++ b/src/Files/File.php @@ -1705,6 +1705,7 @@ public function getMethodProperties($stackPtr) T_PARENT => T_PARENT, T_STATIC => T_STATIC, T_FALSE => T_FALSE, + T_TRUE => T_TRUE, T_NULL => T_NULL, T_NAMESPACE => T_NAMESPACE, T_NS_SEPARATOR => T_NS_SEPARATOR, diff --git a/tests/Core/File/GetMethodPropertiesTest.inc b/tests/Core/File/GetMethodPropertiesTest.inc index 0c592369a5..5ebee67947 100644 --- a/tests/Core/File/GetMethodPropertiesTest.inc +++ b/tests/Core/File/GetMethodPropertiesTest.inc @@ -102,11 +102,11 @@ function unionTypesAllPseudoTypes($var) : false|MIXED|self|parent|static|iterabl $closure = function () use($a) :?int|float {}; /* testPHP8PseudoTypeNull */ -// Intentional fatal error - null pseudotype is only allowed in union types, but that's not the concern of the method. +// PHP 8.0 - 8.1: Intentional fatal error - null pseudotype is only allowed in union types, but that's not the concern of the method. function pseudoTypeNull(): null {} /* testPHP8PseudoTypeFalse */ -// Intentional fatal error - false pseudotype is only allowed in union types, but that's not the concern of the method. +// PHP 8.0 - 8.1: Intentional fatal error - false pseudotype is only allowed in union types, but that's not the concern of the method. function pseudoTypeFalse(): false {} /* testPHP8PseudoTypeFalseAndBool */ @@ -150,3 +150,10 @@ $closure = function (): string&int {}; /* testPHP81NullableIntersectionTypes */ // Intentional fatal error - nullability is not allowed with intersection types, but that's not the concern of the method. $closure = function (): ?Foo&Bar {}; + +/* testPHP82PseudoTypeTrue */ +function pseudoTypeTrue(): ?true {} + +/* testPHP82PseudoTypeFalseAndTrue */ +// Intentional fatal error - Type contains both true and false, bool should be used instead, but that's not the concern of the method. +function pseudoTypeFalseAndTrue(): true|false {} diff --git a/tests/Core/File/GetMethodPropertiesTest.php b/tests/Core/File/GetMethodPropertiesTest.php index ef881965e5..ab8fe66f78 100644 --- a/tests/Core/File/GetMethodPropertiesTest.php +++ b/tests/Core/File/GetMethodPropertiesTest.php @@ -889,6 +889,52 @@ public function testPHP81NullableIntersectionTypes() }//end testPHP81NullableIntersectionTypes() + /** + * Verify recognition of PHP 8.2 stand-alone `true` type. + * + * @return void + */ + public function testPHP82PseudoTypeTrue() + { + $expected = [ + 'scope' => 'public', + 'scope_specified' => false, + 'return_type' => '?true', + 'nullable_return_type' => true, + 'is_abstract' => false, + 'is_final' => false, + 'is_static' => false, + 'has_body' => true, + ]; + + $this->getMethodPropertiesTestHelper('/* '.__FUNCTION__.' */', $expected); + + }//end testPHP82PseudoTypeTrue() + + + /** + * Verify recognition of PHP 8.2 type declaration with (illegal) type false combined with type true. + * + * @return void + */ + public function testPHP82PseudoTypeFalseAndTrue() + { + $expected = [ + 'scope' => 'public', + 'scope_specified' => false, + 'return_type' => 'true|false', + 'nullable_return_type' => false, + 'is_abstract' => false, + 'is_final' => false, + 'is_static' => false, + 'has_body' => true, + ]; + + $this->getMethodPropertiesTestHelper('/* '.__FUNCTION__.' */', $expected); + + }//end testPHP82PseudoTypeFalseAndTrue() + + /** * Test helper. * From 3aa8682a00fe398d0c346afdb8eea67b3dda85c2 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 10 Sep 2022 09:08:41 +0200 Subject: [PATCH 3/7] PHP 8.2 | File::getMethodParameters(): allow for true in types As of PHP 8.2, `true`, `false` and `null` will be allowed as stand-alone types. `true` can now also be used in union types (was already allowed for `false` and `null`). The `true` and the `false` types are allowed to be nullable, the `null` type is not (but that's not the concern of this method). Also see: https://3v4l.org/ZpfID This commit adjusts the `File::getMethodParameters()` method to take `true` into account. `false` and `null` were already handled due to these previously already being allowed in union types. Includes unit tests. Refs: * https://wiki.php.net/rfc/null-false-standalone-types * https://wiki.php.net/rfc/true-type --- src/Files/File.php | 1 + tests/Core/File/GetMethodParametersTest.inc | 11 ++++- tests/Core/File/GetMethodParametersTest.php | 48 +++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/Files/File.php b/src/Files/File.php index 477d36a7df..842617ef81 100644 --- a/src/Files/File.php +++ b/src/Files/File.php @@ -1479,6 +1479,7 @@ public function getMethodParameters($stackPtr) case T_TYPE_UNION: case T_TYPE_INTERSECTION: case T_FALSE: + case T_TRUE: case T_NULL: // Part of a type hint or default value. if ($defaultStart === null) { diff --git a/tests/Core/File/GetMethodParametersTest.inc b/tests/Core/File/GetMethodParametersTest.inc index c0ef6e0621..2635e092c0 100644 --- a/tests/Core/File/GetMethodParametersTest.inc +++ b/tests/Core/File/GetMethodParametersTest.inc @@ -66,11 +66,11 @@ function unionTypesAllPseudoTypes(false|mixed|self|parent|iterable|Resource $var $closure = function (?int|float $number) {}; /* testPHP8PseudoTypeNull */ -// Intentional fatal error - null pseudotype is only allowed in union types, but that's not the concern of the method. +// PHP 8.0 - 8.1: Intentional fatal error - null pseudotype is only allowed in union types, but that's not the concern of the method. function pseudoTypeNull(null $var = null) {} /* testPHP8PseudoTypeFalse */ -// Intentional fatal error - false pseudotype is only allowed in union types, but that's not the concern of the method. +// PHP 8.0 - 8.1: Intentional fatal error - false pseudotype is only allowed in union types, but that's not the concern of the method. function pseudoTypeFalse(false $var = false) {} /* testPHP8PseudoTypeFalseAndBool */ @@ -167,3 +167,10 @@ $closure = function (string&int $numeric_string) {}; /* testPHP81NullableIntersectionTypes */ // Intentional fatal error - nullability is not allowed with intersection types, but that's not the concern of the method. $closure = function (?Foo&Bar $object) {}; + +/* testPHP82PseudoTypeTrue */ +function pseudoTypeTrue(?true $var = true) {} + +/* testPHP82PseudoTypeFalseAndTrue */ +// Intentional fatal error - Type contains both true and false, bool should be used instead, but that's not the concern of the method. +function pseudoTypeFalseAndTrue(true|false $var = true) {} diff --git a/tests/Core/File/GetMethodParametersTest.php b/tests/Core/File/GetMethodParametersTest.php index fe52dbdaaa..fd4742aea7 100644 --- a/tests/Core/File/GetMethodParametersTest.php +++ b/tests/Core/File/GetMethodParametersTest.php @@ -1166,6 +1166,54 @@ public function testPHP81NullableIntersectionTypes() }//end testPHP81NullableIntersectionTypes() + /** + * Verify recognition of PHP 8.2 stand-alone `true` type. + * + * @return void + */ + public function testPHP82PseudoTypeTrue() + { + $expected = []; + $expected[0] = [ + 'name' => '$var', + 'content' => '?true $var = true', + 'default' => 'true', + 'has_attributes' => false, + 'pass_by_reference' => false, + 'variable_length' => false, + 'type_hint' => '?true', + 'nullable_type' => true, + ]; + + $this->getMethodParametersTestHelper('/* '.__FUNCTION__.' */', $expected); + + }//end testPHP82PseudoTypeTrue() + + + /** + * Verify recognition of PHP 8.2 type declaration with (illegal) type false combined with type true. + * + * @return void + */ + public function testPHP82PseudoTypeFalseAndTrue() + { + $expected = []; + $expected[0] = [ + 'name' => '$var', + 'content' => 'true|false $var = true', + 'default' => 'true', + 'has_attributes' => false, + 'pass_by_reference' => false, + 'variable_length' => false, + 'type_hint' => 'true|false', + 'nullable_type' => false, + ]; + + $this->getMethodParametersTestHelper('/* '.__FUNCTION__.' */', $expected); + + }//end testPHP82PseudoTypeFalseAndTrue() + + /** * Test helper. * From 6e307f58500dd20c7fbfac4599aa50ea8d97712f Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 10 Sep 2022 09:09:56 +0200 Subject: [PATCH 4/7] PHP 8.2 | File::getMemberProperties(): allow for true in types As of PHP 8.2, `true`, `false` and `null` will be allowed as stand-alone types. `true` can now also be used in union types (was already allowed for `false` and `null`). The `true` and the `false` types are allowed to be nullable, the `null` type is not (but that's not the concern of this method). Also see: https://3v4l.org/ZpfID This commit adjusts the `File::getMemberProperties()` method to take `true` into account. `false` and `null` were already handled due to these previously already being allowed in union types. Includes unit tests. Includes minor touch up of some pre-existing tests. Refs: * https://wiki.php.net/rfc/null-false-standalone-types * https://wiki.php.net/rfc/true-type --- src/Files/File.php | 1 + tests/Core/File/GetMemberPropertiesTest.inc | 21 +++++++-- tests/Core/File/GetMemberPropertiesTest.php | 47 ++++++++++++++++++++- 3 files changed, 65 insertions(+), 4 deletions(-) diff --git a/src/Files/File.php b/src/Files/File.php index 842617ef81..42e204a534 100644 --- a/src/Files/File.php +++ b/src/Files/File.php @@ -1908,6 +1908,7 @@ public function getMemberProperties($stackPtr) T_SELF => T_SELF, T_PARENT => T_PARENT, T_FALSE => T_FALSE, + T_TRUE => T_TRUE, T_NULL => T_NULL, T_NAMESPACE => T_NAMESPACE, T_NS_SEPARATOR => T_NS_SEPARATOR, diff --git a/tests/Core/File/GetMemberPropertiesTest.inc b/tests/Core/File/GetMemberPropertiesTest.inc index f40b6021f4..51d11c2f1a 100644 --- a/tests/Core/File/GetMemberPropertiesTest.inc +++ b/tests/Core/File/GetMemberPropertiesTest.inc @@ -217,11 +217,11 @@ $anon = class() { public ?int|float $unionTypesNullable; /* testPHP8PseudoTypeNull */ - // Intentional fatal error - null pseudotype is only allowed in union types, but that's not the concern of the method. + // PHP 8.0 - 8.1: Intentional fatal error - null pseudotype is only allowed in union types, but that's not the concern of the method. public null $pseudoTypeNull; /* testPHP8PseudoTypeFalse */ - // Intentional fatal error - false pseudotype is only allowed in union types, but that's not the concern of the method. + // PHP 8.0 - 8.1: Intentional fatal error - false pseudotype is only allowed in union types, but that's not the concern of the method. public false $pseudoTypeFalse; /* testPHP8PseudoTypeFalseAndBool */ @@ -298,7 +298,22 @@ $anon = class() { // Intentional fatal error - types which are not allowed for intersection type, but that's not the concern of the method. public int&string $illegalIntersectionType; - /* testPHP81NulltableIntersectionType */ + /* testPHP81NullableIntersectionType */ // Intentional fatal error - nullability is not allowed with intersection type, but that's not the concern of the method. public ?Foo&Bar $nullableIntersectionType; }; + +$anon = class() { + /* testPHP82PseudoTypeTrue */ + public true $pseudoTypeTrue; + + /* testPHP82NullablePseudoTypeTrue */ + static protected ?true $pseudoTypeNullableTrue; + + /* testPHP82PseudoTypeTrueInUnion */ + private int|string|true $pseudoTypeTrueInUnion; + + /* testPHP82PseudoTypeFalseAndTrue */ + // Intentional fatal error - Type contains both true and false, bool should be used instead, but that's not the concern of the method. + readonly true|FALSE $pseudoTypeFalseAndTrue; +}; diff --git a/tests/Core/File/GetMemberPropertiesTest.php b/tests/Core/File/GetMemberPropertiesTest.php index 70d683ef2e..4fd5fb755b 100644 --- a/tests/Core/File/GetMemberPropertiesTest.php +++ b/tests/Core/File/GetMemberPropertiesTest.php @@ -795,7 +795,7 @@ public function dataGetMemberProperties() ], ], [ - '/* testPHP81NulltableIntersectionType */', + '/* testPHP81NullableIntersectionType */', [ 'scope' => 'public', 'scope_specified' => true, @@ -805,6 +805,51 @@ public function dataGetMemberProperties() 'nullable_type' => true, ], ], + [ + '/* testPHP82PseudoTypeTrue */', + [ + 'scope' => 'public', + 'scope_specified' => true, + 'is_static' => false, + 'is_readonly' => false, + 'type' => 'true', + 'nullable_type' => false, + ], + ], + [ + '/* testPHP82NullablePseudoTypeTrue */', + [ + 'scope' => 'protected', + 'scope_specified' => true, + 'is_static' => true, + 'is_readonly' => false, + 'type' => '?true', + 'nullable_type' => true, + ], + ], + [ + '/* testPHP82PseudoTypeTrueInUnion */', + [ + 'scope' => 'private', + 'scope_specified' => true, + 'is_static' => false, + 'is_readonly' => false, + 'type' => 'int|string|true', + 'nullable_type' => false, + ], + ], + [ + '/* testPHP82PseudoTypeFalseAndTrue */', + [ + 'scope' => 'public', + 'scope_specified' => false, + 'is_static' => false, + 'is_readonly' => true, + 'type' => 'true|FALSE', + 'nullable_type' => false, + ], + ], + ]; }//end dataGetMemberProperties() From d0443368f149a4f625e85117896e6ffd151010d2 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 9 Sep 2022 17:35:40 +0200 Subject: [PATCH 5/7] PHP 8.2 | Generic/LowerCaseType: allow for stand-alone true/false/null As of PHP 8.2, `true`, `false` and `null` will be allowed as stand-alone types. The `true` and the `false` types are allowed to be nullable, the `null` type is not (but that's not the concern of the sniff). Also see: https://3v4l.org/ZpfID This commit adjusts the sniff to take `true` into account. `false` and `null` were already handled due to these previously already being allowed in union types. Includes unit tests. Refs: * https://wiki.php.net/rfc/null-false-standalone-types * https://wiki.php.net/rfc/true-type --- src/Standards/Generic/Sniffs/PHP/LowerCaseTypeSniff.php | 1 + src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc | 2 ++ src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc.fixed | 2 ++ src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.php | 1 + 4 files changed, 6 insertions(+) diff --git a/src/Standards/Generic/Sniffs/PHP/LowerCaseTypeSniff.php b/src/Standards/Generic/Sniffs/PHP/LowerCaseTypeSniff.php index 29cfbc7e2b..28ecb0215f 100644 --- a/src/Standards/Generic/Sniffs/PHP/LowerCaseTypeSniff.php +++ b/src/Standards/Generic/Sniffs/PHP/LowerCaseTypeSniff.php @@ -37,6 +37,7 @@ class LowerCaseTypeSniff implements Sniff 'mixed' => true, 'static' => true, 'false' => true, + 'true' => true, 'null' => true, 'never' => true, ]; diff --git a/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc b/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc index 011adcd530..98d2aa4b56 100644 --- a/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc +++ b/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc @@ -92,3 +92,5 @@ function intersectionReturnTypes ($var): \Package\ClassName&\Package\Other_Class $arrow = fn (int $a, string $b, bool $c, array $d, Foo\Bar $e) : int => $a * $b; $arrow = fn (Int $a, String $b, BOOL $c, Array $d, Foo\Bar $e) : Float => $a * $b; + +$cl = function (False $a, TRUE $b, Null $c): ?True {} diff --git a/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc.fixed b/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc.fixed index d866101b6f..9f17f0f7b1 100644 --- a/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc.fixed +++ b/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc.fixed @@ -92,3 +92,5 @@ function intersectionReturnTypes ($var): \Package\ClassName&\Package\Other_Class $arrow = fn (int $a, string $b, bool $c, array $d, Foo\Bar $e) : int => $a * $b; $arrow = fn (int $a, string $b, bool $c, array $d, Foo\Bar $e) : float => $a * $b; + +$cl = function (false $a, true $b, null $c): ?true {} diff --git a/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.php b/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.php index 197b734a1f..51c42943bc 100644 --- a/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.php +++ b/src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.php @@ -67,6 +67,7 @@ public function getErrorList() 82 => 2, 85 => 1, 94 => 5, + 96 => 4, ]; }//end getErrorList() From 2e6988a0501bc5737398a44a5a8ecf1a969d3c13 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 9 Sep 2022 15:30:48 +0200 Subject: [PATCH 6/7] PHP 8.2 | PSR12/NullableTypeDeclaration: allow for nullable true/false As of PHP 8.2, `true`, `false` and `null` will be allowed as stand-alone types. The `true` and the `false` types are allowed to be nullable, the `null` type is not (but that's not the concern of the sniff). Also see: https://3v4l.org/ZpfID This adjusts the sniff to take these new types into account. Includes unit tests. Refs: * https://wiki.php.net/rfc/null-false-standalone-types * https://wiki.php.net/rfc/true-type --- .../Sniffs/Functions/NullableTypeDeclarationSniff.php | 3 +++ .../Tests/Functions/NullableTypeDeclarationUnitTest.inc | 8 ++++++++ .../Functions/NullableTypeDeclarationUnitTest.inc.fixed | 7 +++++++ .../Tests/Functions/NullableTypeDeclarationUnitTest.php | 3 +++ 4 files changed, 21 insertions(+) diff --git a/src/Standards/PSR12/Sniffs/Functions/NullableTypeDeclarationSniff.php b/src/Standards/PSR12/Sniffs/Functions/NullableTypeDeclarationSniff.php index 3f18a82179..ac0775d13e 100644 --- a/src/Standards/PSR12/Sniffs/Functions/NullableTypeDeclarationSniff.php +++ b/src/Standards/PSR12/Sniffs/Functions/NullableTypeDeclarationSniff.php @@ -27,6 +27,9 @@ class NullableTypeDeclarationSniff implements Sniff T_SELF => true, T_PARENT => true, T_STATIC => true, + T_NULL => true, + T_FALSE => true, + T_TRUE => true, ]; diff --git a/src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.inc b/src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.inc index e3a5a775f2..056d74c3f2 100644 --- a/src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.inc +++ b/src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.inc @@ -85,3 +85,11 @@ class testInstanceOf() { // PHP 8.0: static return type. function testStatic() : ? static {} + +// PHP 8.2: nullable true/false. +function fooG(): ? true {} +function fooH(): ? + false {} + +// Fatal error: null cannot be marked as nullable, but that's not the concern of this sniff. +function fooI(): ? null {} diff --git a/src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.inc.fixed b/src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.inc.fixed index 6225d1b337..6cc418d074 100644 --- a/src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.inc.fixed +++ b/src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.inc.fixed @@ -83,3 +83,10 @@ class testInstanceOf() { // PHP 8.0: static return type. function testStatic() : ?static {} + +// PHP 8.2: nullable true/false. +function fooG(): ?true {} +function fooH(): ?false {} + +// Fatal error: null cannot be marked as nullable, but that's not the concern of this sniff. +function fooI(): ?null {} diff --git a/src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.php b/src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.php index b4905d3650..da11498ad1 100644 --- a/src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.php +++ b/src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.php @@ -41,6 +41,9 @@ protected function getErrorList() 58 => 2, 59 => 2, 87 => 1, + 90 => 1, + 91 => 1, + 95 => 1, ]; }//end getErrorList() From ef96fc6b937bf685645e0bd2fc8512c9aa3070bb Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 4 Dec 2023 11:41:09 +0100 Subject: [PATCH 7/7] Changelog for #49 --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2a3dc0ac1..55016eb50c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,13 @@ The file documents changes to the PHP_CodeSniffer project. - Squiz.Commenting.FileComment - Squiz.Commenting.InlineComment - Thanks to Juliette Reinders Folmer (@jrfnl) for the patch +- Added support for `true` as a stand-alone type declaration + - The `File::getMethodProperties()`, `File::getMethodParameters()` and `File::getMemberProperties()` methods now all support the `true` type. + - Thanks to Juliette Reinders Folmer (@jrfnl) for the patch +- Added support for `true` as a stand-alone type to a number of sniffs + - Generic.PHP.LowerCaseType + - PSr12.Functions.NullableTypeDeclaration + - Thanks to Juliette Reinders Folmer (@jrfnl) for the patch - Squiz.Commenting.FunctionComment: new ParamNameUnexpectedAmpersandPrefix error for parameters annotated as passed by reference while the parameter is not passed by reference - Thanks to Dan Wallis (@fredden) for the patch - Documentation has been added for the following sniffs: @@ -39,6 +46,7 @@ The file documents changes to the PHP_CodeSniffer project. - Support for PHPUnit 8 and 9 to the test suite. - Test suites for external standards which run via the PHPCS native test suite can now run on PHPUnit 4-9 (was 4-7). - If any of these tests use the PHPUnit `setUp()`/`tearDown()` methods or overload the `setUp()` in the `AbstractSniffUnitTest` test case, they will need to be adjusted. See the [PR details for further information](https://github.com/PHPCSStandards/PHP_CodeSniffer/pull/59/commits/26384ebfcc0b1c1651b0e1e40c9b6c8c22881832). + - Thanks to Juliette Reinders Folmer (@jrfnl) for the patch ### Changed - Changes have been made to the way PHPCS handles invalid sniff properties being set in a custom ruleset @@ -69,6 +77,7 @@ The file documents changes to the PHP_CodeSniffer project. - Squiz.PHP.InnerFunctions sniff no longer reports on OO methods for OO structures declared within a function or closure - Thanks to @Daimona for the patch - Runtime performance improvement for PHPCS CLI users. The improvement should be most noticeable for users on Windows. + - Thanks to Juliette Reinders Folmer (@jrfnl) for the patch ### Removed - Removed support for installing via PEAR