Skip to content

Commit 7538167

Browse files
committed
QA: use FQN when using global functions and constants
1 parent d2f355b commit 7538167

File tree

6 files changed

+95
-95
lines changed

6 files changed

+95
-95
lines changed

PHPCSDebug/Sniffs/Debug/TokenListSniff.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ public function process(File $phpcsFile, $stackPtr)
7979
$tokens = $phpcsFile->getTokens();
8080
$last = ($phpcsFile->numTokens - 1);
8181

82-
$ptrPadding = max(3, strlen($last));
83-
$linePadding = strlen($tokens[$last]['line']);
82+
$ptrPadding = \max(3, \strlen($last));
83+
$linePadding = \strlen($tokens[$last]['line']);
8484

8585
echo \PHP_EOL;
8686
echo \str_pad('Ptr', $ptrPadding, ' ', \STR_PAD_BOTH),
@@ -99,23 +99,23 @@ public function process(File $phpcsFile, $stackPtr)
9999
if (isset($token['length']) === false) {
100100
$token['length'] = 0;
101101
if (isset($token['content'])) {
102-
$token['length'] = strlen($content);
102+
$token['length'] = \strlen($content);
103103
}
104104
}
105105

106106
if ($token['code'] === \T_WHITESPACE
107-
|| (defined('T_DOC_COMMENT_WHITESPACE')
107+
|| (\defined('T_DOC_COMMENT_WHITESPACE')
108108
&& $token['code'] === \T_DOC_COMMENT_WHITESPACE)
109109
) {
110-
if (strpos($content, "\t") !== false) {
111-
$content = str_replace("\t", '\t', $content);
110+
if (\strpos($content, "\t") !== false) {
111+
$content = \str_replace("\t", '\t', $content);
112112
}
113113
if (isset($token['orig_content'])) {
114-
$content .= ' :: Orig: ' . str_replace("\t", '\t', $token['orig_content']);
114+
$content .= ' :: Orig: ' . \str_replace("\t", '\t', $token['orig_content']);
115115
}
116116
}
117117

118-
$conditionCount = count($token['conditions']);
118+
$conditionCount = \count($token['conditions']);
119119

120120
echo \str_pad($ptr, $ptrPadding, ' ', \STR_PAD_LEFT),
121121
' :: L', \str_pad($token['line'], $linePadding, '0', \STR_PAD_LEFT),

PHPCSDebug/Tests/Debug/TokenListUnitTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected function setUp()
3838
{
3939
parent::setUp();
4040

41-
ob_start();
41+
\ob_start();
4242
}
4343

4444
/**
@@ -48,7 +48,7 @@ protected function setUp()
4848
*/
4949
protected function tearDown()
5050
{
51-
self::$output = ob_get_flush();
51+
self::$output = \ob_get_flush();
5252

5353
parent::tearDown();
5454
}

PHPCSDebug/Tests/Debug/TokenListZUnitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class TokenListZUnitTest extends TestCase
2929
*/
3030
public function testOutput()
3131
{
32-
$output = str_replace(["\r\n", "\r"], "\n", TokenListUnitTest::$output);
32+
$output = \str_replace(["\r\n", "\r"], "\n", TokenListUnitTest::$output);
3333

3434
$this->assertNotEmpty($output);
3535

Scripts/CheckSniffCompleteness.php

Lines changed: 74 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -156,25 +156,25 @@ public function __construct()
156156
$this->targetDirs[] = $this->projectRoot;
157157
} else {
158158
// Handle Windows vs Unix file paths.
159-
$sep = DIRECTORY_SEPARATOR;
159+
$sep = \DIRECTORY_SEPARATOR;
160160
}
161161

162162
// Handle excluded dirs.
163163
$exclude = '(?!\.git/)';
164164
if (empty($this->excludedDirs) === false) {
165-
$excludedDirs = array_map(
165+
$excludedDirs = \array_map(
166166
'preg_quote',
167167
$this->excludedDirs,
168-
array_fill(0, count($this->excludedDirs), '`')
168+
\array_fill(0, \count($this->excludedDirs), '`')
169169
);
170-
$exclude = '(?!(\.git|' . implode('|', $excludedDirs) . ')/)';
170+
$exclude = '(?!(\.git|' . \implode('|', $excludedDirs) . ')/)';
171171
}
172172

173173
// Prepare the regexes.
174-
$quotedProjectRoot = preg_quote($this->projectRoot . $sep, '`');
175-
$allFilesRegex = str_replace('(?!\.git/)', $exclude, FileList::BASE_REGEX);
176-
$allFilesRegex = sprintf($allFilesRegex, $quotedProjectRoot);
177-
$sniffsRegex = sprintf(self::FILTER_REGEX, $quotedProjectRoot, $exclude);
174+
$quotedProjectRoot = \preg_quote($this->projectRoot . $sep, '`');
175+
$allFilesRegex = \str_replace('(?!\.git/)', $exclude, FileList::BASE_REGEX);
176+
$allFilesRegex = \sprintf($allFilesRegex, $quotedProjectRoot);
177+
$sniffsRegex = \sprintf(self::FILTER_REGEX, $quotedProjectRoot, $exclude);
178178

179179
// Get the file lists.
180180
$allFiles = [];
@@ -187,12 +187,12 @@ public function __construct()
187187
$allSniffs[] = (new FileList($targetDir, $this->projectRoot, $sniffsRegex))->getList();
188188
}
189189

190-
$allFiles = call_user_func_array('array_merge', $allFiles);
191-
sort($allFiles, SORT_NATURAL);
192-
$this->allFiles = array_flip($allFiles);
190+
$allFiles = \call_user_func_array('array_merge', $allFiles);
191+
\sort($allFiles, \SORT_NATURAL);
192+
$this->allFiles = \array_flip($allFiles);
193193

194-
$allSniffs = call_user_func_array('array_merge', $allSniffs);
195-
sort($allSniffs, SORT_NATURAL);
194+
$allSniffs = \call_user_func_array('array_merge', $allSniffs);
195+
\sort($allSniffs, \SORT_NATURAL);
196196
$this->allSniffs = $allSniffs;
197197
}
198198

@@ -206,9 +206,9 @@ protected function processCliCommand()
206206
$args = $_SERVER['argv'];
207207

208208
// Remove the call to the script itself.
209-
array_shift($args);
209+
\array_shift($args);
210210

211-
$this->projectRoot = getcwd();
211+
$this->projectRoot = \getcwd();
212212

213213
if (empty($args)) {
214214
// No options set.
@@ -217,7 +217,7 @@ protected function processCliCommand()
217217
return;
218218
}
219219

220-
$argsFlipped = array_flip($args);
220+
$argsFlipped = \array_flip($args);
221221

222222
if (isset($argsFlipped['-h'])
223223
|| isset($argsFlipped['--help'])
@@ -256,17 +256,17 @@ protected function processCliCommand()
256256
}
257257

258258
foreach ($args as $arg) {
259-
if (strpos($arg, '--exclude=') === 0) {
260-
$exclude = substr($arg, 10);
259+
if (\strpos($arg, '--exclude=') === 0) {
260+
$exclude = \substr($arg, 10);
261261
if ($exclude === '') {
262262
$this->excludedDirs = [];
263263
continue;
264264
}
265265

266-
$exclude = explode(',', $exclude);
267-
$exclude = array_map(
266+
$exclude = \explode(',', $exclude);
267+
$exclude = \array_map(
268268
function ($subdir) {
269-
return trim($subdir, '/');
269+
return \trim($subdir, '/');
270270
},
271271
$exclude
272272
);
@@ -277,7 +277,7 @@ function ($subdir) {
277277

278278
if ($arg[0] !== '-') {
279279
// The user must have set a path to search.
280-
$realpath = realpath($arg);
280+
$realpath = \realpath($arg);
281281

282282
if ($realpath !== false) {
283283
$this->targetDirs[] = $realpath;
@@ -296,9 +296,9 @@ public function validate()
296296
$this->showVersion();
297297

298298
if ($this->verbose > 0) {
299-
echo 'Target dir(s):', PHP_EOL,
300-
'- ' . implode(PHP_EOL . '- ', $this->targetDirs),
301-
PHP_EOL, PHP_EOL;
299+
echo 'Target dir(s):', \PHP_EOL,
300+
'- ' . \implode(\PHP_EOL . '- ', $this->targetDirs),
301+
\PHP_EOL, \PHP_EOL;
302302
}
303303

304304
if ($this->isComplete() !== true) {
@@ -315,9 +315,9 @@ public function validate()
315315
*/
316316
public function isComplete()
317317
{
318-
$sniffCount = count($this->allSniffs);
318+
$sniffCount = \count($this->allSniffs);
319319
if ($sniffCount === 0) {
320-
echo 'No sniffs found.', PHP_EOL;
320+
echo 'No sniffs found.', \PHP_EOL;
321321
return true;
322322
}
323323

@@ -326,39 +326,39 @@ public function isComplete()
326326
$testCaseError = 'ERROR: Unit test case file missing for %s.';
327327

328328
if ($this->showColored === true) {
329-
$docWarning = str_replace('WARNING', "\033[33mWARNING\033[0m", $docWarning);
330-
$testError = str_replace('ERROR', "\033[31mERROR\033[0m", $testError);
331-
$testCaseError = str_replace('ERROR', "\033[31mERROR\033[0m", $testError);
329+
$docWarning = \str_replace('WARNING', "\033[33mWARNING\033[0m", $docWarning);
330+
$testError = \str_replace('ERROR', "\033[31mERROR\033[0m", $testError);
331+
$testCaseError = \str_replace('ERROR', "\033[31mERROR\033[0m", $testError);
332332
}
333333

334334
$notices = [];
335335
$warningCount = 0;
336336
$errorCount = 0;
337337
foreach ($this->allSniffs as $i => $file) {
338338
if ($this->quietMode === false) {
339-
$docFile = str_replace(array_keys($this->sniffToDoc), $this->sniffToDoc, $file);
339+
$docFile = \str_replace(\array_keys($this->sniffToDoc), $this->sniffToDoc, $file);
340340
if (isset($this->allFiles[$docFile]) === false) {
341-
$notices[] = sprintf($docWarning, $file);
341+
$notices[] = \sprintf($docWarning, $file);
342342
++$warningCount;
343343
}
344344
}
345345

346-
$testFile = str_replace(array_keys($this->sniffToUnitTest), $this->sniffToUnitTest, $file);
346+
$testFile = \str_replace(\array_keys($this->sniffToUnitTest), $this->sniffToUnitTest, $file);
347347
if (isset($this->allFiles[$testFile]) === false) {
348-
$notices[] = sprintf($testError, $file);
348+
$notices[] = \sprintf($testError, $file);
349349
++$errorCount;
350350
} else {
351351
$fileFound = false;
352352
foreach ($this->testCaseExtensions as $extension) {
353-
$testCaseFile = str_replace('.php', $extension, $testFile);
353+
$testCaseFile = \str_replace('.php', $extension, $testFile);
354354
if (isset($this->allFiles[$testCaseFile]) === true) {
355355
$fileFound = true;
356356
break;
357357
}
358358
}
359359

360360
if ($fileFound === false) {
361-
$notices[] = sprintf($testCaseError, $file);
361+
$notices[] = \sprintf($testCaseError, $file);
362362
++$errorCount;
363363
}
364364
}
@@ -369,18 +369,18 @@ public function isComplete()
369369

370370
$current = ($i + 1);
371371
if (($current % 60) === 0 || $current === $sniffCount) {
372-
$padding = strlen($sniffCount);
372+
$padding = \strlen($sniffCount);
373373

374374
$filling = '';
375375
if ($current === $sniffCount) {
376-
$lines = ceil($current / 60);
376+
$lines = \ceil($current / 60);
377377
if ($lines > 1) {
378-
$filling = str_repeat(' ', (($lines * 60) - $sniffCount));
378+
$filling = \str_repeat(' ', (($lines * 60) - $sniffCount));
379379
}
380380
}
381381

382-
echo $filling, ' ', str_pad($current, $padding, ' ', \STR_PAD_LEFT), ' / ', $sniffCount,
383-
' (', str_pad(round(($current / $sniffCount) * 100), 3, ' ', \STR_PAD_LEFT), '%)', PHP_EOL;
382+
echo $filling, ' ', \str_pad($current, $padding, ' ', \STR_PAD_LEFT), ' / ', $sniffCount,
383+
' (', \str_pad(\round(($current / $sniffCount) * 100), 3, ' ', \STR_PAD_LEFT), '%)', \PHP_EOL;
384384
}
385385
}
386386
}
@@ -390,11 +390,11 @@ public function isComplete()
390390
*/
391391
if (empty($notices) === false) {
392392
// Show the errors and warnings.
393-
echo PHP_EOL,
394-
implode(PHP_EOL, $notices), PHP_EOL,
395-
PHP_EOL,
396-
'-----------------------------------------', PHP_EOL,
397-
sprintf('Found %d errors and %d warnings', $errorCount, $warningCount), PHP_EOL;
393+
echo \PHP_EOL,
394+
\implode(\PHP_EOL, $notices), \PHP_EOL,
395+
\PHP_EOL,
396+
'-----------------------------------------', \PHP_EOL,
397+
\sprintf('Found %d errors and %d warnings', $errorCount, $warningCount), \PHP_EOL;
398398

399399
return false;
400400
} else {
@@ -413,7 +413,7 @@ public function isComplete()
413413
$feedback = "\033[32m" . $feedback . "\033[0m";
414414
}
415415

416-
echo PHP_EOL, PHP_EOL, $feedback, PHP_EOL;
416+
echo \PHP_EOL, \PHP_EOL, $feedback, \PHP_EOL;
417417

418418
return true;
419419
}
@@ -427,22 +427,22 @@ public function isComplete()
427427
protected function isColorSupported()
428428
{
429429
// Windows.
430-
if (DIRECTORY_SEPARATOR === '\\') {
431-
if (getenv('ANSICON') !== false || getenv('ConEmuANSI') === 'ON') {
430+
if (\DIRECTORY_SEPARATOR === '\\') {
431+
if (\getenv('ANSICON') !== false || \getenv('ConEmuANSI') === 'ON') {
432432
return true;
433433
}
434434

435-
if (function_exists('sapi_windows_vt100_support')) {
435+
if (\function_exists('sapi_windows_vt100_support')) {
436436
// phpcs:ignore PHPCompatibility.FunctionUse.NewFunctions.sapi_windows_vt100_supportFound
437-
return @sapi_windows_vt100_support(STDOUT);
437+
return @\sapi_windows_vt100_support(\STDOUT);
438438
}
439439

440440
return false;
441441
}
442442

443443
// Linux/MacOS.
444-
if (function_exists('posix_isatty')) {
445-
return @posix_isatty(STDOUT);
444+
if (\function_exists('posix_isatty')) {
445+
return @\posix_isatty(\STDOUT);
446446
}
447447

448448
return false;
@@ -457,8 +457,8 @@ protected function showVersion()
457457
{
458458
echo 'PHPCSDevTools: Sniff feature completeness checker version ';
459459
include __DIR__ . '/../VERSION';
460-
echo PHP_EOL,
461-
'by Juliette Reinders Folmer', PHP_EOL, PHP_EOL;
460+
echo \PHP_EOL,
461+
'by Juliette Reinders Folmer', \PHP_EOL, \PHP_EOL;
462462
}
463463

464464
/**
@@ -470,24 +470,24 @@ protected function showHelp()
470470
{
471471
$this->showVersion();
472472

473-
echo 'Usage:', PHP_EOL,
474-
' phpcs-check-feature-completeness', PHP_EOL,
475-
' phpcs-check-feature-completeness [-q] [--exclude=<dir>] [directories]', PHP_EOL;
476-
477-
echo PHP_EOL,
478-
'Options:', PHP_EOL,
479-
' directories One or more specific directories to examine.', PHP_EOL,
480-
' Defaults to the directory from which the script is run.', PHP_EOL,
481-
' -q, --quiet Turn off warnings for missing documentation.', PHP_EOL,
482-
' --exclude Comma-delimited list of (relative) directories to exclude', PHP_EOL,
483-
' from the scan.', PHP_EOL,
484-
' Defaults to excluding the /vendor/ directory.', PHP_EOL,
485-
' --no-progress Disable progress in console output.', PHP_EOL,
486-
' --colors Enable colors in console output.', PHP_EOL,
487-
' (disables auto detection of color support)', PHP_EOL,
488-
' --no-colors Disable colors in console output.', PHP_EOL,
489-
' -v Verbose mode.', PHP_EOL,
490-
' -h, --help Print this help.', PHP_EOL,
491-
' -V, --version Display the current version of this script.', PHP_EOL;
473+
echo 'Usage:', \PHP_EOL,
474+
' phpcs-check-feature-completeness', \PHP_EOL,
475+
' phpcs-check-feature-completeness [-q] [--exclude=<dir>] [directories]', \PHP_EOL;
476+
477+
echo \PHP_EOL,
478+
'Options:', \PHP_EOL,
479+
' directories One or more specific directories to examine.', \PHP_EOL,
480+
' Defaults to the directory from which the script is run.', \PHP_EOL,
481+
' -q, --quiet Turn off warnings for missing documentation.', \PHP_EOL,
482+
' --exclude Comma-delimited list of (relative) directories to exclude', \PHP_EOL,
483+
' from the scan.', \PHP_EOL,
484+
' Defaults to excluding the /vendor/ directory.', \PHP_EOL,
485+
' --no-progress Disable progress in console output.', \PHP_EOL,
486+
' --colors Enable colors in console output.', \PHP_EOL,
487+
' (disables auto detection of color support)', \PHP_EOL,
488+
' --no-colors Disable colors in console output.', \PHP_EOL,
489+
' -v Verbose mode.', \PHP_EOL,
490+
' -h, --help Print this help.', \PHP_EOL,
491+
' -V, --version Display the current version of this script.', \PHP_EOL;
492492
}
493493
}

Scripts/FileList.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function __construct($directory, $rootPath = '', $filter = '')
7474
);
7575

7676
if ($filter === '') {
77-
$filter = sprintf(self::BASE_REGEX, preg_quote($this->rootPath . DIRECTORY_SEPARATOR, '`'));
77+
$filter = \sprintf(self::BASE_REGEX, \preg_quote($this->rootPath . \DIRECTORY_SEPARATOR, '`'));
7878
}
7979

8080
$this->fileIterator = new RegexIterator($flattened, $filter);
@@ -102,7 +102,7 @@ public function getList()
102102
$fileList = [];
103103

104104
foreach ($this->fileIterator as $file) {
105-
$fileList[] = str_replace($this->rootPath, '', $file);
105+
$fileList[] = \str_replace($this->rootPath, '', $file);
106106
}
107107

108108
return $fileList;

0 commit comments

Comments
 (0)