Skip to content

Commit 26df2fc

Browse files
authored
Merge pull request #49 from PHPCSStandards/php-8.2/account-for-true-type
PHP 8.2 | Tokenizer, File, sniffs: account for new `true` type
2 parents 2ff6414 + ef96fc6 commit 26df2fc

19 files changed

+228
-8
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ The file documents changes to the PHP_CodeSniffer project.
2929
- Squiz.Commenting.FileComment
3030
- Squiz.Commenting.InlineComment
3131
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
32+
- Added support for `true` as a stand-alone type declaration
33+
- The `File::getMethodProperties()`, `File::getMethodParameters()` and `File::getMemberProperties()` methods now all support the `true` type.
34+
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
35+
- Added support for `true` as a stand-alone type to a number of sniffs
36+
- Generic.PHP.LowerCaseType
37+
- PSr12.Functions.NullableTypeDeclaration
38+
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
3239
- Squiz.Commenting.FunctionComment: new ParamNameUnexpectedAmpersandPrefix error for parameters annotated as passed by reference while the parameter is not passed by reference
3340
- Thanks to Dan Wallis (@fredden) for the patch
3441
- Documentation has been added for the following sniffs:
@@ -39,6 +46,7 @@ The file documents changes to the PHP_CodeSniffer project.
3946
- Support for PHPUnit 8 and 9 to the test suite.
4047
- Test suites for external standards which run via the PHPCS native test suite can now run on PHPUnit 4-9 (was 4-7).
4148
- 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).
49+
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
4250

4351
### Changed
4452
- 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.
6977
- Squiz.PHP.InnerFunctions sniff no longer reports on OO methods for OO structures declared within a function or closure
7078
- Thanks to @Daimona for the patch
7179
- Runtime performance improvement for PHPCS CLI users. The improvement should be most noticeable for users on Windows.
80+
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
7281

7382
### Removed
7483
- Removed support for installing via PEAR

src/Files/File.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,7 @@ public function getMethodParameters($stackPtr)
14791479
case T_TYPE_UNION:
14801480
case T_TYPE_INTERSECTION:
14811481
case T_FALSE:
1482+
case T_TRUE:
14821483
case T_NULL:
14831484
// Part of a type hint or default value.
14841485
if ($defaultStart === null) {
@@ -1705,6 +1706,7 @@ public function getMethodProperties($stackPtr)
17051706
T_PARENT => T_PARENT,
17061707
T_STATIC => T_STATIC,
17071708
T_FALSE => T_FALSE,
1709+
T_TRUE => T_TRUE,
17081710
T_NULL => T_NULL,
17091711
T_NAMESPACE => T_NAMESPACE,
17101712
T_NS_SEPARATOR => T_NS_SEPARATOR,
@@ -1906,6 +1908,7 @@ public function getMemberProperties($stackPtr)
19061908
T_SELF => T_SELF,
19071909
T_PARENT => T_PARENT,
19081910
T_FALSE => T_FALSE,
1911+
T_TRUE => T_TRUE,
19091912
T_NULL => T_NULL,
19101913
T_NAMESPACE => T_NAMESPACE,
19111914
T_NS_SEPARATOR => T_NS_SEPARATOR,

src/Standards/Generic/Sniffs/PHP/LowerCaseTypeSniff.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class LowerCaseTypeSniff implements Sniff
3737
'mixed' => true,
3838
'static' => true,
3939
'false' => true,
40+
'true' => true,
4041
'null' => true,
4142
'never' => true,
4243
];

src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,5 @@ function intersectionReturnTypes ($var): \Package\ClassName&\Package\Other_Class
9292

9393
$arrow = fn (int $a, string $b, bool $c, array $d, Foo\Bar $e) : int => $a * $b;
9494
$arrow = fn (Int $a, String $b, BOOL $c, Array $d, Foo\Bar $e) : Float => $a * $b;
95+
96+
$cl = function (False $a, TRUE $b, Null $c): ?True {}

src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc.fixed

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,5 @@ function intersectionReturnTypes ($var): \Package\ClassName&\Package\Other_Class
9292

9393
$arrow = fn (int $a, string $b, bool $c, array $d, Foo\Bar $e) : int => $a * $b;
9494
$arrow = fn (int $a, string $b, bool $c, array $d, Foo\Bar $e) : float => $a * $b;
95+
96+
$cl = function (false $a, true $b, null $c): ?true {}

src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public function getErrorList()
6767
82 => 2,
6868
85 => 1,
6969
94 => 5,
70+
96 => 4,
7071
];
7172

7273
}//end getErrorList()

src/Standards/PSR12/Sniffs/Functions/NullableTypeDeclarationSniff.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class NullableTypeDeclarationSniff implements Sniff
2727
T_SELF => true,
2828
T_PARENT => true,
2929
T_STATIC => true,
30+
T_NULL => true,
31+
T_FALSE => true,
32+
T_TRUE => true,
3033
];
3134

3235

src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.inc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,11 @@ class testInstanceOf() {
8585

8686
// PHP 8.0: static return type.
8787
function testStatic() : ? static {}
88+
89+
// PHP 8.2: nullable true/false.
90+
function fooG(): ? true {}
91+
function fooH(): ?
92+
false {}
93+
94+
// Fatal error: null cannot be marked as nullable, but that's not the concern of this sniff.
95+
function fooI(): ? null {}

src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.inc.fixed

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,10 @@ class testInstanceOf() {
8383

8484
// PHP 8.0: static return type.
8585
function testStatic() : ?static {}
86+
87+
// PHP 8.2: nullable true/false.
88+
function fooG(): ?true {}
89+
function fooH(): ?false {}
90+
91+
// Fatal error: null cannot be marked as nullable, but that's not the concern of this sniff.
92+
function fooI(): ?null {}

src/Standards/PSR12/Tests/Functions/NullableTypeDeclarationUnitTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ protected function getErrorList()
4141
58 => 2,
4242
59 => 2,
4343
87 => 1,
44+
90 => 1,
45+
91 => 1,
46+
95 => 1,
4447
];
4548

4649
}//end getErrorList()

0 commit comments

Comments
 (0)