Skip to content

Commit b82e30c

Browse files
authored
Merge pull request #1233 from PHPCSStandards/phpcs-4.x/feature/cs-qa-no-reserved-keywords-as-param-names
CS/QA: rename various parameters
2 parents 9397a57 + d0d52cd commit b82e30c

File tree

9 files changed

+116
-116
lines changed

9 files changed

+116
-116
lines changed

autoload.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,19 @@ class Autoload
6161
* This method only loads classes that exist in the PHP_CodeSniffer namespace.
6262
* All other classes are ignored and loaded by subsequent autoloaders.
6363
*
64-
* @param string $class The name of the class to load.
64+
* @param string $className The name of the class to load.
6565
*
6666
* @return bool
6767
*/
68-
public static function load($class)
68+
public static function load($className)
6969
{
7070
// Include the composer autoloader if there is one, but re-register it
7171
// so this autoloader runs before the composer one as we need to include
7272
// all files so we can figure out what the class/interface/trait name is.
7373
if (self::$composerAutoloader === null) {
7474
// Make sure we don't try to load any of Composer's classes
7575
// while the autoloader is being setup.
76-
if (strpos($class, 'Composer\\') === 0) {
76+
if (strpos($className, 'Composer\\') === 0) {
7777
return false;
7878
}
7979

@@ -97,32 +97,32 @@ public static function load($class)
9797
$ds = DIRECTORY_SEPARATOR;
9898
$path = false;
9999

100-
if (substr($class, 0, 16) === 'PHP_CodeSniffer\\') {
101-
if (substr($class, 0, 22) === 'PHP_CodeSniffer\Tests\\') {
100+
if (substr($className, 0, 16) === 'PHP_CodeSniffer\\') {
101+
if (substr($className, 0, 22) === 'PHP_CodeSniffer\Tests\\') {
102102
$isInstalled = !is_dir(__DIR__.$ds.'tests');
103103
if ($isInstalled === false) {
104104
$path = __DIR__.$ds.'tests';
105105
} else {
106106
$path = '@test_dir@'.$ds.'PHP_CodeSniffer'.$ds.'CodeSniffer';
107107
}
108108

109-
$path .= $ds.substr(str_replace('\\', $ds, $class), 22).'.php';
109+
$path .= $ds.substr(str_replace('\\', $ds, $className), 22).'.php';
110110
} else {
111-
$path = __DIR__.$ds.'src'.$ds.substr(str_replace('\\', $ds, $class), 16).'.php';
111+
$path = __DIR__.$ds.'src'.$ds.substr(str_replace('\\', $ds, $className), 16).'.php';
112112
}
113113
}
114114

115115
// See if the composer autoloader knows where the class is.
116116
if ($path === false && self::$composerAutoloader !== false) {
117-
$path = self::$composerAutoloader->findFile($class);
117+
$path = self::$composerAutoloader->findFile($className);
118118
}
119119

120120
// See if the class is inside one of our alternate search paths.
121121
if ($path === false) {
122122
foreach (self::$searchPaths as $searchPath => $nsPrefix) {
123-
$className = $class;
124-
if ($nsPrefix !== '' && substr($class, 0, strlen($nsPrefix)) === $nsPrefix) {
125-
$className = substr($class, (strlen($nsPrefix) + 1));
123+
$className = $className;
124+
if ($nsPrefix !== '' && substr($className, 0, strlen($nsPrefix)) === $nsPrefix) {
125+
$className = substr($className, (strlen($nsPrefix) + 1));
126126
}
127127

128128
$path = $searchPath.$ds.str_replace('\\', $ds, $className).'.php';
@@ -297,18 +297,18 @@ public static function getLoadedClassName($path)
297297
/**
298298
* Gets the file path for the given class name.
299299
*
300-
* @param string $class The name of the class.
300+
* @param string $className The name of the class.
301301
*
302302
* @throws \Exception If the class name has not been loaded.
303303
* @return string
304304
*/
305-
public static function getLoadedFileName($class)
305+
public static function getLoadedFileName($className)
306306
{
307-
if (isset(self::$loadedFiles[$class]) === false) {
308-
throw new Exception("Cannot get file name for $class; class has not been included");
307+
if (isset(self::$loadedFiles[$className]) === false) {
308+
throw new Exception("Cannot get file name for $className; class has not been included");
309309
}
310310

311-
return self::$loadedFiles[$class];
311+
return self::$loadedFiles[$className];
312312

313313
}//end getLoadedFileName()
314314

src/Config.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,12 +1483,12 @@ public function printUsage()
14831483
/**
14841484
* Prints out the short usage information for this script.
14851485
*
1486-
* @param bool $return If TRUE, the usage string is returned
1487-
* instead of output to screen.
1486+
* @param bool $returnOutput If TRUE, the usage string is returned
1487+
* instead of output to screen.
14881488
*
14891489
* @return string|void
14901490
*/
1491-
public function printShortUsage($return=false)
1491+
public function printShortUsage($returnOutput=false)
14921492
{
14931493
if (PHP_CODESNIFFER_CBF === true) {
14941494
$usage = 'Run "phpcbf --help" for usage information';
@@ -1498,7 +1498,7 @@ public function printShortUsage($return=false)
14981498

14991499
$usage .= PHP_EOL.PHP_EOL;
15001500

1501-
if ($return === true) {
1501+
if ($returnOutput === true) {
15021502
return $usage;
15031503
}
15041504

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ public function __construct()
4949
/**
5050
* Generates the error or warning for this sniff.
5151
*
52-
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
53-
* @param int $stackPtr The position of the forbidden function
54-
* in the token array.
55-
* @param string $function The name of the forbidden function.
56-
* @param string $pattern The pattern used for the match.
52+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
53+
* @param int $stackPtr The position of the forbidden function
54+
* in the token array.
55+
* @param string $functionName The name of the forbidden function.
56+
* @param string $pattern The pattern used for the match.
5757
*
5858
* @return void
5959
*/
60-
protected function addError($phpcsFile, $stackPtr, $function, $pattern=null)
60+
protected function addError($phpcsFile, $stackPtr, $functionName, $pattern=null)
6161
{
62-
$data = [$function];
62+
$data = [$functionName];
6363
$error = 'Function %s() has been deprecated';
6464
$type = 'Deprecated';
6565

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,17 +202,17 @@ public function process(File $phpcsFile, $stackPtr)
202202
/**
203203
* Generates the error or warning for this sniff.
204204
*
205-
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
206-
* @param int $stackPtr The position of the forbidden function
207-
* in the token array.
208-
* @param string $function The name of the forbidden function.
209-
* @param string $pattern The pattern used for the match.
205+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
206+
* @param int $stackPtr The position of the forbidden function
207+
* in the token array.
208+
* @param string $functionName The name of the forbidden function.
209+
* @param string $pattern The pattern used for the match.
210210
*
211211
* @return void
212212
*/
213-
protected function addError($phpcsFile, $stackPtr, $function, $pattern=null)
213+
protected function addError($phpcsFile, $stackPtr, $functionName, $pattern=null)
214214
{
215-
$data = [$function];
215+
$data = [$functionName];
216216
$error = 'The use of function %s() is ';
217217
if ($this->error === true) {
218218
$type = 'Found';
@@ -223,7 +223,7 @@ protected function addError($phpcsFile, $stackPtr, $function, $pattern=null)
223223
}
224224

225225
if ($pattern === null) {
226-
$pattern = strtolower($function);
226+
$pattern = strtolower($functionName);
227227
}
228228

229229
if ($this->forbiddenFunctions[$pattern] !== null) {

src/Tokenizers/Comment.php

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,35 @@ class Comment
1919
/**
2020
* Splits a single doc block comment token up into something that can be easily iterated over.
2121
*
22-
* @param string $string The doc block comment string to parse.
22+
* @param string $comment The doc block comment string to parse.
2323
* @param string $eolChar The EOL character to use for splitting strings.
2424
* @param int $stackPtr The position of the token in the "new"/final token stream.
2525
*
2626
* @return array<int, array<string, string|int|array<int>>>
2727
*/
28-
public function tokenizeString($string, $eolChar, $stackPtr)
28+
public function tokenizeString($comment, $eolChar, $stackPtr)
2929
{
3030
if (PHP_CODESNIFFER_VERBOSITY > 1) {
3131
StatusWriter::write('*** START COMMENT TOKENIZING ***', 2);
3232
}
3333

3434
$tokens = [];
35-
$numChars = strlen($string);
35+
$numChars = strlen($comment);
3636

3737
/*
3838
Doc block comments start with /*, but typically contain an
3939
extra star when they are used for function and class comments.
4040
*/
4141

42-
$char = ($numChars - strlen(ltrim($string, '/*')));
43-
$lastChars = substr($string, -2);
42+
$char = ($numChars - strlen(ltrim($comment, '/*')));
43+
$lastChars = substr($comment, -2);
4444
if ($char === $numChars && $lastChars === '*/') {
4545
// Edge case: docblock without whitespace or contents.
46-
$openTag = substr($string, 0, -2);
47-
$string = $lastChars;
46+
$openTag = substr($comment, 0, -2);
47+
$comment = $lastChars;
4848
} else {
49-
$openTag = substr($string, 0, $char);
50-
$string = ltrim($string, '/*');
49+
$openTag = substr($comment, 0, $char);
50+
$comment = ltrim($comment, '/*');
5151
}
5252

5353
$tokens[$stackPtr] = [
@@ -73,7 +73,7 @@ public function tokenizeString($string, $eolChar, $stackPtr)
7373
*/
7474

7575
$closeTag = [
76-
'content' => substr($string, strlen(rtrim($string, '/*'))),
76+
'content' => substr($comment, strlen(rtrim($comment, '/*'))),
7777
'code' => T_DOC_COMMENT_CLOSE_TAG,
7878
'type' => 'T_DOC_COMMENT_CLOSE_TAG',
7979
'comment_opener' => $openPtr,
@@ -84,7 +84,7 @@ public function tokenizeString($string, $eolChar, $stackPtr)
8484
$closeTag['content'] = '';
8585
}
8686

87-
$string = rtrim($string, '/*');
87+
$string = rtrim($comment, '/*');
8888

8989
/*
9090
Process each line of the comment.
@@ -181,32 +181,32 @@ public function tokenizeString($string, $eolChar, $stackPtr)
181181
/**
182182
* Process a single line of a comment.
183183
*
184-
* @param string $string The comment string being tokenized.
184+
* @param string $comment The comment string being tokenized.
185185
* @param string $eolChar The EOL character to use for splitting strings.
186186
* @param int $start The position in the string to start processing.
187187
* @param int $end The position in the string to end processing.
188188
*
189189
* @return array<int, array<string, string|int>>
190190
*/
191-
private function processLine($string, $eolChar, $start, $end)
191+
private function processLine($comment, $eolChar, $start, $end)
192192
{
193193
$tokens = [];
194194

195195
// Collect content padding.
196-
$space = $this->collectWhitespace($string, $start, $end);
196+
$space = $this->collectWhitespace($comment, $start, $end);
197197
if ($space !== null) {
198198
$tokens[] = $space;
199199
$start += strlen($space['content']);
200200
}
201201

202-
if (isset($string[$start]) === false) {
202+
if (isset($comment[$start]) === false) {
203203
return $tokens;
204204
}
205205

206-
if ($string[$start] === '@') {
206+
if ($comment[$start] === '@') {
207207
// The content up until the first whitespace is the tag name.
208208
$matches = [];
209-
preg_match('/@[^\s]+/', $string, $matches, 0, $start);
209+
preg_match('/@[^\s]+/', $comment, $matches, 0, $start);
210210
if (isset($matches[0]) === true
211211
&& substr(strtolower($matches[0]), 0, 7) !== '@phpcs:'
212212
) {
@@ -219,7 +219,7 @@ private function processLine($string, $eolChar, $start, $end)
219219
];
220220

221221
// Then there will be some whitespace.
222-
$space = $this->collectWhitespace($string, $start, $end);
222+
$space = $this->collectWhitespace($comment, $start, $end);
223223
if ($space !== null) {
224224
$tokens[] = $space;
225225
$start += strlen($space['content']);
@@ -228,22 +228,22 @@ private function processLine($string, $eolChar, $start, $end)
228228
}//end if
229229

230230
// Process the rest of the line.
231-
$eol = strpos($string, $eolChar, $start);
231+
$eol = strpos($comment, $eolChar, $start);
232232
if ($eol === false) {
233233
$eol = $end;
234234
}
235235

236236
if ($eol > $start) {
237237
$tokens[] = [
238-
'content' => substr($string, $start, ($eol - $start)),
238+
'content' => substr($comment, $start, ($eol - $start)),
239239
'code' => T_DOC_COMMENT_STRING,
240240
'type' => 'T_DOC_COMMENT_STRING',
241241
];
242242
}
243243

244244
if ($eol !== $end) {
245245
$tokens[] = [
246-
'content' => substr($string, $eol, strlen($eolChar)),
246+
'content' => substr($comment, $eol, strlen($eolChar)),
247247
'code' => T_DOC_COMMENT_WHITESPACE,
248248
'type' => 'T_DOC_COMMENT_WHITESPACE',
249249
];
@@ -257,21 +257,21 @@ private function processLine($string, $eolChar, $start, $end)
257257
/**
258258
* Collect consecutive whitespace into a single token.
259259
*
260-
* @param string $string The comment string being tokenized.
261-
* @param int $start The position in the string to start processing.
262-
* @param int $end The position in the string to end processing.
260+
* @param string $comment The comment string being tokenized.
261+
* @param int $start The position in the string to start processing.
262+
* @param int $end The position in the string to end processing.
263263
*
264264
* @return array<string, string|int>|null
265265
*/
266-
private function collectWhitespace($string, $start, $end)
266+
private function collectWhitespace($comment, $start, $end)
267267
{
268268
$space = '';
269269
for ($start; $start < $end; $start++) {
270-
if ($string[$start] !== ' ' && $string[$start] !== "\t") {
270+
if ($comment[$start] !== ' ' && $comment[$start] !== "\t") {
271271
break;
272272
}
273273

274-
$space .= $string[$start];
274+
$space .= $comment[$start];
275275
}
276276

277277
if ($space === '') {

src/Tokenizers/PHP.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,11 +531,11 @@ class PHP extends Tokenizer
531531
* Starts by using token_get_all() but does a lot of extra processing
532532
* to insert information about the context of the token.
533533
*
534-
* @param string $string The string to tokenize.
534+
* @param string $code The code to tokenize.
535535
*
536536
* @return array
537537
*/
538-
protected function tokenize($string)
538+
protected function tokenize($code)
539539
{
540540
if (PHP_CODESNIFFER_VERBOSITY > 1) {
541541
StatusWriter::write('*** START PHP TOKENIZING ***', 1);
@@ -545,7 +545,7 @@ protected function tokenize($string)
545545
}
546546
}
547547

548-
$tokens = @token_get_all($string);
548+
$tokens = @token_get_all($code);
549549
$finalTokens = [];
550550

551551
$newStackPtr = 0;

src/Tokenizers/Tokenizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ public function getTokens()
170170
/**
171171
* Creates an array of tokens when given some content.
172172
*
173-
* @param string $string The string to tokenize.
173+
* @param string $code The code to tokenize.
174174
*
175175
* @return array
176176
*/
177-
abstract protected function tokenize($string);
177+
abstract protected function tokenize($code);
178178

179179

180180
/**

0 commit comments

Comments
 (0)