diff --git a/src/Config.php b/src/Config.php index 6f1dc2d5b6..e512d33fe6 100644 --- a/src/Config.php +++ b/src/Config.php @@ -12,9 +12,12 @@ namespace PHP_CodeSniffer; +use Exception; +use Phar; use PHP_CodeSniffer\Exceptions\DeepExitException; use PHP_CodeSniffer\Exceptions\RuntimeException; use PHP_CodeSniffer\Util\Common; +use PHP_CodeSniffer\Util\Standards; /** * Stores the configuration used to run PHPCS and PHPCBF. @@ -265,7 +268,7 @@ public function __set($name, $value) $cleaned = []; // Check if the standard name is valid, or if the case is invalid. - $installedStandards = Util\Standards::getInstalledStandards(); + $installedStandards = Standards::getInstalledStandards(); foreach ($value as $standard) { foreach ($installedStandards as $validStandard) { if (strtolower($standard) === strtolower($validStandard)) { @@ -420,7 +423,7 @@ public function __construct(array $cliArgs=[], $dieOnUnknownArg=true) // Check for content on STDIN. if ($this->stdin === true - || (Util\Common::isStdinATTY() === false + || (Common::isStdinATTY() === false && feof($handle) === false) ) { $readStreams = [$handle]; @@ -649,7 +652,7 @@ public function processShortArgument($arg, $pos) throw new DeepExitException($output, 0); case 'i' : ob_start(); - Util\Standards::printInstalledStandards(); + Standards::printInstalledStandards(); $output = ob_get_contents(); ob_end_clean(); throw new DeepExitException($output, 0); @@ -812,7 +815,7 @@ public function processLongArgument($arg, $pos) try { $this->setConfigData($key, $value); - } catch (\Exception $e) { + } catch (Exception $e) { throw new DeepExitException($e->getMessage().PHP_EOL, 3); } @@ -840,7 +843,7 @@ public function processLongArgument($arg, $pos) } else { try { $this->setConfigData($key, null); - } catch (\Exception $e) { + } catch (Exception $e) { throw new DeepExitException($e->getMessage().PHP_EOL, 3); } @@ -922,7 +925,7 @@ public function processLongArgument($arg, $pos) $this->cache = true; self::$overriddenDefaults['cache'] = true; - $this->cacheFile = Util\Common::realpath(substr($arg, 6)); + $this->cacheFile = Common::realpath(substr($arg, 6)); // It may not exist and return false instead. if ($this->cacheFile === false) { @@ -941,9 +944,9 @@ public function processLongArgument($arg, $pos) } else { if ($dir[0] === '/') { // An absolute path. - $dir = Util\Common::realpath($dir); + $dir = Common::realpath($dir); } else { - $dir = Util\Common::realpath(getcwd().'/'.$dir); + $dir = Common::realpath(getcwd().'/'.$dir); } if ($dir !== false) { @@ -964,7 +967,7 @@ public function processLongArgument($arg, $pos) $files = explode(',', substr($arg, 10)); $bootstrap = []; foreach ($files as $file) { - $path = Util\Common::realpath($file); + $path = Common::realpath($file); if ($path === false) { $error = 'ERROR: The specified bootstrap file "'.$file.'" does not exist'.PHP_EOL.PHP_EOL; $error .= $this->printShortUsage(true); @@ -978,7 +981,7 @@ public function processLongArgument($arg, $pos) self::$overriddenDefaults['bootstrap'] = true; } else if (substr($arg, 0, 10) === 'file-list=') { $fileList = substr($arg, 10); - $path = Util\Common::realpath($fileList); + $path = Common::realpath($fileList); if ($path === false) { $error = 'ERROR: The specified file list "'.$fileList.'" does not exist'.PHP_EOL.PHP_EOL; $error .= $this->printShortUsage(true); @@ -1001,7 +1004,7 @@ public function processLongArgument($arg, $pos) break; } - $this->stdinPath = Util\Common::realpath(substr($arg, 11)); + $this->stdinPath = Common::realpath(substr($arg, 11)); // It may not exist and return false instead, so use whatever they gave us. if ($this->stdinPath === false) { @@ -1014,13 +1017,13 @@ public function processLongArgument($arg, $pos) break; } - $this->reportFile = Util\Common::realpath(substr($arg, 12)); + $this->reportFile = Common::realpath(substr($arg, 12)); // It may not exist and return false instead. if ($this->reportFile === false) { $this->reportFile = substr($arg, 12); - $dir = Util\Common::realpath(dirname($this->reportFile)); + $dir = Common::realpath(dirname($this->reportFile)); if (is_dir($dir) === false) { $error = 'ERROR: The specified report file path "'.$this->reportFile.'" points to a non-existent directory'.PHP_EOL.PHP_EOL; $error .= $this->printShortUsage(true); @@ -1056,7 +1059,7 @@ public function processLongArgument($arg, $pos) break; } - $this->basepath = Util\Common::realpath(substr($arg, 9)); + $this->basepath = Common::realpath(substr($arg, 9)); // It may not exist and return false instead. if ($this->basepath === false) { @@ -1083,7 +1086,7 @@ public function processLongArgument($arg, $pos) if ($output === false) { $output = null; } else { - $dir = Util\Common::realpath(dirname($output)); + $dir = Common::realpath(dirname($output)); if (is_dir($dir) === false) { $error = 'ERROR: The specified '.$report.' report file path "'.$output.'" points to a non-existent directory'.PHP_EOL.PHP_EOL; $error .= $this->printShortUsage(true); @@ -1317,7 +1320,7 @@ public function processFilePath($path) return; } - $file = Util\Common::realpath($path); + $file = Common::realpath($path); if (file_exists($file) === false) { if ($this->dieOnUnknownArg === false) { return; @@ -1608,7 +1611,7 @@ public static function setConfigData($key, $value, $temp=false) if ($temp === false) { $path = ''; if (is_callable('\Phar::running') === true) { - $path = \Phar::running(false); + $path = Phar::running(false); } if ($path !== '') { @@ -1653,7 +1656,7 @@ public static function setConfigData($key, $value, $temp=false) // If the installed paths are being set, make sure all known // standards paths are added to the autoloader. if ($key === 'installed_paths') { - $installedStandards = Util\Standards::getInstalledStandardDetails(); + $installedStandards = Standards::getInstalledStandardDetails(); foreach ($installedStandards as $name => $details) { Autoload::addSearchPath($details['path'], $details['namespace']); } @@ -1679,7 +1682,7 @@ public static function getAllConfigData() $path = ''; if (is_callable('\Phar::running') === true) { - $path = \Phar::running(false); + $path = Phar::running(false); } if ($path !== '') { diff --git a/src/Exceptions/DeepExitException.php b/src/Exceptions/DeepExitException.php index 7732c6da48..6943e033ed 100644 --- a/src/Exceptions/DeepExitException.php +++ b/src/Exceptions/DeepExitException.php @@ -12,7 +12,9 @@ namespace PHP_CodeSniffer\Exceptions; -class DeepExitException extends \Exception +use Exception; + +class DeepExitException extends Exception { }//end class diff --git a/src/Exceptions/RuntimeException.php b/src/Exceptions/RuntimeException.php index a3d590984c..25eacd0b18 100644 --- a/src/Exceptions/RuntimeException.php +++ b/src/Exceptions/RuntimeException.php @@ -9,7 +9,9 @@ namespace PHP_CodeSniffer\Exceptions; -class RuntimeException extends \RuntimeException +use RuntimeException as PHPRuntimeException; + +class RuntimeException extends PHPRuntimeException { }//end class diff --git a/src/Exceptions/TokenizerException.php b/src/Exceptions/TokenizerException.php index ad25ace198..1cf53d6237 100644 --- a/src/Exceptions/TokenizerException.php +++ b/src/Exceptions/TokenizerException.php @@ -9,7 +9,9 @@ namespace PHP_CodeSniffer\Exceptions; -class TokenizerException extends \Exception +use Exception; + +class TokenizerException extends Exception { }//end class diff --git a/src/Files/DummyFile.php b/src/Files/DummyFile.php index eb947fd2a9..f5dc7cc7ac 100644 --- a/src/Files/DummyFile.php +++ b/src/Files/DummyFile.php @@ -14,8 +14,8 @@ namespace PHP_CodeSniffer\Files; -use PHP_CodeSniffer\Ruleset; use PHP_CodeSniffer\Config; +use PHP_CodeSniffer\Ruleset; class DummyFile extends File { diff --git a/src/Files/File.php b/src/Files/File.php index 7b54bea179..ab3cc290b8 100644 --- a/src/Files/File.php +++ b/src/Files/File.php @@ -9,12 +9,13 @@ namespace PHP_CodeSniffer\Files; -use PHP_CodeSniffer\Ruleset; use PHP_CodeSniffer\Config; -use PHP_CodeSniffer\Fixer; -use PHP_CodeSniffer\Util; use PHP_CodeSniffer\Exceptions\RuntimeException; use PHP_CodeSniffer\Exceptions\TokenizerException; +use PHP_CodeSniffer\Fixer; +use PHP_CodeSniffer\Ruleset; +use PHP_CodeSniffer\Util\Common; +use PHP_CodeSniffer\Util\Tokens; class File { @@ -276,7 +277,7 @@ public function setContent($content) $this->tokens = []; try { - $this->eolChar = Util\Common::detectLineEndings($content); + $this->eolChar = Common::detectLineEndings($content); } catch (RuntimeException $e) { $this->addWarningOnLine($e->getMessage(), 1, 'Internal.DetectLineEndings'); return; @@ -430,7 +431,7 @@ public function process() if (PHP_CODESNIFFER_VERBOSITY > 2) { $type = $token['type']; - $content = Util\Common::prepareForOutput($token['content']); + $content = Common::prepareForOutput($token['content']); echo "\t\tProcess token $stackPtr: $type => $content".PHP_EOL; } @@ -872,7 +873,7 @@ protected function addMessage($error, $message, $line, $column, $code, $data, $s $parts = explode('.', $code); if ($parts[0] === 'Internal') { // An internal message. - $listenerCode = Util\Common::getSniffCode($this->activeListener); + $listenerCode = Common::getSniffCode($this->activeListener); $sniffCode = $code; $checkCodes = [$sniffCode]; } else { @@ -881,7 +882,7 @@ protected function addMessage($error, $message, $line, $column, $code, $data, $s $sniffCode = $code; $listenerCode = substr($sniffCode, 0, strrpos($sniffCode, '.')); } else { - $listenerCode = Util\Common::getSniffCode($this->activeListener); + $listenerCode = Common::getSniffCode($this->activeListener); $sniffCode = $listenerCode.'.'.$code; $parts = explode('.', $sniffCode); } @@ -1615,7 +1616,7 @@ public function getMethodParameters($stackPtr) $paramCount++; break; case T_EQUAL: - $defaultStart = $this->findNext(Util\Tokens::$emptyTokens, ($i + 1), null, true); + $defaultStart = $this->findNext(Tokens::$emptyTokens, ($i + 1), null, true); $equalToken = $i; break; }//end switch @@ -1885,7 +1886,7 @@ public function getMemberProperties($stackPtr) T_READONLY => T_READONLY, ]; - $valid += Util\Tokens::$emptyTokens; + $valid += Tokens::$emptyTokens; $scope = 'public'; $scopeSpecified = false; @@ -2073,7 +2074,7 @@ public function isReference($stackPtr) } $tokenBefore = $this->findPrevious( - Util\Tokens::$emptyTokens, + Tokens::$emptyTokens, ($stackPtr - 1), null, true @@ -2097,14 +2098,14 @@ public function isReference($stackPtr) return true; } - if (isset(Util\Tokens::$assignmentTokens[$this->tokens[$tokenBefore]['code']]) === true) { + if (isset(Tokens::$assignmentTokens[$this->tokens[$tokenBefore]['code']]) === true) { // This is directly after an assignment. It's a reference. Even if // it is part of an operation, the other tests will handle it. return true; } $tokenAfter = $this->findNext( - Util\Tokens::$emptyTokens, + Tokens::$emptyTokens, ($stackPtr + 1), null, true @@ -2155,7 +2156,7 @@ public function isReference($stackPtr) if ($this->tokens[$tokenAfter]['code'] === T_VARIABLE) { return true; } else { - $skip = Util\Tokens::$emptyTokens; + $skip = Tokens::$emptyTokens; $skip[] = T_NS_SEPARATOR; $skip[] = T_SELF; $skip[] = T_PARENT; @@ -2382,7 +2383,7 @@ public function findNext( */ public function findStartOfStatement($start, $ignore=null) { - $startTokens = Util\Tokens::$blockOpeners; + $startTokens = Tokens::$blockOpeners; $startTokens[T_OPEN_SHORT_ARRAY] = true; $startTokens[T_OPEN_TAG] = true; $startTokens[T_OPEN_TAG_WITH_ECHO] = true; @@ -2436,7 +2437,7 @@ public function findStartOfStatement($start, $ignore=null) if ($prevMatch <= $this->tokens[$matchExpression]['scope_opener']) { // We're before the arrow in the first case. - $next = $this->findNext(Util\Tokens::$emptyTokens, ($this->tokens[$matchExpression]['scope_opener'] + 1), null, true); + $next = $this->findNext(Tokens::$emptyTokens, ($this->tokens[$matchExpression]['scope_opener'] + 1), null, true); if ($next === false) { return $start; } @@ -2449,12 +2450,12 @@ public function findStartOfStatement($start, $ignore=null) $prevMatchArrow = $this->findPrevious(T_MATCH_ARROW, ($prevMatch - 1), $this->tokens[$matchExpression]['scope_opener']); if ($prevMatchArrow === false) { // We're before the arrow in the first case. - $next = $this->findNext(Util\Tokens::$emptyTokens, ($this->tokens[$matchExpression]['scope_opener'] + 1), null, true); + $next = $this->findNext(Tokens::$emptyTokens, ($this->tokens[$matchExpression]['scope_opener'] + 1), null, true); return $next; } $end = $this->findEndOfStatement($prevMatchArrow); - $next = $this->findNext(Util\Tokens::$emptyTokens, ($end + 1), null, true); + $next = $this->findNext(Tokens::$emptyTokens, ($end + 1), null, true); return $next; } }//end if @@ -2515,7 +2516,7 @@ public function findStartOfStatement($start, $ignore=null) } }//end if - if (isset(Util\Tokens::$emptyTokens[$this->tokens[$i]['code']]) === false) { + if (isset(Tokens::$emptyTokens[$this->tokens[$i]['code']]) === false) { $lastNotEmpty = $i; } }//end for @@ -2610,7 +2611,7 @@ public function findEndOfStatement($start, $ignore=null) continue; } - if ($i === $start && isset(Util\Tokens::$scopeOpeners[$this->tokens[$i]['code']]) === true) { + if ($i === $start && isset(Tokens::$scopeOpeners[$this->tokens[$i]['code']]) === true) { return $this->tokens[$i]['scope_closer']; } @@ -2630,7 +2631,7 @@ public function findEndOfStatement($start, $ignore=null) } }//end if - if (isset(Util\Tokens::$emptyTokens[$this->tokens[$i]['code']]) === false) { + if (isset(Tokens::$emptyTokens[$this->tokens[$i]['code']]) === false) { $lastNotEmpty = $i; } }//end for diff --git a/src/Files/FileList.php b/src/Files/FileList.php index 13357ecdef..ab52e33888 100644 --- a/src/Files/FileList.php +++ b/src/Files/FileList.php @@ -11,14 +11,20 @@ namespace PHP_CodeSniffer\Files; +use Countable; +use FilesystemIterator; +use Iterator; use PHP_CodeSniffer\Autoload; -use PHP_CodeSniffer\Util; -use PHP_CodeSniffer\Ruleset; use PHP_CodeSniffer\Config; use PHP_CodeSniffer\Exceptions\DeepExitException; +use PHP_CodeSniffer\Ruleset; +use PHP_CodeSniffer\Util\Common; +use RecursiveArrayIterator; +use RecursiveDirectoryIterator; +use RecursiveIteratorIterator; use ReturnTypeWillChange; -class FileList implements \Iterator, \Countable +class FileList implements Iterator, Countable { /** @@ -72,7 +78,7 @@ public function __construct(Config $config, Ruleset $ruleset) $paths = $config->files; foreach ($paths as $path) { - $isPharFile = Util\Common::isPharFile($path); + $isPharFile = Common::isPharFile($path); if (is_dir($path) === true || $isPharFile === true) { if ($isPharFile === true) { $path = 'phar://'.$path; @@ -80,9 +86,9 @@ public function __construct(Config $config, Ruleset $ruleset) $filterClass = $this->getFilterClass(); - $di = new \RecursiveDirectoryIterator($path, (\RecursiveDirectoryIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS)); + $di = new RecursiveDirectoryIterator($path, (RecursiveDirectoryIterator::SKIP_DOTS | FilesystemIterator::FOLLOW_SYMLINKS)); $filter = new $filterClass($di, $path, $config, $ruleset); - $iterator = new \RecursiveIteratorIterator($filter); + $iterator = new RecursiveIteratorIterator($filter); foreach ($iterator as $file) { $this->files[$file->getPathname()] = null; @@ -121,9 +127,9 @@ public function addFile($path, $file=null) $filterClass = $this->getFilterClass(); - $di = new \RecursiveArrayIterator([$path]); + $di = new RecursiveArrayIterator([$path]); $filter = new $filterClass($di, $path, $this->config, $this->ruleset); - $iterator = new \RecursiveIteratorIterator($filter); + $iterator = new RecursiveIteratorIterator($filter); foreach ($iterator as $path) { $this->files[$path] = $file; diff --git a/src/Files/LocalFile.php b/src/Files/LocalFile.php index c2af77c42a..babfe69c31 100644 --- a/src/Files/LocalFile.php +++ b/src/Files/LocalFile.php @@ -9,8 +9,8 @@ namespace PHP_CodeSniffer\Files; -use PHP_CodeSniffer\Ruleset; use PHP_CodeSniffer\Config; +use PHP_CodeSniffer\Ruleset; use PHP_CodeSniffer\Util\Cache; use PHP_CodeSniffer\Util\Common; diff --git a/src/Filters/ExactMatch.php b/src/Filters/ExactMatch.php index c929fe8102..89517b8385 100644 --- a/src/Filters/ExactMatch.php +++ b/src/Filters/ExactMatch.php @@ -11,7 +11,7 @@ namespace PHP_CodeSniffer\Filters; -use PHP_CodeSniffer\Util; +use PHP_CodeSniffer\Util\Common; abstract class ExactMatch extends Filter { @@ -64,7 +64,7 @@ public function accept() } } - $filePath = Util\Common::realpath($this->current()); + $filePath = Common::realpath($this->current()); // If a file is both disallowed and allowed, the disallowed files list takes precedence. if (isset($this->disallowedFiles[$filePath]) === true) { diff --git a/src/Filters/Filter.php b/src/Filters/Filter.php index c72518c660..349fd6dbce 100644 --- a/src/Filters/Filter.php +++ b/src/Filters/Filter.php @@ -9,12 +9,15 @@ namespace PHP_CodeSniffer\Filters; -use PHP_CodeSniffer\Util; -use PHP_CodeSniffer\Ruleset; +use FilesystemIterator; use PHP_CodeSniffer\Config; +use PHP_CodeSniffer\Ruleset; +use PHP_CodeSniffer\Util\Common; +use RecursiveDirectoryIterator; +use RecursiveFilterIterator; use ReturnTypeWillChange; -class Filter extends \RecursiveFilterIterator +class Filter extends RecursiveFilterIterator { /** @@ -94,7 +97,7 @@ public function __construct($iterator, $basedir, Config $config, Ruleset $rulese public function accept() { $filePath = $this->current(); - $realPath = Util\Common::realpath($filePath); + $realPath = Common::realpath($filePath); if ($realPath !== false) { // It's a real path somewhere, so record it @@ -137,7 +140,7 @@ public function getChildren() { $filterClass = get_called_class(); $children = new $filterClass( - new \RecursiveDirectoryIterator($this->current(), (\RecursiveDirectoryIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS)), + new RecursiveDirectoryIterator($this->current(), (RecursiveDirectoryIterator::SKIP_DOTS | FilesystemIterator::FOLLOW_SYMLINKS)), $this->basedir, $this->config, $this->ruleset diff --git a/src/Filters/GitModified.php b/src/Filters/GitModified.php index dcd9752819..3337287b92 100644 --- a/src/Filters/GitModified.php +++ b/src/Filters/GitModified.php @@ -9,7 +9,7 @@ namespace PHP_CodeSniffer\Filters; -use PHP_CodeSniffer\Util; +use PHP_CodeSniffer\Util\Common; class GitModified extends ExactMatch { @@ -65,7 +65,7 @@ protected function getAllowedFiles() } foreach ($output as $path) { - $path = Util\Common::realpath($path); + $path = Common::realpath($path); if ($path === false) { continue; diff --git a/src/Filters/GitStaged.php b/src/Filters/GitStaged.php index 5e18359b09..7a764314aa 100644 --- a/src/Filters/GitStaged.php +++ b/src/Filters/GitStaged.php @@ -11,7 +11,7 @@ namespace PHP_CodeSniffer\Filters; -use PHP_CodeSniffer\Util; +use PHP_CodeSniffer\Util\Common; class GitStaged extends ExactMatch { @@ -67,7 +67,7 @@ protected function getAllowedFiles() } foreach ($output as $path) { - $path = Util\Common::realpath($path); + $path = Common::realpath($path); if ($path === false) { // Skip deleted files. continue; diff --git a/src/Fixer.php b/src/Fixer.php index b54dde94b6..e64f89ba6c 100644 --- a/src/Fixer.php +++ b/src/Fixer.php @@ -362,7 +362,7 @@ public function beginChangeset() if ($bt[1]['class'] === __CLASS__) { $sniff = 'Fixer'; } else { - $sniff = Util\Common::getSniffCode($bt[1]['class']); + $sniff = Common::getSniffCode($bt[1]['class']); } $line = $bt[0]['line']; @@ -447,7 +447,7 @@ public function rollbackChangeset() $line = $bt[0]['line']; } - $sniff = Util\Common::getSniffCode($sniff); + $sniff = Common::getSniffCode($sniff); $numChanges = count($this->changeset); @@ -504,7 +504,7 @@ public function replaceToken($stackPtr, $content) $line = $bt[0]['line']; } - $sniff = Util\Common::getSniffCode($sniff); + $sniff = Common::getSniffCode($sniff); $tokens = $this->currentFile->getTokens(); $type = $tokens[$stackPtr]['type']; @@ -619,7 +619,7 @@ public function revertToken($stackPtr) $line = $bt[0]['line']; } - $sniff = Util\Common::getSniffCode($sniff); + $sniff = Common::getSniffCode($sniff); $tokens = $this->currentFile->getTokens(); $type = $tokens[$stackPtr]['type']; diff --git a/src/Generators/Generator.php b/src/Generators/Generator.php index 483cae800f..af0e0f5c40 100644 --- a/src/Generators/Generator.php +++ b/src/Generators/Generator.php @@ -12,8 +12,10 @@ namespace PHP_CodeSniffer\Generators; -use PHP_CodeSniffer\Ruleset; +use DOMDocument; +use DOMNode; use PHP_CodeSniffer\Autoload; +use PHP_CodeSniffer\Ruleset; abstract class Generator { @@ -70,7 +72,7 @@ public function __construct(Ruleset $ruleset) * * @return string */ - protected function getTitle(\DOMNode $doc) + protected function getTitle(DOMNode $doc) { return $doc->getAttribute('title'); @@ -90,7 +92,7 @@ protected function getTitle(\DOMNode $doc) public function generate() { foreach ($this->docFiles as $file) { - $doc = new \DOMDocument(); + $doc = new DOMDocument(); $doc->load($file); $documentation = $doc->getElementsByTagName('documentation')->item(0); $this->processSniff($documentation); @@ -111,7 +113,7 @@ public function generate() * @return void * @see generate() */ - abstract protected function processSniff(\DOMNode $doc); + abstract protected function processSniff(DOMNode $doc); }//end class diff --git a/src/Generators/HTML.php b/src/Generators/HTML.php index 55acd9e172..a042f36be9 100644 --- a/src/Generators/HTML.php +++ b/src/Generators/HTML.php @@ -13,6 +13,8 @@ namespace PHP_CodeSniffer\Generators; +use DOMDocument; +use DOMNode; use PHP_CodeSniffer\Config; class HTML extends Generator @@ -32,7 +34,7 @@ public function generate() $this->printToc(); foreach ($this->docFiles as $file) { - $doc = new \DOMDocument(); + $doc = new DOMDocument(); $doc->load($file); $documentation = $doc->getElementsByTagName('documentation')->item(0); $this->processSniff($documentation); @@ -145,7 +147,7 @@ protected function printToc() echo '