-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #173 from PHPCSStandards/universal/noreservedkeywo…
…rdparamname-various-improvements Universal/NoReservedKeywordParameterNames: various improvements
- Loading branch information
Showing
3 changed files
with
170 additions
and
117 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
47 changes: 43 additions & 4 deletions
47
Universal/Tests/NamingConventions/NoReservedKeywordParameterNamesUnitTest.inc
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 |
---|---|---|
@@ -1,15 +1,54 @@ | ||
<?php | ||
|
||
function foo( $parameter, $descriptive_name ) {} // OK. | ||
function noReservedKeywords( $parameter, $descriptive_name ) {} // OK. | ||
|
||
function foo( $string, $echo = true ) {} // Bad x 2. | ||
function hasReservedKeywords( $string, $echo = true ) {} // Bad x 2. | ||
$closure = function ( $foreach, $array, $require ) {}; // Bad x 3. | ||
$fn = fn($callable, $list) => $callable($list); // Bad x 2. | ||
$fn = fn($callable, $__FILE__) => $callable($__FILE__); // Bad x 2. | ||
|
||
abstract class Foo { | ||
abstract public function bar( | ||
abstract public function abstractMethod( | ||
string &$string, | ||
Foo|false $exit, | ||
?int $parent | ||
); // Bad x 3. | ||
} | ||
|
||
/* | ||
* Tests using less conventional param name casing. | ||
*/ | ||
function noReservedKeywordsCasedParams( $Parameter, $DescriptiveName ) {} // OK. | ||
|
||
function hasReservedKeywordsCasedParams( $String, $ECHO = true ) {} // Bad x 2. | ||
$closure = function ( $forEach, $Array, $REQUIRE ) {}; // Bad x 3. | ||
$fn = fn($Callable, $__file__) => $Callable($__file__); // Bad x 2. | ||
|
||
abstract class Bar { | ||
abstract public function abstractMethodCasedParams( | ||
string &$STRING, | ||
Foo|false $Exit, | ||
?int $PaReNt | ||
); // Bad x 3. | ||
} | ||
|
||
/* | ||
* Also flag properties declared via constructor property promotion as those can also be | ||
* passed to the class constructor as named parameters. | ||
*/ | ||
class ConstructorPropertyPromotionNoTypes { | ||
public function __construct( | ||
public $const = 0.0, | ||
protected $do = '', | ||
private $eval = null, | ||
) {} | ||
} | ||
|
||
class ConstructorPropertyPromotionWithTypes { | ||
public function __construct(protected float|int $Function, public ?string &$GLOBAL = 'test', private mixed $match) {} | ||
} | ||
|
||
// No parameters, nothing to do. | ||
function noParam() {} | ||
|
||
// Live coding/parse error. This has to be the last test in the file. | ||
function liveCoding($echo |
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