Skip to content
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
32 changes: 16 additions & 16 deletions autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,19 @@ class Autoload
* This method only loads classes that exist in the PHP_CodeSniffer namespace.
* All other classes are ignored and loaded by subsequent autoloaders.
*
* @param string $class The name of the class to load.
* @param string $className The name of the class to load.
*
* @return bool
*/
public static function load($class)
public static function load($className)
{
// Include the composer autoloader if there is one, but re-register it
// so this autoloader runs before the composer one as we need to include
// all files so we can figure out what the class/interface/trait name is.
if (self::$composerAutoloader === null) {
// Make sure we don't try to load any of Composer's classes
// while the autoloader is being setup.
if (strpos($class, 'Composer\\') === 0) {
if (strpos($className, 'Composer\\') === 0) {
return false;
}

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

if (substr($class, 0, 16) === 'PHP_CodeSniffer\\') {
if (substr($class, 0, 22) === 'PHP_CodeSniffer\Tests\\') {
if (substr($className, 0, 16) === 'PHP_CodeSniffer\\') {
if (substr($className, 0, 22) === 'PHP_CodeSniffer\Tests\\') {
$isInstalled = !is_dir(__DIR__.$ds.'tests');
if ($isInstalled === false) {
$path = __DIR__.$ds.'tests';
} else {
$path = '@test_dir@'.$ds.'PHP_CodeSniffer'.$ds.'CodeSniffer';
}

$path .= $ds.substr(str_replace('\\', $ds, $class), 22).'.php';
$path .= $ds.substr(str_replace('\\', $ds, $className), 22).'.php';
} else {
$path = __DIR__.$ds.'src'.$ds.substr(str_replace('\\', $ds, $class), 16).'.php';
$path = __DIR__.$ds.'src'.$ds.substr(str_replace('\\', $ds, $className), 16).'.php';
}
}

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

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

$path = $searchPath.$ds.str_replace('\\', $ds, $className).'.php';
Expand Down Expand Up @@ -297,18 +297,18 @@ public static function getLoadedClassName($path)
/**
* Gets the file path for the given class name.
*
* @param string $class The name of the class.
* @param string $className The name of the class.
*
* @throws \Exception If the class name has not been loaded.
* @return string
*/
public static function getLoadedFileName($class)
public static function getLoadedFileName($className)
{
if (isset(self::$loadedFiles[$class]) === false) {
throw new Exception("Cannot get file name for $class; class has not been included");
if (isset(self::$loadedFiles[$className]) === false) {
throw new Exception("Cannot get file name for $className; class has not been included");
}

return self::$loadedFiles[$class];
return self::$loadedFiles[$className];

}//end getLoadedFileName()

Expand Down
8 changes: 4 additions & 4 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -1483,12 +1483,12 @@ public function printUsage()
/**
* Prints out the short usage information for this script.
*
* @param bool $return If TRUE, the usage string is returned
* instead of output to screen.
* @param bool $returnOutput If TRUE, the usage string is returned
* instead of output to screen.
*
* @return string|void
*/
public function printShortUsage($return=false)
public function printShortUsage($returnOutput=false)
{
if (PHP_CODESNIFFER_CBF === true) {
$usage = 'Run "phpcbf --help" for usage information';
Expand All @@ -1498,7 +1498,7 @@ public function printShortUsage($return=false)

$usage .= PHP_EOL.PHP_EOL;

if ($return === true) {
if ($returnOutput === true) {
return $usage;
}

Expand Down
14 changes: 7 additions & 7 deletions src/Standards/Generic/Sniffs/PHP/DeprecatedFunctionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ public function __construct()
/**
* Generates the error or warning for this sniff.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the forbidden function
* in the token array.
* @param string $function The name of the forbidden function.
* @param string $pattern The pattern used for the match.
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the forbidden function
* in the token array.
* @param string $functionName The name of the forbidden function.
* @param string $pattern The pattern used for the match.
*
* @return void
*/
protected function addError($phpcsFile, $stackPtr, $function, $pattern=null)
protected function addError($phpcsFile, $stackPtr, $functionName, $pattern=null)
{
$data = [$function];
$data = [$functionName];
$error = 'Function %s() has been deprecated';
$type = 'Deprecated';

Expand Down
16 changes: 8 additions & 8 deletions src/Standards/Generic/Sniffs/PHP/ForbiddenFunctionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,17 @@ public function process(File $phpcsFile, $stackPtr)
/**
* Generates the error or warning for this sniff.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the forbidden function
* in the token array.
* @param string $function The name of the forbidden function.
* @param string $pattern The pattern used for the match.
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the forbidden function
* in the token array.
* @param string $functionName The name of the forbidden function.
* @param string $pattern The pattern used for the match.
*
* @return void
*/
protected function addError($phpcsFile, $stackPtr, $function, $pattern=null)
protected function addError($phpcsFile, $stackPtr, $functionName, $pattern=null)
{
$data = [$function];
$data = [$functionName];
$error = 'The use of function %s() is ';
if ($this->error === true) {
$type = 'Found';
Expand All @@ -223,7 +223,7 @@ protected function addError($phpcsFile, $stackPtr, $function, $pattern=null)
}

if ($pattern === null) {
$pattern = strtolower($function);
$pattern = strtolower($functionName);
}

if ($this->forbiddenFunctions[$pattern] !== null) {
Expand Down
54 changes: 27 additions & 27 deletions src/Tokenizers/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,35 @@ class Comment
/**
* Splits a single doc block comment token up into something that can be easily iterated over.
*
* @param string $string The doc block comment string to parse.
* @param string $comment The doc block comment string to parse.
* @param string $eolChar The EOL character to use for splitting strings.
* @param int $stackPtr The position of the token in the "new"/final token stream.
*
* @return array<int, array<string, string|int|array<int>>>
*/
public function tokenizeString($string, $eolChar, $stackPtr)
public function tokenizeString($comment, $eolChar, $stackPtr)
{
if (PHP_CODESNIFFER_VERBOSITY > 1) {
StatusWriter::write('*** START COMMENT TOKENIZING ***', 2);
}

$tokens = [];
$numChars = strlen($string);
$numChars = strlen($comment);

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

$char = ($numChars - strlen(ltrim($string, '/*')));
$lastChars = substr($string, -2);
$char = ($numChars - strlen(ltrim($comment, '/*')));
$lastChars = substr($comment, -2);
if ($char === $numChars && $lastChars === '*/') {
// Edge case: docblock without whitespace or contents.
$openTag = substr($string, 0, -2);
$string = $lastChars;
$openTag = substr($comment, 0, -2);
$comment = $lastChars;
} else {
$openTag = substr($string, 0, $char);
$string = ltrim($string, '/*');
$openTag = substr($comment, 0, $char);
$comment = ltrim($comment, '/*');
}

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

$closeTag = [
'content' => substr($string, strlen(rtrim($string, '/*'))),
'content' => substr($comment, strlen(rtrim($comment, '/*'))),
'code' => T_DOC_COMMENT_CLOSE_TAG,
'type' => 'T_DOC_COMMENT_CLOSE_TAG',
'comment_opener' => $openPtr,
Expand All @@ -84,7 +84,7 @@ public function tokenizeString($string, $eolChar, $stackPtr)
$closeTag['content'] = '';
}

$string = rtrim($string, '/*');
$string = rtrim($comment, '/*');

/*
Process each line of the comment.
Expand Down Expand Up @@ -181,32 +181,32 @@ public function tokenizeString($string, $eolChar, $stackPtr)
/**
* Process a single line of a comment.
*
* @param string $string The comment string being tokenized.
* @param string $comment The comment string being tokenized.
* @param string $eolChar The EOL character to use for splitting strings.
* @param int $start The position in the string to start processing.
* @param int $end The position in the string to end processing.
*
* @return array<int, array<string, string|int>>
*/
private function processLine($string, $eolChar, $start, $end)
private function processLine($comment, $eolChar, $start, $end)
{
$tokens = [];

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

if (isset($string[$start]) === false) {
if (isset($comment[$start]) === false) {
return $tokens;
}

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

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

// Process the rest of the line.
$eol = strpos($string, $eolChar, $start);
$eol = strpos($comment, $eolChar, $start);
if ($eol === false) {
$eol = $end;
}

if ($eol > $start) {
$tokens[] = [
'content' => substr($string, $start, ($eol - $start)),
'content' => substr($comment, $start, ($eol - $start)),
'code' => T_DOC_COMMENT_STRING,
'type' => 'T_DOC_COMMENT_STRING',
];
}

if ($eol !== $end) {
$tokens[] = [
'content' => substr($string, $eol, strlen($eolChar)),
'content' => substr($comment, $eol, strlen($eolChar)),
'code' => T_DOC_COMMENT_WHITESPACE,
'type' => 'T_DOC_COMMENT_WHITESPACE',
];
Expand All @@ -257,21 +257,21 @@ private function processLine($string, $eolChar, $start, $end)
/**
* Collect consecutive whitespace into a single token.
*
* @param string $string The comment string being tokenized.
* @param int $start The position in the string to start processing.
* @param int $end The position in the string to end processing.
* @param string $comment The comment string being tokenized.
* @param int $start The position in the string to start processing.
* @param int $end The position in the string to end processing.
*
* @return array<string, string|int>|null
*/
private function collectWhitespace($string, $start, $end)
private function collectWhitespace($comment, $start, $end)
{
$space = '';
for ($start; $start < $end; $start++) {
if ($string[$start] !== ' ' && $string[$start] !== "\t") {
if ($comment[$start] !== ' ' && $comment[$start] !== "\t") {
break;
}

$space .= $string[$start];
$space .= $comment[$start];
}

if ($space === '') {
Expand Down
6 changes: 3 additions & 3 deletions src/Tokenizers/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,11 +531,11 @@ class PHP extends Tokenizer
* Starts by using token_get_all() but does a lot of extra processing
* to insert information about the context of the token.
*
* @param string $string The string to tokenize.
* @param string $code The code to tokenize.
*
* @return array
*/
protected function tokenize($string)
protected function tokenize($code)
{
if (PHP_CODESNIFFER_VERBOSITY > 1) {
StatusWriter::write('*** START PHP TOKENIZING ***', 1);
Expand All @@ -545,7 +545,7 @@ protected function tokenize($string)
}
}

$tokens = @token_get_all($string);
$tokens = @token_get_all($code);
$finalTokens = [];

$newStackPtr = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/Tokenizers/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ public function getTokens()
/**
* Creates an array of tokens when given some content.
*
* @param string $string The string to tokenize.
* @param string $code The code to tokenize.
*
* @return array
*/
abstract protected function tokenize($string);
abstract protected function tokenize($code);


/**
Expand Down
Loading
Loading