Skip to content

Commit be6312a

Browse files
authored
Merge pull request #2551 from rodrigoprimo/asymmetric-visibility-properties
PHP 8.4 asymmetric visibility properties: add tests to four sniffs
2 parents f8685a2 + a1f0108 commit be6312a

7 files changed

+38
-4
lines changed

WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public function process_token( $stackPtr ) {
174174
protected function process_list_assignment( $stackPtr ) {
175175
$list_open_close = Lists::getOpenClose( $this->phpcsFile, $stackPtr );
176176
if ( false === $list_open_close ) {
177-
// Short array, not short list.
177+
// Live coding or short array, not short list.
178178
return;
179179
}
180180

WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.1.inc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,4 +673,14 @@ class WP_Atom_Server {
673673
}
674674
}
675675

676+
/*
677+
* Safeguard that PHP 8.4+ asymmetric visibility properties don't lead to false positives.
678+
* Including those defined using constructor property promotion.
679+
*/
680+
class Acronym_AsymmetricVisibilityProperties {
681+
public private(set) string $bar = 'bar'; // Ok.
682+
683+
public function __construct(public protected(set) int $foo = 0) {} // Ok.
684+
}
685+
676686
// phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[]

WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.inc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,11 @@ class Has_Mixed_Case_Property {
237237
$lähtöaika = true; // OK.
238238
$lÄhtÖaika = true; // Bad, but only handled by the sniff if Mbstring is available.
239239
$lÄhtOaika = true; // Bad, handled via transliteration of non-ASCII chars if Mbstring is not available.
240+
241+
/*
242+
* Safeguard that the sniff handles PHP 8.4+ asymmetric visibility properties correctly.
243+
*/
244+
class Acronym_AsymmetricVisibilityProperties {
245+
public private(set) string $valid_name = 'bar'; // Ok.
246+
public(set) string $invalidName = 'bar'; // Bad.
247+
}

WordPress/Tests/NamingConventions/ValidVariableNameUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public function getErrorList() {
9898
227 => 1,
9999
238 => function_exists( 'mb_strtolower' ) ? 1 : 0,
100100
239 => 1,
101+
246 => 1,
101102
);
102103
}
103104

WordPress/Tests/Security/NonceVerificationUnitTest.8.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
class IgnoreProperties {
44
public $_GET = array( 'key' => 'something' ); // OK.
55
public $_POST; // OK.
6+
public private(set) string $_REQUEST; // Ok.
67
}

WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.1.inc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,12 @@ list(
311311
get($year, $day) => &$not_a_wp_global[$year]
312312
] = $array;
313313

314-
// Live coding/parse error.
315-
// This has to be the last test in the file!
316-
list( $tab, $tabs
314+
/*
315+
* Safeguard that PHP 8.4+ asymmetric visibility properties don't lead to false positives.
316+
* Including those defined using constructor property promotion.
317+
*/
318+
class AsymmetricVisibilityProperties {
319+
public private(set) string $pagenow = 'bar'; // Ok.
320+
321+
public function __construct(public protected(set) int $page = 0) {} // Ok.
322+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
/*
4+
* Intentional parse error (missing closing parenthesis).
5+
* This should be the only test in this file.
6+
*/
7+
8+
list( $tab, $tabs

0 commit comments

Comments
 (0)