Skip to content

Commit 68a8a34

Browse files
authored
Merge pull request #347 from PHPCSStandards/feature/cs-clean-up-use-statements
CS: clean up use statements
2 parents a788d54 + 8b83793 commit 68a8a34

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+306
-248
lines changed

src/Config.php

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212

1313
namespace PHP_CodeSniffer;
1414

15+
use Exception;
16+
use Phar;
1517
use PHP_CodeSniffer\Exceptions\DeepExitException;
1618
use PHP_CodeSniffer\Exceptions\RuntimeException;
1719
use PHP_CodeSniffer\Util\Common;
20+
use PHP_CodeSniffer\Util\Standards;
1821

1922
/**
2023
* Stores the configuration used to run PHPCS and PHPCBF.
@@ -265,7 +268,7 @@ public function __set($name, $value)
265268
$cleaned = [];
266269

267270
// Check if the standard name is valid, or if the case is invalid.
268-
$installedStandards = Util\Standards::getInstalledStandards();
271+
$installedStandards = Standards::getInstalledStandards();
269272
foreach ($value as $standard) {
270273
foreach ($installedStandards as $validStandard) {
271274
if (strtolower($standard) === strtolower($validStandard)) {
@@ -420,7 +423,7 @@ public function __construct(array $cliArgs=[], $dieOnUnknownArg=true)
420423

421424
// Check for content on STDIN.
422425
if ($this->stdin === true
423-
|| (Util\Common::isStdinATTY() === false
426+
|| (Common::isStdinATTY() === false
424427
&& feof($handle) === false)
425428
) {
426429
$readStreams = [$handle];
@@ -649,7 +652,7 @@ public function processShortArgument($arg, $pos)
649652
throw new DeepExitException($output, 0);
650653
case 'i' :
651654
ob_start();
652-
Util\Standards::printInstalledStandards();
655+
Standards::printInstalledStandards();
653656
$output = ob_get_contents();
654657
ob_end_clean();
655658
throw new DeepExitException($output, 0);
@@ -812,7 +815,7 @@ public function processLongArgument($arg, $pos)
812815

813816
try {
814817
$this->setConfigData($key, $value);
815-
} catch (\Exception $e) {
818+
} catch (Exception $e) {
816819
throw new DeepExitException($e->getMessage().PHP_EOL, 3);
817820
}
818821

@@ -840,7 +843,7 @@ public function processLongArgument($arg, $pos)
840843
} else {
841844
try {
842845
$this->setConfigData($key, null);
843-
} catch (\Exception $e) {
846+
} catch (Exception $e) {
844847
throw new DeepExitException($e->getMessage().PHP_EOL, 3);
845848
}
846849

@@ -922,7 +925,7 @@ public function processLongArgument($arg, $pos)
922925
$this->cache = true;
923926
self::$overriddenDefaults['cache'] = true;
924927

925-
$this->cacheFile = Util\Common::realpath(substr($arg, 6));
928+
$this->cacheFile = Common::realpath(substr($arg, 6));
926929

927930
// It may not exist and return false instead.
928931
if ($this->cacheFile === false) {
@@ -941,9 +944,9 @@ public function processLongArgument($arg, $pos)
941944
} else {
942945
if ($dir[0] === '/') {
943946
// An absolute path.
944-
$dir = Util\Common::realpath($dir);
947+
$dir = Common::realpath($dir);
945948
} else {
946-
$dir = Util\Common::realpath(getcwd().'/'.$dir);
949+
$dir = Common::realpath(getcwd().'/'.$dir);
947950
}
948951

949952
if ($dir !== false) {
@@ -964,7 +967,7 @@ public function processLongArgument($arg, $pos)
964967
$files = explode(',', substr($arg, 10));
965968
$bootstrap = [];
966969
foreach ($files as $file) {
967-
$path = Util\Common::realpath($file);
970+
$path = Common::realpath($file);
968971
if ($path === false) {
969972
$error = 'ERROR: The specified bootstrap file "'.$file.'" does not exist'.PHP_EOL.PHP_EOL;
970973
$error .= $this->printShortUsage(true);
@@ -978,7 +981,7 @@ public function processLongArgument($arg, $pos)
978981
self::$overriddenDefaults['bootstrap'] = true;
979982
} else if (substr($arg, 0, 10) === 'file-list=') {
980983
$fileList = substr($arg, 10);
981-
$path = Util\Common::realpath($fileList);
984+
$path = Common::realpath($fileList);
982985
if ($path === false) {
983986
$error = 'ERROR: The specified file list "'.$fileList.'" does not exist'.PHP_EOL.PHP_EOL;
984987
$error .= $this->printShortUsage(true);
@@ -1001,7 +1004,7 @@ public function processLongArgument($arg, $pos)
10011004
break;
10021005
}
10031006

1004-
$this->stdinPath = Util\Common::realpath(substr($arg, 11));
1007+
$this->stdinPath = Common::realpath(substr($arg, 11));
10051008

10061009
// It may not exist and return false instead, so use whatever they gave us.
10071010
if ($this->stdinPath === false) {
@@ -1014,13 +1017,13 @@ public function processLongArgument($arg, $pos)
10141017
break;
10151018
}
10161019

1017-
$this->reportFile = Util\Common::realpath(substr($arg, 12));
1020+
$this->reportFile = Common::realpath(substr($arg, 12));
10181021

10191022
// It may not exist and return false instead.
10201023
if ($this->reportFile === false) {
10211024
$this->reportFile = substr($arg, 12);
10221025

1023-
$dir = Util\Common::realpath(dirname($this->reportFile));
1026+
$dir = Common::realpath(dirname($this->reportFile));
10241027
if (is_dir($dir) === false) {
10251028
$error = 'ERROR: The specified report file path "'.$this->reportFile.'" points to a non-existent directory'.PHP_EOL.PHP_EOL;
10261029
$error .= $this->printShortUsage(true);
@@ -1056,7 +1059,7 @@ public function processLongArgument($arg, $pos)
10561059
break;
10571060
}
10581061

1059-
$this->basepath = Util\Common::realpath(substr($arg, 9));
1062+
$this->basepath = Common::realpath(substr($arg, 9));
10601063

10611064
// It may not exist and return false instead.
10621065
if ($this->basepath === false) {
@@ -1083,7 +1086,7 @@ public function processLongArgument($arg, $pos)
10831086
if ($output === false) {
10841087
$output = null;
10851088
} else {
1086-
$dir = Util\Common::realpath(dirname($output));
1089+
$dir = Common::realpath(dirname($output));
10871090
if (is_dir($dir) === false) {
10881091
$error = 'ERROR: The specified '.$report.' report file path "'.$output.'" points to a non-existent directory'.PHP_EOL.PHP_EOL;
10891092
$error .= $this->printShortUsage(true);
@@ -1317,7 +1320,7 @@ public function processFilePath($path)
13171320
return;
13181321
}
13191322

1320-
$file = Util\Common::realpath($path);
1323+
$file = Common::realpath($path);
13211324
if (file_exists($file) === false) {
13221325
if ($this->dieOnUnknownArg === false) {
13231326
return;
@@ -1608,7 +1611,7 @@ public static function setConfigData($key, $value, $temp=false)
16081611
if ($temp === false) {
16091612
$path = '';
16101613
if (is_callable('\Phar::running') === true) {
1611-
$path = \Phar::running(false);
1614+
$path = Phar::running(false);
16121615
}
16131616

16141617
if ($path !== '') {
@@ -1653,7 +1656,7 @@ public static function setConfigData($key, $value, $temp=false)
16531656
// If the installed paths are being set, make sure all known
16541657
// standards paths are added to the autoloader.
16551658
if ($key === 'installed_paths') {
1656-
$installedStandards = Util\Standards::getInstalledStandardDetails();
1659+
$installedStandards = Standards::getInstalledStandardDetails();
16571660
foreach ($installedStandards as $name => $details) {
16581661
Autoload::addSearchPath($details['path'], $details['namespace']);
16591662
}
@@ -1679,7 +1682,7 @@ public static function getAllConfigData()
16791682

16801683
$path = '';
16811684
if (is_callable('\Phar::running') === true) {
1682-
$path = \Phar::running(false);
1685+
$path = Phar::running(false);
16831686
}
16841687

16851688
if ($path !== '') {

src/Exceptions/DeepExitException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
namespace PHP_CodeSniffer\Exceptions;
1414

15-
class DeepExitException extends \Exception
15+
use Exception;
16+
17+
class DeepExitException extends Exception
1618
{
1719

1820
}//end class

src/Exceptions/RuntimeException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
namespace PHP_CodeSniffer\Exceptions;
1111

12-
class RuntimeException extends \RuntimeException
12+
use RuntimeException as PHPRuntimeException;
13+
14+
class RuntimeException extends PHPRuntimeException
1315
{
1416

1517
}//end class

src/Exceptions/TokenizerException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
namespace PHP_CodeSniffer\Exceptions;
1111

12-
class TokenizerException extends \Exception
12+
use Exception;
13+
14+
class TokenizerException extends Exception
1315
{
1416

1517
}//end class

src/Files/DummyFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
namespace PHP_CodeSniffer\Files;
1616

17-
use PHP_CodeSniffer\Ruleset;
1817
use PHP_CodeSniffer\Config;
18+
use PHP_CodeSniffer\Ruleset;
1919

2020
class DummyFile extends File
2121
{

src/Files/File.php

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99

1010
namespace PHP_CodeSniffer\Files;
1111

12-
use PHP_CodeSniffer\Ruleset;
1312
use PHP_CodeSniffer\Config;
14-
use PHP_CodeSniffer\Fixer;
15-
use PHP_CodeSniffer\Util;
1613
use PHP_CodeSniffer\Exceptions\RuntimeException;
1714
use PHP_CodeSniffer\Exceptions\TokenizerException;
15+
use PHP_CodeSniffer\Fixer;
16+
use PHP_CodeSniffer\Ruleset;
17+
use PHP_CodeSniffer\Util\Common;
18+
use PHP_CodeSniffer\Util\Tokens;
1819

1920
class File
2021
{
@@ -276,7 +277,7 @@ public function setContent($content)
276277
$this->tokens = [];
277278

278279
try {
279-
$this->eolChar = Util\Common::detectLineEndings($content);
280+
$this->eolChar = Common::detectLineEndings($content);
280281
} catch (RuntimeException $e) {
281282
$this->addWarningOnLine($e->getMessage(), 1, 'Internal.DetectLineEndings');
282283
return;
@@ -430,7 +431,7 @@ public function process()
430431

431432
if (PHP_CODESNIFFER_VERBOSITY > 2) {
432433
$type = $token['type'];
433-
$content = Util\Common::prepareForOutput($token['content']);
434+
$content = Common::prepareForOutput($token['content']);
434435
echo "\t\tProcess token $stackPtr: $type => $content".PHP_EOL;
435436
}
436437

@@ -872,7 +873,7 @@ protected function addMessage($error, $message, $line, $column, $code, $data, $s
872873
$parts = explode('.', $code);
873874
if ($parts[0] === 'Internal') {
874875
// An internal message.
875-
$listenerCode = Util\Common::getSniffCode($this->activeListener);
876+
$listenerCode = Common::getSniffCode($this->activeListener);
876877
$sniffCode = $code;
877878
$checkCodes = [$sniffCode];
878879
} else {
@@ -881,7 +882,7 @@ protected function addMessage($error, $message, $line, $column, $code, $data, $s
881882
$sniffCode = $code;
882883
$listenerCode = substr($sniffCode, 0, strrpos($sniffCode, '.'));
883884
} else {
884-
$listenerCode = Util\Common::getSniffCode($this->activeListener);
885+
$listenerCode = Common::getSniffCode($this->activeListener);
885886
$sniffCode = $listenerCode.'.'.$code;
886887
$parts = explode('.', $sniffCode);
887888
}
@@ -1615,7 +1616,7 @@ public function getMethodParameters($stackPtr)
16151616
$paramCount++;
16161617
break;
16171618
case T_EQUAL:
1618-
$defaultStart = $this->findNext(Util\Tokens::$emptyTokens, ($i + 1), null, true);
1619+
$defaultStart = $this->findNext(Tokens::$emptyTokens, ($i + 1), null, true);
16191620
$equalToken = $i;
16201621
break;
16211622
}//end switch
@@ -1885,7 +1886,7 @@ public function getMemberProperties($stackPtr)
18851886
T_READONLY => T_READONLY,
18861887
];
18871888

1888-
$valid += Util\Tokens::$emptyTokens;
1889+
$valid += Tokens::$emptyTokens;
18891890

18901891
$scope = 'public';
18911892
$scopeSpecified = false;
@@ -2073,7 +2074,7 @@ public function isReference($stackPtr)
20732074
}
20742075

20752076
$tokenBefore = $this->findPrevious(
2076-
Util\Tokens::$emptyTokens,
2077+
Tokens::$emptyTokens,
20772078
($stackPtr - 1),
20782079
null,
20792080
true
@@ -2097,14 +2098,14 @@ public function isReference($stackPtr)
20972098
return true;
20982099
}
20992100

2100-
if (isset(Util\Tokens::$assignmentTokens[$this->tokens[$tokenBefore]['code']]) === true) {
2101+
if (isset(Tokens::$assignmentTokens[$this->tokens[$tokenBefore]['code']]) === true) {
21012102
// This is directly after an assignment. It's a reference. Even if
21022103
// it is part of an operation, the other tests will handle it.
21032104
return true;
21042105
}
21052106

21062107
$tokenAfter = $this->findNext(
2107-
Util\Tokens::$emptyTokens,
2108+
Tokens::$emptyTokens,
21082109
($stackPtr + 1),
21092110
null,
21102111
true
@@ -2155,7 +2156,7 @@ public function isReference($stackPtr)
21552156
if ($this->tokens[$tokenAfter]['code'] === T_VARIABLE) {
21562157
return true;
21572158
} else {
2158-
$skip = Util\Tokens::$emptyTokens;
2159+
$skip = Tokens::$emptyTokens;
21592160
$skip[] = T_NS_SEPARATOR;
21602161
$skip[] = T_SELF;
21612162
$skip[] = T_PARENT;
@@ -2382,7 +2383,7 @@ public function findNext(
23822383
*/
23832384
public function findStartOfStatement($start, $ignore=null)
23842385
{
2385-
$startTokens = Util\Tokens::$blockOpeners;
2386+
$startTokens = Tokens::$blockOpeners;
23862387
$startTokens[T_OPEN_SHORT_ARRAY] = true;
23872388
$startTokens[T_OPEN_TAG] = true;
23882389
$startTokens[T_OPEN_TAG_WITH_ECHO] = true;
@@ -2436,7 +2437,7 @@ public function findStartOfStatement($start, $ignore=null)
24362437

24372438
if ($prevMatch <= $this->tokens[$matchExpression]['scope_opener']) {
24382439
// We're before the arrow in the first case.
2439-
$next = $this->findNext(Util\Tokens::$emptyTokens, ($this->tokens[$matchExpression]['scope_opener'] + 1), null, true);
2440+
$next = $this->findNext(Tokens::$emptyTokens, ($this->tokens[$matchExpression]['scope_opener'] + 1), null, true);
24402441
if ($next === false) {
24412442
return $start;
24422443
}
@@ -2449,12 +2450,12 @@ public function findStartOfStatement($start, $ignore=null)
24492450
$prevMatchArrow = $this->findPrevious(T_MATCH_ARROW, ($prevMatch - 1), $this->tokens[$matchExpression]['scope_opener']);
24502451
if ($prevMatchArrow === false) {
24512452
// We're before the arrow in the first case.
2452-
$next = $this->findNext(Util\Tokens::$emptyTokens, ($this->tokens[$matchExpression]['scope_opener'] + 1), null, true);
2453+
$next = $this->findNext(Tokens::$emptyTokens, ($this->tokens[$matchExpression]['scope_opener'] + 1), null, true);
24532454
return $next;
24542455
}
24552456

24562457
$end = $this->findEndOfStatement($prevMatchArrow);
2457-
$next = $this->findNext(Util\Tokens::$emptyTokens, ($end + 1), null, true);
2458+
$next = $this->findNext(Tokens::$emptyTokens, ($end + 1), null, true);
24582459
return $next;
24592460
}
24602461
}//end if
@@ -2515,7 +2516,7 @@ public function findStartOfStatement($start, $ignore=null)
25152516
}
25162517
}//end if
25172518

2518-
if (isset(Util\Tokens::$emptyTokens[$this->tokens[$i]['code']]) === false) {
2519+
if (isset(Tokens::$emptyTokens[$this->tokens[$i]['code']]) === false) {
25192520
$lastNotEmpty = $i;
25202521
}
25212522
}//end for
@@ -2610,7 +2611,7 @@ public function findEndOfStatement($start, $ignore=null)
26102611
continue;
26112612
}
26122613

2613-
if ($i === $start && isset(Util\Tokens::$scopeOpeners[$this->tokens[$i]['code']]) === true) {
2614+
if ($i === $start && isset(Tokens::$scopeOpeners[$this->tokens[$i]['code']]) === true) {
26142615
return $this->tokens[$i]['scope_closer'];
26152616
}
26162617

@@ -2630,7 +2631,7 @@ public function findEndOfStatement($start, $ignore=null)
26302631
}
26312632
}//end if
26322633

2633-
if (isset(Util\Tokens::$emptyTokens[$this->tokens[$i]['code']]) === false) {
2634+
if (isset(Tokens::$emptyTokens[$this->tokens[$i]['code']]) === false) {
26342635
$lastNotEmpty = $i;
26352636
}
26362637
}//end for

0 commit comments

Comments
 (0)