Skip to content

CS: clean up use statements #347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 !== '') {
Expand Down Expand Up @@ -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']);
}
Expand All @@ -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 !== '') {
Expand Down
4 changes: 3 additions & 1 deletion src/Exceptions/DeepExitException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

namespace PHP_CodeSniffer\Exceptions;

class DeepExitException extends \Exception
use Exception;

class DeepExitException extends Exception
{

}//end class
4 changes: 3 additions & 1 deletion src/Exceptions/RuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

namespace PHP_CodeSniffer\Exceptions;

class RuntimeException extends \RuntimeException
use RuntimeException as PHPRuntimeException;

class RuntimeException extends PHPRuntimeException
{

}//end class
4 changes: 3 additions & 1 deletion src/Exceptions/TokenizerException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

namespace PHP_CodeSniffer\Exceptions;

class TokenizerException extends \Exception
use Exception;

class TokenizerException extends Exception
{

}//end class
2 changes: 1 addition & 1 deletion src/Files/DummyFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

namespace PHP_CodeSniffer\Files;

use PHP_CodeSniffer\Ruleset;
use PHP_CodeSniffer\Config;
use PHP_CodeSniffer\Ruleset;

class DummyFile extends File
{
Expand Down
41 changes: 21 additions & 20 deletions src/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1885,7 +1886,7 @@ public function getMemberProperties($stackPtr)
T_READONLY => T_READONLY,
];

$valid += Util\Tokens::$emptyTokens;
$valid += Tokens::$emptyTokens;

$scope = 'public';
$scopeSpecified = false;
Expand Down Expand Up @@ -2073,7 +2074,7 @@ public function isReference($stackPtr)
}

$tokenBefore = $this->findPrevious(
Util\Tokens::$emptyTokens,
Tokens::$emptyTokens,
($stackPtr - 1),
null,
true
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'];
}

Expand All @@ -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
Expand Down
Loading