Skip to content

Commit 653720c

Browse files
authored
Merge pull request #256 from PHPCSStandards/feature/no-reserved-keyword-params
PHP 8.0 | QA/CS: don't use reserved keywords as parameter names
2 parents 97d8101 + 11c8731 commit 653720c

File tree

6 files changed

+85
-81
lines changed

6 files changed

+85
-81
lines changed

PHPCSUtils/Utils/Numbers.php

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -332,16 +332,18 @@ public static function getCompleteNumber(File $phpcsFile, $stackPtr)
332332
*
333333
* @since 1.0.0
334334
*
335-
* @param string $string Arbitrary token content string.
335+
* @param string $textString Arbitrary text string.
336+
* This text string should be the (combined) token content of
337+
* one or more tokens which together represent a number in PHP.
336338
*
337339
* @return string|false Decimal number as a string or `FALSE` if the passed parameter
338340
* was not a numeric string.
339341
* > Note: floating point numbers with exponent will not be expanded,
340342
* but returned as-is.
341343
*/
342-
public static function getDecimalValue($string)
344+
public static function getDecimalValue($textString)
343345
{
344-
if (\is_string($string) === false || $string === '') {
346+
if (\is_string($textString) === false || $textString === '') {
345347
return false;
346348
}
347349

@@ -352,26 +354,26 @@ public static function getDecimalValue($string)
352354
* here to allow the hexdec(), bindec() functions to work correctly and for
353355
* the decimal/float to return a cross-version compatible decimal value.}
354356
*/
355-
$string = \str_replace('_', '', $string);
357+
$textString = \str_replace('_', '', $textString);
356358

357-
if (self::isDecimalInt($string) === true) {
358-
return $string;
359+
if (self::isDecimalInt($textString) === true) {
360+
return $textString;
359361
}
360362

361-
if (self::isHexidecimalInt($string) === true) {
362-
return (string) \hexdec($string);
363+
if (self::isHexidecimalInt($textString) === true) {
364+
return (string) \hexdec($textString);
363365
}
364366

365-
if (self::isBinaryInt($string) === true) {
366-
return (string) \bindec($string);
367+
if (self::isBinaryInt($textString) === true) {
368+
return (string) \bindec($textString);
367369
}
368370

369-
if (self::isOctalInt($string) === true) {
370-
return (string) \octdec($string);
371+
if (self::isOctalInt($textString) === true) {
372+
return (string) \octdec($textString);
371373
}
372374

373-
if (self::isFloat($string) === true) {
374-
return $string;
375+
if (self::isFloat($textString) === true) {
376+
return $textString;
375377
}
376378

377379
return false;
@@ -384,20 +386,20 @@ public static function getDecimalValue($string)
384386
*
385387
* @since 1.0.0
386388
*
387-
* @param string $string Arbitrary string.
389+
* @param string $textString Arbitrary string.
388390
*
389391
* @return bool
390392
*/
391-
public static function isDecimalInt($string)
393+
public static function isDecimalInt($textString)
392394
{
393-
if (\is_string($string) === false || $string === '') {
395+
if (\is_string($textString) === false || $textString === '') {
394396
return false;
395397
}
396398

397399
// Remove potential PHP 7.4 numeric literal separators.
398-
$string = \str_replace('_', '', $string);
400+
$textString = \str_replace('_', '', $textString);
399401

400-
return (\preg_match(self::REGEX_DECIMAL_INT, $string) === 1);
402+
return (\preg_match(self::REGEX_DECIMAL_INT, $textString) === 1);
401403
}
402404

403405
/**
@@ -407,20 +409,20 @@ public static function isDecimalInt($string)
407409
*
408410
* @since 1.0.0
409411
*
410-
* @param string $string Arbitrary string.
412+
* @param string $textString Arbitrary string.
411413
*
412414
* @return bool
413415
*/
414-
public static function isHexidecimalInt($string)
416+
public static function isHexidecimalInt($textString)
415417
{
416-
if (\is_string($string) === false || $string === '') {
418+
if (\is_string($textString) === false || $textString === '') {
417419
return false;
418420
}
419421

420422
// Remove potential PHP 7.4 numeric literal separators.
421-
$string = \str_replace('_', '', $string);
423+
$textString = \str_replace('_', '', $textString);
422424

423-
return (\preg_match(self::REGEX_HEX_INT, $string) === 1);
425+
return (\preg_match(self::REGEX_HEX_INT, $textString) === 1);
424426
}
425427

426428
/**
@@ -430,20 +432,20 @@ public static function isHexidecimalInt($string)
430432
*
431433
* @since 1.0.0
432434
*
433-
* @param string $string Arbitrary string.
435+
* @param string $textString Arbitrary string.
434436
*
435437
* @return bool
436438
*/
437-
public static function isBinaryInt($string)
439+
public static function isBinaryInt($textString)
438440
{
439-
if (\is_string($string) === false || $string === '') {
441+
if (\is_string($textString) === false || $textString === '') {
440442
return false;
441443
}
442444

443445
// Remove potential PHP 7.4 numeric literal separators.
444-
$string = \str_replace('_', '', $string);
446+
$textString = \str_replace('_', '', $textString);
445447

446-
return (\preg_match(self::REGEX_BINARY_INT, $string) === 1);
448+
return (\preg_match(self::REGEX_BINARY_INT, $textString) === 1);
447449
}
448450

449451
/**
@@ -453,20 +455,20 @@ public static function isBinaryInt($string)
453455
*
454456
* @since 1.0.0
455457
*
456-
* @param string $string Arbitrary string.
458+
* @param string $textString Arbitrary string.
457459
*
458460
* @return bool
459461
*/
460-
public static function isOctalInt($string)
462+
public static function isOctalInt($textString)
461463
{
462-
if (\is_string($string) === false || $string === '') {
464+
if (\is_string($textString) === false || $textString === '') {
463465
return false;
464466
}
465467

466468
// Remove potential PHP 7.4 numeric literal separators.
467-
$string = \str_replace('_', '', $string);
469+
$textString = \str_replace('_', '', $textString);
468470

469-
return (\preg_match(self::REGEX_OCTAL_INT, $string) === 1);
471+
return (\preg_match(self::REGEX_OCTAL_INT, $textString) === 1);
470472
}
471473

472474
/**
@@ -476,19 +478,19 @@ public static function isOctalInt($string)
476478
*
477479
* @since 1.0.0
478480
*
479-
* @param string $string Arbitrary string.
481+
* @param string $textString Arbitrary string.
480482
*
481483
* @return bool
482484
*/
483-
public static function isFloat($string)
485+
public static function isFloat($textString)
484486
{
485-
if (\is_string($string) === false || $string === '') {
487+
if (\is_string($textString) === false || $textString === '') {
486488
return false;
487489
}
488490

489491
// Remove potential PHP 7.4 numeric literal separators.
490-
$string = \str_replace('_', '', $string);
492+
$textString = \str_replace('_', '', $textString);
491493

492-
return (\preg_match(self::REGEX_FLOAT, $string) === 1);
494+
return (\preg_match(self::REGEX_FLOAT, $textString) === 1);
493495
}
494496
}

PHPCSUtils/Utils/Orthography.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,51 +43,51 @@ class Orthography
4343
*
4444
* @since 1.0.0
4545
*
46-
* @param string $string The text string to examine.
47-
* This can be the contents of a text string token,
48-
* but also, for instance, a comment text.
49-
* Potential text delimiter quotes should be stripped
50-
* off a text string before passing it to this method.
51-
* Also see: {@see \PHPCSUtils\Utils\TextStrings::stripQuotes()}.
46+
* @param string $textString The text string to examine.
47+
* This can be the contents of a text string token,
48+
* but also, for instance, a comment text.
49+
* Potential text delimiter quotes should be stripped
50+
* off a text string before passing it to this method.
51+
* Also see: {@see \PHPCSUtils\Utils\TextStrings::stripQuotes()}.
5252
*
5353
* @return bool `TRUE` when the first character is a capital letter or a letter
5454
* which doesn't have a concept of capitalization.
5555
* `FALSE` otherwise, including for non-letter characters.
5656
*/
57-
public static function isFirstCharCapitalized($string)
57+
public static function isFirstCharCapitalized($textString)
5858
{
59-
$string = \ltrim($string);
60-
return (\preg_match('`^[\p{Lu}\p{Lt}\p{Lo}]`u', $string) > 0);
59+
$textString = \ltrim($textString);
60+
return (\preg_match('`^[\p{Lu}\p{Lt}\p{Lo}]`u', $textString) > 0);
6161
}
6262

6363
/**
6464
* Check if the first character of an arbitrary text string is a lowercase letter.
6565
*
6666
* @since 1.0.0
6767
*
68-
* @param string $string The text string to examine.
69-
* This can be the contents of a text string token,
70-
* but also, for instance, a comment text.
71-
* Potential text delimiter quotes should be stripped
72-
* off a text string before passing it to this method.
73-
* Also see: {@see \PHPCSUtils\Utils\TextStrings::stripQuotes()}.
68+
* @param string $textString The text string to examine.
69+
* This can be the contents of a text string token,
70+
* but also, for instance, a comment text.
71+
* Potential text delimiter quotes should be stripped
72+
* off a text string before passing it to this method.
73+
* Also see: {@see \PHPCSUtils\Utils\TextStrings::stripQuotes()}.
7474
*
7575
* @return bool `TRUE` when the first character is a lowercase letter.
7676
* `FALSE` otherwise, including for letters which don't have a concept of
7777
* capitalization and for non-letter characters.
7878
*/
79-
public static function isFirstCharLowercase($string)
79+
public static function isFirstCharLowercase($textString)
8080
{
81-
$string = \ltrim($string);
82-
return (\preg_match('`^\p{Ll}`u', $string) > 0);
81+
$textString = \ltrim($textString);
82+
return (\preg_match('`^\p{Ll}`u', $textString) > 0);
8383
}
8484

8585
/**
8686
* Check if the last character of an arbitrary text string is a valid punctuation character.
8787
*
8888
* @since 1.0.0
8989
*
90-
* @param string $string The text string to examine.
90+
* @param string $textString The text string to examine.
9191
* This can be the contents of a text string token,
9292
* but also, for instance, a comment text.
9393
* Potential text delimiter quotes should be stripped
@@ -100,19 +100,19 @@ public static function isFirstCharLowercase($string)
100100
*
101101
* @return bool
102102
*/
103-
public static function isLastCharPunctuation($string, $allowedChars = self::TERMINAL_POINTS)
103+
public static function isLastCharPunctuation($textString, $allowedChars = self::TERMINAL_POINTS)
104104
{
105105
static $encoding;
106106

107107
if (isset($encoding) === false) {
108108
$encoding = Helper::getEncoding();
109109
}
110110

111-
$string = \rtrim($string);
111+
$textString = \rtrim($textString);
112112
if (\function_exists('iconv_substr') === true) {
113-
$lastChar = \iconv_substr($string, -1, 1, $encoding);
113+
$lastChar = \iconv_substr($textString, -1, 1, $encoding);
114114
} else {
115-
$lastChar = \substr($string, -1);
115+
$lastChar = \substr($textString, -1);
116116
}
117117

118118
if (\function_exists('iconv_strpos') === true) {

PHPCSUtils/Utils/TextStrings.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,21 @@ public static function getCompleteTextString(File $phpcsFile, $stackPtr, $stripQ
113113
}
114114

115115
/**
116-
* Strip text delimiter quotes from an arbitrary string.
116+
* Strip text delimiter quotes from an arbitrary text string.
117117
*
118118
* Intended for use with the "contents" of a `T_CONSTANT_ENCAPSED_STRING` / `T_DOUBLE_QUOTED_STRING`.
119119
*
120120
* - Prevents stripping mis-matched quotes.
121-
* - Prevents stripping quotes from the textual content of the string.
121+
* - Prevents stripping quotes from the textual content of the text string.
122122
*
123123
* @since 1.0.0
124124
*
125-
* @param string $string The raw string.
125+
* @param string $textString The raw text string.
126126
*
127-
* @return string String without quotes around it.
127+
* @return string Text string without quotes around it.
128128
*/
129-
public static function stripQuotes($string)
129+
public static function stripQuotes($textString)
130130
{
131-
return \preg_replace('`^([\'"])(.*)\1$`Ds', '$2', $string);
131+
return \preg_replace('`^([\'"])(.*)\1$`Ds', '$2', $textString);
132132
}
133133
}

Tests/AssertAttributeSame.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,27 +58,27 @@ public function assertAttributeValueSame($expected, $attributeName, $actualObjec
5858
* Retrieve the value of an object's attribute.
5959
* This also works for attributes that are declared protected or private.
6060
*
61-
* @param object|string $object The object or class on which to check the property value.
62-
* @param string $attributeName The name of the property to check.
61+
* @param object|string $objectUnderTest The object or class on which to check the property value.
62+
* @param string $attributeName The name of the property to check.
6363
*
6464
* @return mixed Property value.
6565
*
6666
* @throws \Exception
6767
*/
68-
public static function getObjectAttributeValue($object, $attributeName)
68+
public static function getObjectAttributeValue($objectUnderTest, $attributeName)
6969
{
70-
$reflector = new ReflectionObject($object);
70+
$reflector = new ReflectionObject($objectUnderTest);
7171

7272
do {
7373
try {
7474
$attribute = $reflector->getProperty($attributeName);
7575

7676
if (!$attribute || $attribute->isPublic()) {
77-
return $object->$attributeName;
77+
return $objectUnderTest->$attributeName;
7878
}
7979

8080
$attribute->setAccessible(true);
81-
$value = $attribute->getValue($object);
81+
$value = $attribute->getValue($objectUnderTest);
8282
$attribute->setAccessible(false);
8383

8484
return $value;

Tests/bootstrap.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,17 @@
8787
* Fixes issues with PHPUnit not being able to find test classes being extended when running
8888
* in a non-Composer context.
8989
*/
90-
\spl_autoload_register(function ($class) {
90+
\spl_autoload_register(function ($fqClassName) {
9191
// Only try & load our own classes.
92-
if (\stripos($class, 'PHPCSUtils\Tests\\') !== 0) {
92+
if (\stripos($fqClassName, 'PHPCSUtils\Tests\\') !== 0) {
9393
return;
9494
}
9595

9696
// Strip namespace prefix 'PHPCSUtils\Tests\'.
97-
$class = \substr($class, 17);
98-
$file = \realpath(__DIR__) . \DIRECTORY_SEPARATOR . \strtr($class, '\\', \DIRECTORY_SEPARATOR) . '.php';
97+
$relativeClass = \substr($fqClassName, 17);
98+
$file = \realpath(__DIR__) . \DIRECTORY_SEPARATOR
99+
. \strtr($relativeClass, '\\', \DIRECTORY_SEPARATOR) . '.php';
100+
99101
if (\file_exists($file)) {
100102
include_once $file;
101103
}

phpcsutils-autoload.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@
3636
* External PHPCS standards which have their own unit test suite
3737
* should include this file in their test runner bootstrap.
3838
*/
39-
spl_autoload_register(function ($class) {
39+
spl_autoload_register(function ($fqClassName) {
4040
// Only try & load our own classes.
41-
if (stripos($class, 'PHPCSUtils') !== 0) {
41+
if (stripos($fqClassName, 'PHPCSUtils') !== 0) {
4242
return;
4343
}
4444

45-
$file = realpath(__DIR__) . DIRECTORY_SEPARATOR . strtr($class, '\\', DIRECTORY_SEPARATOR) . '.php';
45+
$file = realpath(__DIR__) . DIRECTORY_SEPARATOR . strtr($fqClassName, '\\', DIRECTORY_SEPARATOR) . '.php';
4646

4747
if (file_exists($file)) {
4848
include_once $file;

0 commit comments

Comments
 (0)