mirror of
https://github.com/WordPress/WordPress-Coding-Standards.git
synced 2025-08-30 03:11:24 +08:00
Merge pull request #2551 from rodrigoprimo/asymmetric-visibility-properties
PHP 8.4 asymmetric visibility properties: add tests to four sniffs
This commit is contained in:
commit
be6312aa4b
7 changed files with 38 additions and 4 deletions
|
@ -174,7 +174,7 @@ final class GlobalVariablesOverrideSniff extends Sniff {
|
|||
protected function process_list_assignment( $stackPtr ) {
|
||||
$list_open_close = Lists::getOpenClose( $this->phpcsFile, $stackPtr );
|
||||
if ( false === $list_open_close ) {
|
||||
// Short array, not short list.
|
||||
// Live coding or short array, not short list.
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -673,4 +673,14 @@ class WP_Atom_Server {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Safeguard that PHP 8.4+ asymmetric visibility properties don't lead to false positives.
|
||||
* Including those defined using constructor property promotion.
|
||||
*/
|
||||
class Acronym_AsymmetricVisibilityProperties {
|
||||
public private(set) string $bar = 'bar'; // Ok.
|
||||
|
||||
public function __construct(public protected(set) int $foo = 0) {} // Ok.
|
||||
}
|
||||
|
||||
// phpcs:set WordPress.NamingConventions.PrefixAllGlobals prefixes[]
|
||||
|
|
|
@ -237,3 +237,11 @@ class Has_Mixed_Case_Property {
|
|||
$lähtöaika = true; // OK.
|
||||
$lÄhtÖaika = true; // Bad, but only handled by the sniff if Mbstring is available.
|
||||
$lÄhtOaika = true; // Bad, handled via transliteration of non-ASCII chars if Mbstring is not available.
|
||||
|
||||
/*
|
||||
* Safeguard that the sniff handles PHP 8.4+ asymmetric visibility properties correctly.
|
||||
*/
|
||||
class Acronym_AsymmetricVisibilityProperties {
|
||||
public private(set) string $valid_name = 'bar'; // Ok.
|
||||
public(set) string $invalidName = 'bar'; // Bad.
|
||||
}
|
||||
|
|
|
@ -98,6 +98,7 @@ final class ValidVariableNameUnitTest extends AbstractSniffUnitTest {
|
|||
227 => 1,
|
||||
238 => function_exists( 'mb_strtolower' ) ? 1 : 0,
|
||||
239 => 1,
|
||||
246 => 1,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,4 +3,5 @@
|
|||
class IgnoreProperties {
|
||||
public $_GET = array( 'key' => 'something' ); // OK.
|
||||
public $_POST; // OK.
|
||||
public private(set) string $_REQUEST; // Ok.
|
||||
}
|
||||
|
|
|
@ -311,6 +311,12 @@ list(
|
|||
get($year, $day) => &$not_a_wp_global[$year]
|
||||
] = $array;
|
||||
|
||||
// Live coding/parse error.
|
||||
// This has to be the last test in the file!
|
||||
list( $tab, $tabs
|
||||
/*
|
||||
* Safeguard that PHP 8.4+ asymmetric visibility properties don't lead to false positives.
|
||||
* Including those defined using constructor property promotion.
|
||||
*/
|
||||
class AsymmetricVisibilityProperties {
|
||||
public private(set) string $pagenow = 'bar'; // Ok.
|
||||
|
||||
public function __construct(public protected(set) int $page = 0) {} // Ok.
|
||||
}
|
||||
|
|
8
WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.8.inc
Normal file
8
WordPress/Tests/WP/GlobalVariablesOverrideUnitTest.8.inc
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Intentional parse error (missing closing parenthesis).
|
||||
* This should be the only test in this file.
|
||||
*/
|
||||
|
||||
list( $tab, $tabs
|
Loading…
Add table
Add a link
Reference in a new issue