repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Formatting/TraitUseSpacingSniff.php
TraitUseSpacingSniff.checkLinesAfterLastUse
private function checkLinesAfterLastUse(int $lastUsePos): void { $lastUseEndPos = $this->getLastUseEndPos($lastUsePos); list($realLinesAfterUse, $whitespaceEnd) = $this->getRealLinesAfterLastUse($lastUseEndPos); $requiredLinesAfter = $this->isEndOfClass($lastUseEndPos) ? self::LINES_AFTER_LAST_USE_WHEN_LAST_IN_CLASS : self::LINES_AFTER_LAST_USE; if ($realLinesAfterUse !== $requiredLinesAfter) { $fix = $this->getFile()->addFixableError( self::MESSAGE_INCORRECT_LINES_COUNT_AFTER_LAST_USE, $lastUsePos, self::CODE_INCORRECT_LINES_COUNT_AFTER_LAST_USE, [ $requiredLinesAfter, $realLinesAfterUse ] ); if ($fix) { $this->fixLineAfterLastUse($lastUseEndPos, $whitespaceEnd, $requiredLinesAfter); } } }
php
private function checkLinesAfterLastUse(int $lastUsePos): void { $lastUseEndPos = $this->getLastUseEndPos($lastUsePos); list($realLinesAfterUse, $whitespaceEnd) = $this->getRealLinesAfterLastUse($lastUseEndPos); $requiredLinesAfter = $this->isEndOfClass($lastUseEndPos) ? self::LINES_AFTER_LAST_USE_WHEN_LAST_IN_CLASS : self::LINES_AFTER_LAST_USE; if ($realLinesAfterUse !== $requiredLinesAfter) { $fix = $this->getFile()->addFixableError( self::MESSAGE_INCORRECT_LINES_COUNT_AFTER_LAST_USE, $lastUsePos, self::CODE_INCORRECT_LINES_COUNT_AFTER_LAST_USE, [ $requiredLinesAfter, $realLinesAfterUse ] ); if ($fix) { $this->fixLineAfterLastUse($lastUseEndPos, $whitespaceEnd, $requiredLinesAfter); } } }
[ "private", "function", "checkLinesAfterLastUse", "(", "int", "$", "lastUsePos", ")", ":", "void", "{", "$", "lastUseEndPos", "=", "$", "this", "->", "getLastUseEndPos", "(", "$", "lastUsePos", ")", ";", "list", "(", "$", "realLinesAfterUse", ",", "$", "white...
Checks the line after the last use and registers an error if needed. @param int $lastUsePos @return void
[ "Checks", "the", "line", "after", "the", "last", "use", "and", "registers", "an", "error", "if", "needed", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Formatting/TraitUseSpacingSniff.php#L106-L131
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Formatting/TraitUseSpacingSniff.php
TraitUseSpacingSniff.checkLinesBeforeFirstUse
private function checkLinesBeforeFirstUse(int $firstUsePos): void { $posBeforeFirstUse = TokenHelper::findPreviousExcluding($this->getFile(), T_WHITESPACE, $firstUsePos - 1); $realLinesBeforeUse = $this->getRealLinesBeforeFirstUse($firstUsePos, $posBeforeFirstUse); if ($realLinesBeforeUse !== self::LINES_BEFORE_FIRST_USE) { $fix = $this->getFile()->addFixableError( self::MESSAGE_INCORRECT_LINES_COUNT_BEFORE_FIRST_USE, $firstUsePos, self::CODE_INCORRECT_LINES_COUNT_BEFORE_FIRST_USE, [ self::LINES_BEFORE_FIRST_USE, $realLinesBeforeUse ] ); if ($fix) { $this->fixLinesBeforeFirstUse($firstUsePos, $posBeforeFirstUse, self::LINES_BEFORE_FIRST_USE); } } }
php
private function checkLinesBeforeFirstUse(int $firstUsePos): void { $posBeforeFirstUse = TokenHelper::findPreviousExcluding($this->getFile(), T_WHITESPACE, $firstUsePos - 1); $realLinesBeforeUse = $this->getRealLinesBeforeFirstUse($firstUsePos, $posBeforeFirstUse); if ($realLinesBeforeUse !== self::LINES_BEFORE_FIRST_USE) { $fix = $this->getFile()->addFixableError( self::MESSAGE_INCORRECT_LINES_COUNT_BEFORE_FIRST_USE, $firstUsePos, self::CODE_INCORRECT_LINES_COUNT_BEFORE_FIRST_USE, [ self::LINES_BEFORE_FIRST_USE, $realLinesBeforeUse ] ); if ($fix) { $this->fixLinesBeforeFirstUse($firstUsePos, $posBeforeFirstUse, self::LINES_BEFORE_FIRST_USE); } } }
[ "private", "function", "checkLinesBeforeFirstUse", "(", "int", "$", "firstUsePos", ")", ":", "void", "{", "$", "posBeforeFirstUse", "=", "TokenHelper", "::", "findPreviousExcluding", "(", "$", "this", "->", "getFile", "(", ")", ",", "T_WHITESPACE", ",", "$", "...
Checks the lines before the first usage and registers an error if needed. @param int $firstUsePos @return void
[ "Checks", "the", "lines", "before", "the", "first", "usage", "and", "registers", "an", "error", "if", "needed", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Formatting/TraitUseSpacingSniff.php#L140-L160
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Formatting/TraitUseSpacingSniff.php
TraitUseSpacingSniff.checkLinesBetweenUses
private function checkLinesBetweenUses(): void { $file = $this->getFile(); $previousUsePos = null; foreach ($this->uses as $usePos) { if ($previousUsePos === null) { $previousUsePos = $usePos; continue; } $posBeforeUse = TokenHelper::findPreviousEffective($file, $usePos - 1); $previousUseEndPos = TokenHelper::findNextLocal( $file, [T_SEMICOLON, T_OPEN_CURLY_BRACKET], $previousUsePos + 1 ); $realLinesBetweenUse = $this->getRealLinesBetweenUses( $previousUseEndPos, $usePos ); $previousUsePos = $usePos; if ($realLinesBetweenUse !== self::LINES_BETWEEN_USES) { $errorParameters = [ self::MESSAGE_INCORRECT_LINES_COUNT_BETWEEN_USES, $usePos, self::CODE_INCORRECT_LINES_COUNT_BETWEEN_USES, [ self::LINES_BETWEEN_USES, $realLinesBetweenUse ] ]; if ($previousUseEndPos !== $posBeforeUse) { $file->addError(...$errorParameters); } else { $fix = $file->addFixableError(...$errorParameters); if ($fix) { $this->fixLinesBetweenUses($usePos, $previousUseEndPos, self::LINES_BETWEEN_USES); } } } } }
php
private function checkLinesBetweenUses(): void { $file = $this->getFile(); $previousUsePos = null; foreach ($this->uses as $usePos) { if ($previousUsePos === null) { $previousUsePos = $usePos; continue; } $posBeforeUse = TokenHelper::findPreviousEffective($file, $usePos - 1); $previousUseEndPos = TokenHelper::findNextLocal( $file, [T_SEMICOLON, T_OPEN_CURLY_BRACKET], $previousUsePos + 1 ); $realLinesBetweenUse = $this->getRealLinesBetweenUses( $previousUseEndPos, $usePos ); $previousUsePos = $usePos; if ($realLinesBetweenUse !== self::LINES_BETWEEN_USES) { $errorParameters = [ self::MESSAGE_INCORRECT_LINES_COUNT_BETWEEN_USES, $usePos, self::CODE_INCORRECT_LINES_COUNT_BETWEEN_USES, [ self::LINES_BETWEEN_USES, $realLinesBetweenUse ] ]; if ($previousUseEndPos !== $posBeforeUse) { $file->addError(...$errorParameters); } else { $fix = $file->addFixableError(...$errorParameters); if ($fix) { $this->fixLinesBetweenUses($usePos, $previousUseEndPos, self::LINES_BETWEEN_USES); } } } } }
[ "private", "function", "checkLinesBetweenUses", "(", ")", ":", "void", "{", "$", "file", "=", "$", "this", "->", "getFile", "(", ")", ";", "$", "previousUsePos", "=", "null", ";", "foreach", "(", "$", "this", "->", "uses", "as", "$", "usePos", ")", "...
Checks the lines between uses and registers an erro rif needed. @return void
[ "Checks", "the", "lines", "between", "uses", "and", "registers", "an", "erro", "rif", "needed", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Formatting/TraitUseSpacingSniff.php#L167-L214
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Formatting/TraitUseSpacingSniff.php
TraitUseSpacingSniff.fixLineAfterLastUse
private function fixLineAfterLastUse( int $lastUseEndPos, int $whitespaceEnd, int $requiredLinesAfter ): void { $file = $this->getFile(); $file->fixer->beginChangeset(); for ($i = $lastUseEndPos + 1; $i <= $whitespaceEnd; $i++) { $file->fixer->replaceToken($i, ''); } for ($i = 0; $i <= $requiredLinesAfter; $i++) { $file->fixer->addNewline($lastUseEndPos); } $file->fixer->endChangeset(); }
php
private function fixLineAfterLastUse( int $lastUseEndPos, int $whitespaceEnd, int $requiredLinesAfter ): void { $file = $this->getFile(); $file->fixer->beginChangeset(); for ($i = $lastUseEndPos + 1; $i <= $whitespaceEnd; $i++) { $file->fixer->replaceToken($i, ''); } for ($i = 0; $i <= $requiredLinesAfter; $i++) { $file->fixer->addNewline($lastUseEndPos); } $file->fixer->endChangeset(); }
[ "private", "function", "fixLineAfterLastUse", "(", "int", "$", "lastUseEndPos", ",", "int", "$", "whitespaceEnd", ",", "int", "$", "requiredLinesAfter", ")", ":", "void", "{", "$", "file", "=", "$", "this", "->", "getFile", "(", ")", ";", "$", "file", "-...
Fixes the lines which are allowed after the last use. @param int $lastUseEndPos @param int $whitespaceEnd @param int $requiredLinesAfter @return void
[ "Fixes", "the", "lines", "which", "are", "allowed", "after", "the", "last", "use", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Formatting/TraitUseSpacingSniff.php#L225-L243
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Formatting/TraitUseSpacingSniff.php
TraitUseSpacingSniff.fixLinesBeforeFirstUse
private function fixLinesBeforeFirstUse( int $firstUsePos, int $posBeforeFirstUse ): void { $file = $this->getFile(); $file->fixer->beginChangeset(); $posBeforeIndentation = TokenHelper::findPreviousContent( $file, T_WHITESPACE, $file->eolChar, $firstUsePos, $posBeforeFirstUse ); if ($posBeforeIndentation !== null) { for ($i = $posBeforeFirstUse + 1; $i <= $posBeforeIndentation; $i++) { $file->fixer->replaceToken($i, ''); } } for ($i = 0; $i <= self::LINES_BEFORE_FIRST_USE; $i++) { $file->fixer->addNewline($posBeforeFirstUse); } $file->fixer->endChangeset(); }
php
private function fixLinesBeforeFirstUse( int $firstUsePos, int $posBeforeFirstUse ): void { $file = $this->getFile(); $file->fixer->beginChangeset(); $posBeforeIndentation = TokenHelper::findPreviousContent( $file, T_WHITESPACE, $file->eolChar, $firstUsePos, $posBeforeFirstUse ); if ($posBeforeIndentation !== null) { for ($i = $posBeforeFirstUse + 1; $i <= $posBeforeIndentation; $i++) { $file->fixer->replaceToken($i, ''); } } for ($i = 0; $i <= self::LINES_BEFORE_FIRST_USE; $i++) { $file->fixer->addNewline($posBeforeFirstUse); } $file->fixer->endChangeset(); }
[ "private", "function", "fixLinesBeforeFirstUse", "(", "int", "$", "firstUsePos", ",", "int", "$", "posBeforeFirstUse", ")", ":", "void", "{", "$", "file", "=", "$", "this", "->", "getFile", "(", ")", ";", "$", "file", "->", "fixer", "->", "beginChangeset",...
Fixes the lines before the first use. @param int $firstUsePos @param int $posBeforeFirstUse @return void
[ "Fixes", "the", "lines", "before", "the", "first", "use", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Formatting/TraitUseSpacingSniff.php#L253-L278
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Formatting/TraitUseSpacingSniff.php
TraitUseSpacingSniff.fixLinesBetweenUses
private function fixLinesBetweenUses(int $usePos, int $previousUseEndPos): void { $file = $this->getFile(); $posBeforeIndentation = TokenHelper::findPreviousContent( $file, T_WHITESPACE, $file->eolChar, $usePos, $previousUseEndPos ); $file->fixer->beginChangeset(); if ($posBeforeIndentation !== null) { for ($i = $previousUseEndPos + 1; $i <= $posBeforeIndentation; $i++) { $file->fixer->replaceToken($i, ''); } } for ($i = 0; $i <= self::LINES_BETWEEN_USES; $i++) { $file->fixer->addNewline($previousUseEndPos); } $file->fixer->endChangeset(); }
php
private function fixLinesBetweenUses(int $usePos, int $previousUseEndPos): void { $file = $this->getFile(); $posBeforeIndentation = TokenHelper::findPreviousContent( $file, T_WHITESPACE, $file->eolChar, $usePos, $previousUseEndPos ); $file->fixer->beginChangeset(); if ($posBeforeIndentation !== null) { for ($i = $previousUseEndPos + 1; $i <= $posBeforeIndentation; $i++) { $file->fixer->replaceToken($i, ''); } } for ($i = 0; $i <= self::LINES_BETWEEN_USES; $i++) { $file->fixer->addNewline($previousUseEndPos); } $file->fixer->endChangeset(); }
[ "private", "function", "fixLinesBetweenUses", "(", "int", "$", "usePos", ",", "int", "$", "previousUseEndPos", ")", ":", "void", "{", "$", "file", "=", "$", "this", "->", "getFile", "(", ")", ";", "$", "posBeforeIndentation", "=", "TokenHelper", "::", "fin...
Fixes the lines between the uses. @param int $usePos @param int $previousUseEndPos @return void
[ "Fixes", "the", "lines", "between", "the", "uses", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Formatting/TraitUseSpacingSniff.php#L288-L310
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Formatting/TraitUseSpacingSniff.php
TraitUseSpacingSniff.getLastUseEndPos
private function getLastUseEndPos(int $lastUsePos): int { $file = $this->getFile(); $tokens = $file->getTokens(); $lastUseEndPos = TokenHelper::findNextLocal( $file, [T_SEMICOLON, T_OPEN_CURLY_BRACKET], $lastUsePos + 1 ); if ($tokens[$lastUseEndPos]['code'] === T_OPEN_CURLY_BRACKET) { $lastUseEndPos = $tokens[$lastUseEndPos]['bracket_closer']; } return $lastUseEndPos; }
php
private function getLastUseEndPos(int $lastUsePos): int { $file = $this->getFile(); $tokens = $file->getTokens(); $lastUseEndPos = TokenHelper::findNextLocal( $file, [T_SEMICOLON, T_OPEN_CURLY_BRACKET], $lastUsePos + 1 ); if ($tokens[$lastUseEndPos]['code'] === T_OPEN_CURLY_BRACKET) { $lastUseEndPos = $tokens[$lastUseEndPos]['bracket_closer']; } return $lastUseEndPos; }
[ "private", "function", "getLastUseEndPos", "(", "int", "$", "lastUsePos", ")", ":", "int", "{", "$", "file", "=", "$", "this", "->", "getFile", "(", ")", ";", "$", "tokens", "=", "$", "file", "->", "getTokens", "(", ")", ";", "$", "lastUseEndPos", "=...
Gets the position on which the last use ends. @param int $lastUsePos @return int
[ "Gets", "the", "position", "on", "which", "the", "last", "use", "ends", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Formatting/TraitUseSpacingSniff.php#L319-L335
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Formatting/TraitUseSpacingSniff.php
TraitUseSpacingSniff.getRealLinesAfterLastUse
private function getRealLinesAfterLastUse(int $lastUseEndPos): array { $file = $this->getFile(); $tokens = $file->getTokens(); $whitespaceEnd = TokenHelper::findNextExcluding($file, T_WHITESPACE, $lastUseEndPos + 1) - 1; if ($lastUseEndPos !== $whitespaceEnd && $tokens[$whitespaceEnd]['content'] !== $file->eolChar) { $lastEolPos = TokenHelper::findPreviousContent( $file, T_WHITESPACE, $file->eolChar, $whitespaceEnd - 1, $lastUseEndPos ); $whitespaceEnd = $lastEolPos ?? $lastUseEndPos; } $whitespaceAfterLastUse = TokenHelper::getContent($file, $lastUseEndPos + 1, $whitespaceEnd); $realLinesAfterUse = substr_count($whitespaceAfterLastUse, $file->eolChar) - 1; return [$realLinesAfterUse, $whitespaceEnd]; }
php
private function getRealLinesAfterLastUse(int $lastUseEndPos): array { $file = $this->getFile(); $tokens = $file->getTokens(); $whitespaceEnd = TokenHelper::findNextExcluding($file, T_WHITESPACE, $lastUseEndPos + 1) - 1; if ($lastUseEndPos !== $whitespaceEnd && $tokens[$whitespaceEnd]['content'] !== $file->eolChar) { $lastEolPos = TokenHelper::findPreviousContent( $file, T_WHITESPACE, $file->eolChar, $whitespaceEnd - 1, $lastUseEndPos ); $whitespaceEnd = $lastEolPos ?? $lastUseEndPos; } $whitespaceAfterLastUse = TokenHelper::getContent($file, $lastUseEndPos + 1, $whitespaceEnd); $realLinesAfterUse = substr_count($whitespaceAfterLastUse, $file->eolChar) - 1; return [$realLinesAfterUse, $whitespaceEnd]; }
[ "private", "function", "getRealLinesAfterLastUse", "(", "int", "$", "lastUseEndPos", ")", ":", "array", "{", "$", "file", "=", "$", "this", "->", "getFile", "(", ")", ";", "$", "tokens", "=", "$", "file", "->", "getTokens", "(", ")", ";", "$", "whitesp...
Gets the real lines after the last use. @param int $lastUseEndPos @return array The first element is the line count, and the second element is when the whitespace ends.
[ "Gets", "the", "real", "lines", "after", "the", "last", "use", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Formatting/TraitUseSpacingSniff.php#L344-L366
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Formatting/TraitUseSpacingSniff.php
TraitUseSpacingSniff.getRealLinesBeforeFirstUse
private function getRealLinesBeforeFirstUse(int $firstUsePos, int $posBeforeFirstUse): int { $file = $this->getFile(); $whitespaceBeforeFirstUse = ''; if ($posBeforeFirstUse + 1 !== $firstUsePos) { $whitespaceBeforeFirstUse .= TokenHelper::getContent( $file, $posBeforeFirstUse + 1, $firstUsePos - 1 ); } return substr_count($whitespaceBeforeFirstUse, $file->eolChar) - 1; }
php
private function getRealLinesBeforeFirstUse(int $firstUsePos, int $posBeforeFirstUse): int { $file = $this->getFile(); $whitespaceBeforeFirstUse = ''; if ($posBeforeFirstUse + 1 !== $firstUsePos) { $whitespaceBeforeFirstUse .= TokenHelper::getContent( $file, $posBeforeFirstUse + 1, $firstUsePos - 1 ); } return substr_count($whitespaceBeforeFirstUse, $file->eolChar) - 1; }
[ "private", "function", "getRealLinesBeforeFirstUse", "(", "int", "$", "firstUsePos", ",", "int", "$", "posBeforeFirstUse", ")", ":", "int", "{", "$", "file", "=", "$", "this", "->", "getFile", "(", ")", ";", "$", "whitespaceBeforeFirstUse", "=", "''", ";", ...
Returns the real lines before the first use. @param int $firstUsePos @param int $posBeforeFirstUse @return int
[ "Returns", "the", "real", "lines", "before", "the", "first", "use", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Formatting/TraitUseSpacingSniff.php#L376-L390
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Formatting/TraitUseSpacingSniff.php
TraitUseSpacingSniff.getRealLinesBetweenUses
private function getRealLinesBetweenUses(int &$previousUseEndPos, int $usePos): int { $tokens = $this->getFile()->getTokens(); if ($tokens[$previousUseEndPos]['code'] === T_OPEN_CURLY_BRACKET) { $previousUseEndPos = $tokens[$previousUseEndPos]['bracket_closer']; } return $tokens[$usePos]['line'] - $tokens[$previousUseEndPos]['line'] - 1; }
php
private function getRealLinesBetweenUses(int &$previousUseEndPos, int $usePos): int { $tokens = $this->getFile()->getTokens(); if ($tokens[$previousUseEndPos]['code'] === T_OPEN_CURLY_BRACKET) { $previousUseEndPos = $tokens[$previousUseEndPos]['bracket_closer']; } return $tokens[$usePos]['line'] - $tokens[$previousUseEndPos]['line'] - 1; }
[ "private", "function", "getRealLinesBetweenUses", "(", "int", "&", "$", "previousUseEndPos", ",", "int", "$", "usePos", ")", ":", "int", "{", "$", "tokens", "=", "$", "this", "->", "getFile", "(", ")", "->", "getTokens", "(", ")", ";", "if", "(", "$", ...
Returns the real lines between the uses. @param int $previousUseEndPos @param int $usePos @return int
[ "Returns", "the", "real", "lines", "between", "the", "uses", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Formatting/TraitUseSpacingSniff.php#L400-L409
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Formatting/TraitUseSpacingSniff.php
TraitUseSpacingSniff.isEndOfClass
private function isEndOfClass(int $lastUseEndPos): bool { $file = $this->getFile(); $tokens = $file->getTokens(); $posAfterLastUse = TokenHelper::findNextEffective($file, $lastUseEndPos + 1); return $tokens[$posAfterLastUse]['code'] === T_CLOSE_CURLY_BRACKET; }
php
private function isEndOfClass(int $lastUseEndPos): bool { $file = $this->getFile(); $tokens = $file->getTokens(); $posAfterLastUse = TokenHelper::findNextEffective($file, $lastUseEndPos + 1); return $tokens[$posAfterLastUse]['code'] === T_CLOSE_CURLY_BRACKET; }
[ "private", "function", "isEndOfClass", "(", "int", "$", "lastUseEndPos", ")", ":", "bool", "{", "$", "file", "=", "$", "this", "->", "getFile", "(", ")", ";", "$", "tokens", "=", "$", "file", "->", "getTokens", "(", ")", ";", "$", "posAfterLastUse", ...
Is the given Position the end of the class. @param int $lastUseEndPos @return bool
[ "Is", "the", "given", "Position", "the", "end", "of", "the", "class", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Formatting/TraitUseSpacingSniff.php#L418-L426
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/TypeHints/ReturnTypeDeclarationSniff.php
ReturnTypeDeclarationSniff.addReturnType
private function addReturnType(): void { $file = $this->getFile(); $returnTypeHint = $this->createReturnType(); $file->fixer->beginChangeset(); if ($this->isCustomArrayType($returnTypeHint)) { $returnTypeHint = ($returnTypeHint[0] === '?' ? '?' : '') . 'array'; } $file->fixer->addContent( $this->token['parenthesis_closer'], ': ' . $returnTypeHint ); $file->fixer->endChangeset(); }
php
private function addReturnType(): void { $file = $this->getFile(); $returnTypeHint = $this->createReturnType(); $file->fixer->beginChangeset(); if ($this->isCustomArrayType($returnTypeHint)) { $returnTypeHint = ($returnTypeHint[0] === '?' ? '?' : '') . 'array'; } $file->fixer->addContent( $this->token['parenthesis_closer'], ': ' . $returnTypeHint ); $file->fixer->endChangeset(); }
[ "private", "function", "addReturnType", "(", ")", ":", "void", "{", "$", "file", "=", "$", "this", "->", "getFile", "(", ")", ";", "$", "returnTypeHint", "=", "$", "this", "->", "createReturnType", "(", ")", ";", "$", "file", "->", "fixer", "->", "be...
Adds the return type to fix the error. @return void
[ "Adds", "the", "return", "type", "to", "fix", "the", "error", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/TypeHints/ReturnTypeDeclarationSniff.php#L95-L112
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/TypeHints/ReturnTypeDeclarationSniff.php
ReturnTypeDeclarationSniff.areRequirementsMet
protected function areRequirementsMet(): bool { return !$this->isSniffSuppressed(static::CODE_MISSING_RETURN_TYPE) && !$this->hasReturnType() && !in_array($this->getFunctionName(), $this->methodsWithoutVoid); }
php
protected function areRequirementsMet(): bool { return !$this->isSniffSuppressed(static::CODE_MISSING_RETURN_TYPE) && !$this->hasReturnType() && !in_array($this->getFunctionName(), $this->methodsWithoutVoid); }
[ "protected", "function", "areRequirementsMet", "(", ")", ":", "bool", "{", "return", "!", "$", "this", "->", "isSniffSuppressed", "(", "static", "::", "CODE_MISSING_RETURN_TYPE", ")", "&&", "!", "$", "this", "->", "hasReturnType", "(", ")", "&&", "!", "in_ar...
Returns true if this sniff may run. @return bool
[ "Returns", "true", "if", "this", "sniff", "may", "run", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/TypeHints/ReturnTypeDeclarationSniff.php#L119-L123
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/TypeHints/ReturnTypeDeclarationSniff.php
ReturnTypeDeclarationSniff.createReturnType
private function createReturnType(): string { $returnTypeHint = ''; $typeCount = count($this->typesForFix); foreach ($this->typesForFix as $type) { // We add the default value if only null is used (which has no real native return type). if ($type === 'null' && ($typeCount === 1)) { $returnTypeHint = $this->defaultNullReturn; break; // We still need this break to prevent further execution of the default value. } // We add the question mark if there is a nullable type. if (in_array($type, self::NULL_TYPES, true) && ($typeCount > 1)) { $returnTypeHint = '?' . $returnTypeHint; continue; // We still need this continue to prevent further execution of the questionmark. } // We add a fixable "native" type. We do not fix custom classes (because it would have side effects to the // imported usage of classes. $returnTypeHint .= (TypeHintHelper::isSimpleTypeHint($type)) ? TypeHintHelper::convertLongSimpleTypeHintToShort($type) : $type; } return $returnTypeHint; }
php
private function createReturnType(): string { $returnTypeHint = ''; $typeCount = count($this->typesForFix); foreach ($this->typesForFix as $type) { // We add the default value if only null is used (which has no real native return type). if ($type === 'null' && ($typeCount === 1)) { $returnTypeHint = $this->defaultNullReturn; break; // We still need this break to prevent further execution of the default value. } // We add the question mark if there is a nullable type. if (in_array($type, self::NULL_TYPES, true) && ($typeCount > 1)) { $returnTypeHint = '?' . $returnTypeHint; continue; // We still need this continue to prevent further execution of the questionmark. } // We add a fixable "native" type. We do not fix custom classes (because it would have side effects to the // imported usage of classes. $returnTypeHint .= (TypeHintHelper::isSimpleTypeHint($type)) ? TypeHintHelper::convertLongSimpleTypeHintToShort($type) : $type; } return $returnTypeHint; }
[ "private", "function", "createReturnType", "(", ")", ":", "string", "{", "$", "returnTypeHint", "=", "''", ";", "$", "typeCount", "=", "count", "(", "$", "this", "->", "typesForFix", ")", ";", "foreach", "(", "$", "this", "->", "typesForFix", "as", "$", ...
Creates the new return type for fixing or returns a null if not possible. @return string
[ "Creates", "the", "new", "return", "type", "for", "fixing", "or", "returns", "a", "null", "if", "not", "possible", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/TypeHints/ReturnTypeDeclarationSniff.php#L130-L156
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/TypeHints/ReturnTypeDeclarationSniff.php
ReturnTypeDeclarationSniff.getFunctionName
private function getFunctionName(): string { if (!$this->functionName) { $this->functionName = $this->loadFunctionName(); } return $this->functionName; }
php
private function getFunctionName(): string { if (!$this->functionName) { $this->functionName = $this->loadFunctionName(); } return $this->functionName; }
[ "private", "function", "getFunctionName", "(", ")", ":", "string", "{", "if", "(", "!", "$", "this", "->", "functionName", ")", "{", "$", "this", "->", "functionName", "=", "$", "this", "->", "loadFunctionName", "(", ")", ";", "}", "return", "$", "this...
Returns the name of the function. @return string
[ "Returns", "the", "name", "of", "the", "function", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/TypeHints/ReturnTypeDeclarationSniff.php#L181-L188
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/TypeHints/ReturnTypeDeclarationSniff.php
ReturnTypeDeclarationSniff.getReturnsFromAnnotation
private function getReturnsFromAnnotation(?Annotation $annotation): array { return $this->isFilledReturnAnnotation($annotation) ? explode('|', preg_split('~\\s+~', $annotation->getContent())[0]) : []; }
php
private function getReturnsFromAnnotation(?Annotation $annotation): array { return $this->isFilledReturnAnnotation($annotation) ? explode('|', preg_split('~\\s+~', $annotation->getContent())[0]) : []; }
[ "private", "function", "getReturnsFromAnnotation", "(", "?", "Annotation", "$", "annotation", ")", ":", "array", "{", "return", "$", "this", "->", "isFilledReturnAnnotation", "(", "$", "annotation", ")", "?", "explode", "(", "'|'", ",", "preg_split", "(", "'~\...
Returns the return types of the annotation. @param null|Annotation $annotation @return array
[ "Returns", "the", "return", "types", "of", "the", "annotation", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/TypeHints/ReturnTypeDeclarationSniff.php#L197-L202
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/TypeHints/ReturnTypeDeclarationSniff.php
ReturnTypeDeclarationSniff.getUsableReturnTypes
private function getUsableReturnTypes(Annotation $annotation): ?array { $return = null; $returnTypes = $this->getReturnsFromAnnotation($annotation); $returnTypeCount = count($returnTypes); $justOneReturn = $returnTypeCount === 1; if (!$justOneReturn || strtolower($returnTypes[0]) !== 'mixed') { $isNullableType = ($returnTypeCount === 2) && version_compare(phpversion(), '7.1.0', '>=') && (count(array_intersect($returnTypes, self::NULL_TYPES)) === 1); $return = ($justOneReturn || $isNullableType) ? $returnTypes : null; } return $return; }
php
private function getUsableReturnTypes(Annotation $annotation): ?array { $return = null; $returnTypes = $this->getReturnsFromAnnotation($annotation); $returnTypeCount = count($returnTypes); $justOneReturn = $returnTypeCount === 1; if (!$justOneReturn || strtolower($returnTypes[0]) !== 'mixed') { $isNullableType = ($returnTypeCount === 2) && version_compare(phpversion(), '7.1.0', '>=') && (count(array_intersect($returnTypes, self::NULL_TYPES)) === 1); $return = ($justOneReturn || $isNullableType) ? $returnTypes : null; } return $return; }
[ "private", "function", "getUsableReturnTypes", "(", "Annotation", "$", "annotation", ")", ":", "?", "array", "{", "$", "return", "=", "null", ";", "$", "returnTypes", "=", "$", "this", "->", "getReturnsFromAnnotation", "(", "$", "annotation", ")", ";", "$", ...
Returns the types of the annotation, if the types are usable. Usable means, that there should be one type != mixed in the return-annotation or a nullable type, which means 2 types like null|$ANYTYPE. @param Annotation $annotation @return array|null Null if there are no usable types or the usable types.
[ "Returns", "the", "types", "of", "the", "annotation", "if", "the", "types", "are", "usable", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/TypeHints/ReturnTypeDeclarationSniff.php#L214-L231
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/TypeHints/ReturnTypeDeclarationSniff.php
ReturnTypeDeclarationSniff.hasReturnType
private function hasReturnType(): bool { if ($this->hasReturnType === null) { $this->hasReturnType = FunctionHelper::hasReturnTypeHint($this->file->getBaseFile(), $this->stackPos); } return $this->hasReturnType; }
php
private function hasReturnType(): bool { if ($this->hasReturnType === null) { $this->hasReturnType = FunctionHelper::hasReturnTypeHint($this->file->getBaseFile(), $this->stackPos); } return $this->hasReturnType; }
[ "private", "function", "hasReturnType", "(", ")", ":", "bool", "{", "if", "(", "$", "this", "->", "hasReturnType", "===", "null", ")", "{", "$", "this", "->", "hasReturnType", "=", "FunctionHelper", "::", "hasReturnTypeHint", "(", "$", "this", "->", "file"...
Check if there is a return type. @return bool
[ "Check", "if", "there", "is", "a", "return", "type", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/TypeHints/ReturnTypeDeclarationSniff.php#L238-L245
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/TypeHints/ReturnTypeDeclarationSniff.php
ReturnTypeDeclarationSniff.isFixableReturnType
private function isFixableReturnType(string $type): bool { // $type === null is not valid in our slevomat helper. return TypeHintHelper::isSimpleTypeHint($type) || $type === 'null' || $this->isCustomArrayType($type); }
php
private function isFixableReturnType(string $type): bool { // $type === null is not valid in our slevomat helper. return TypeHintHelper::isSimpleTypeHint($type) || $type === 'null' || $this->isCustomArrayType($type); }
[ "private", "function", "isFixableReturnType", "(", "string", "$", "type", ")", ":", "bool", "{", "// $type === null is not valid in our slevomat helper.", "return", "TypeHintHelper", "::", "isSimpleTypeHint", "(", "$", "type", ")", "||", "$", "type", "===", "'null'", ...
Check if the return annotation type is valid. @param string $type The type value of the return annotation @return bool Type is valid
[ "Check", "if", "the", "return", "annotation", "type", "is", "valid", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/TypeHints/ReturnTypeDeclarationSniff.php#L278-L282
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/TypeHints/ReturnTypeDeclarationSniff.php
ReturnTypeDeclarationSniff.loadFixableTypes
private function loadFixableTypes(?array $returnTypes): array { return array_filter($returnTypes ?? [], function (string $returnType): bool { return $this->isFixableReturnType($returnType); }); }
php
private function loadFixableTypes(?array $returnTypes): array { return array_filter($returnTypes ?? [], function (string $returnType): bool { return $this->isFixableReturnType($returnType); }); }
[ "private", "function", "loadFixableTypes", "(", "?", "array", "$", "returnTypes", ")", ":", "array", "{", "return", "array_filter", "(", "$", "returnTypes", "??", "[", "]", ",", "function", "(", "string", "$", "returnType", ")", ":", "bool", "{", "return",...
Removes the return types from the given array, which are not compatible with our fix. @param array|null $returnTypes @return array The cleaned array.
[ "Removes", "the", "return", "types", "from", "the", "given", "array", "which", "are", "not", "compatible", "with", "our", "fix", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/TypeHints/ReturnTypeDeclarationSniff.php#L291-L296
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/TypeHints/ReturnTypeDeclarationSniff.php
ReturnTypeDeclarationSniff.processToken
protected function processToken(): void { $this->getFile()->recordMetric($this->stackPos, 'Has return type', 'no'); $returnAnnotation = $this->loadReturnAnnotation(); if (!$this->isFilledReturnAnnotation($returnAnnotation) || ($returnTypes = $this->getUsableReturnTypes($returnAnnotation))) { $this->validateReturnType($returnTypes ?? null); } }
php
protected function processToken(): void { $this->getFile()->recordMetric($this->stackPos, 'Has return type', 'no'); $returnAnnotation = $this->loadReturnAnnotation(); if (!$this->isFilledReturnAnnotation($returnAnnotation) || ($returnTypes = $this->getUsableReturnTypes($returnAnnotation))) { $this->validateReturnType($returnTypes ?? null); } }
[ "protected", "function", "processToken", "(", ")", ":", "void", "{", "$", "this", "->", "getFile", "(", ")", "->", "recordMetric", "(", "$", "this", "->", "stackPos", ",", "'Has return type'", ",", "'no'", ")", ";", "$", "returnAnnotation", "=", "$", "th...
Check method return type based with its return annotation. @throws CodeWarning @return void
[ "Check", "method", "return", "type", "based", "with", "its", "return", "annotation", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/TypeHints/ReturnTypeDeclarationSniff.php#L325-L335
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/TypeHints/ReturnTypeDeclarationSniff.php
ReturnTypeDeclarationSniff.setUp
protected function setUp(): void { parent::setUp(); if ($this->hasReturnType()) { $this->getFile()->recordMetric($this->stackPos, 'Has return type', 'yes'); } }
php
protected function setUp(): void { parent::setUp(); if ($this->hasReturnType()) { $this->getFile()->recordMetric($this->stackPos, 'Has return type', 'yes'); } }
[ "protected", "function", "setUp", "(", ")", ":", "void", "{", "parent", "::", "setUp", "(", ")", ";", "if", "(", "$", "this", "->", "hasReturnType", "(", ")", ")", "{", "$", "this", "->", "getFile", "(", ")", "->", "recordMetric", "(", "$", "this",...
Sets up the test. @return void
[ "Sets", "up", "the", "test", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/TypeHints/ReturnTypeDeclarationSniff.php#L342-L349
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/TypeHints/ReturnTypeDeclarationSniff.php
ReturnTypeDeclarationSniff.tearDown
protected function tearDown(): void { $this->resetDocCommentPos(); $this->hasReturnType = null; $this->functionName = null; $this->typesForFix = null; }
php
protected function tearDown(): void { $this->resetDocCommentPos(); $this->hasReturnType = null; $this->functionName = null; $this->typesForFix = null; }
[ "protected", "function", "tearDown", "(", ")", ":", "void", "{", "$", "this", "->", "resetDocCommentPos", "(", ")", ";", "$", "this", "->", "hasReturnType", "=", "null", ";", "$", "this", "->", "functionName", "=", "null", ";", "$", "this", "->", "type...
Resets the data of this sniff. @return void
[ "Resets", "the", "data", "of", "this", "sniff", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/TypeHints/ReturnTypeDeclarationSniff.php#L356-L363
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/TypeHints/ReturnTypeDeclarationSniff.php
ReturnTypeDeclarationSniff.validateReturnType
private function validateReturnType(?array $returnTypes): void { if (!$returnTypes) { $returnTypes = []; } $fixableTypes = $this->loadFixableTypes($returnTypes); if (count($returnTypes) === count($fixableTypes)) { // Make sure this var is only filled, if it really is fixable for us. $this->typesForFix = $fixableTypes; } $exception = (new CodeError(static::CODE_MISSING_RETURN_TYPE, self::MESSAGE_MISSING_RETURN_TYPE, $this->stackPos)) ->setPayload([$this->getFunctionName()]); $exception->isFixable((bool) $this->typesForFix); throw $exception; }
php
private function validateReturnType(?array $returnTypes): void { if (!$returnTypes) { $returnTypes = []; } $fixableTypes = $this->loadFixableTypes($returnTypes); if (count($returnTypes) === count($fixableTypes)) { // Make sure this var is only filled, if it really is fixable for us. $this->typesForFix = $fixableTypes; } $exception = (new CodeError(static::CODE_MISSING_RETURN_TYPE, self::MESSAGE_MISSING_RETURN_TYPE, $this->stackPos)) ->setPayload([$this->getFunctionName()]); $exception->isFixable((bool) $this->typesForFix); throw $exception; }
[ "private", "function", "validateReturnType", "(", "?", "array", "$", "returnTypes", ")", ":", "void", "{", "if", "(", "!", "$", "returnTypes", ")", "{", "$", "returnTypes", "=", "[", "]", ";", "}", "$", "fixableTypes", "=", "$", "this", "->", "loadFixa...
Validates the return type and registers an error if there is one. @param array|null $returnTypes @throws CodeWarning @return void
[ "Validates", "the", "return", "type", "and", "registers", "an", "error", "if", "there", "is", "one", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/TypeHints/ReturnTypeDeclarationSniff.php#L373-L393
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/Helper/PropertyHelper.php
PropertyHelper.getProperties
public function getProperties(array $classToken, ?File $file = null): array { if (!$file) { $file = $this->file; } $properties = []; $startPos = $classToken['scope_opener'] ?? 0; $tokens = $file->getTokens(); while (($propertyPos = $file->findNext([T_VARIABLE], $startPos, $classToken['scope_closer'])) > 0) { if ($this->isProperty($propertyPos)) { $properties[] = substr($tokens[$propertyPos]['content'], 1); } $startPos = $propertyPos + 1; } return $properties; }
php
public function getProperties(array $classToken, ?File $file = null): array { if (!$file) { $file = $this->file; } $properties = []; $startPos = $classToken['scope_opener'] ?? 0; $tokens = $file->getTokens(); while (($propertyPos = $file->findNext([T_VARIABLE], $startPos, $classToken['scope_closer'])) > 0) { if ($this->isProperty($propertyPos)) { $properties[] = substr($tokens[$propertyPos]['content'], 1); } $startPos = $propertyPos + 1; } return $properties; }
[ "public", "function", "getProperties", "(", "array", "$", "classToken", ",", "?", "File", "$", "file", "=", "null", ")", ":", "array", "{", "if", "(", "!", "$", "file", ")", "{", "$", "file", "=", "$", "this", "->", "file", ";", "}", "$", "proper...
Returns the names of the class' properties. @param array $classToken The token array for the class like structure. @param File|null $file The used file. If not given then the file from the construct is used. @return array The names of the properties.
[ "Returns", "the", "names", "of", "the", "class", "properties", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/PropertyHelper.php#L43-L62
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/Helper/PropertyHelper.php
PropertyHelper.isProperty
public function isProperty(int $variablePtr): bool { $tokens = $this->file->getTokens(); $propertyPointer = $this->file->findPrevious( [T_STATIC, T_WHITESPACE, T_COMMENT], $variablePtr - 1, null, true ); $propertyToken = $tokens[$propertyPointer]; $propertyCode = $propertyToken['code']; return in_array( $propertyCode, [ T_PRIVATE, T_PROTECTED, T_PUBLIC, T_VAR ], true ); }
php
public function isProperty(int $variablePtr): bool { $tokens = $this->file->getTokens(); $propertyPointer = $this->file->findPrevious( [T_STATIC, T_WHITESPACE, T_COMMENT], $variablePtr - 1, null, true ); $propertyToken = $tokens[$propertyPointer]; $propertyCode = $propertyToken['code']; return in_array( $propertyCode, [ T_PRIVATE, T_PROTECTED, T_PUBLIC, T_VAR ], true ); }
[ "public", "function", "isProperty", "(", "int", "$", "variablePtr", ")", ":", "bool", "{", "$", "tokens", "=", "$", "this", "->", "file", "->", "getTokens", "(", ")", ";", "$", "propertyPointer", "=", "$", "this", "->", "file", "->", "findPrevious", "(...
Determines if the given variable is a property of a class. @param int $variablePtr Pointer to the current variable @return bool Indicator if the current T_VARIABLE is a property of a class
[ "Determines", "if", "the", "given", "variable", "is", "a", "property", "of", "a", "class", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/PropertyHelper.php#L71-L94
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/SuppressingTrait.php
SuppressingTrait.getSniffName
private function getSniffName(?string $sniffName = null): string { $sniffClassName = preg_replace( '/Sniff$/', '', str_replace(['\\', '.Sniffs'], ['.', ''], static::class) ); if ($sniffName) { $sniffClassName .= '.' . $sniffName; } return $sniffClassName; }
php
private function getSniffName(?string $sniffName = null): string { $sniffClassName = preg_replace( '/Sniff$/', '', str_replace(['\\', '.Sniffs'], ['.', ''], static::class) ); if ($sniffName) { $sniffClassName .= '.' . $sniffName; } return $sniffClassName; }
[ "private", "function", "getSniffName", "(", "?", "string", "$", "sniffName", "=", "null", ")", ":", "string", "{", "$", "sniffClassName", "=", "preg_replace", "(", "'/Sniff$/'", ",", "''", ",", "str_replace", "(", "[", "'\\\\'", ",", "'.Sniffs'", "]", ",",...
Get the sniff name. @param string|null $sniffName If there is an optional sniff name. @return string Returns the special sniff name in the code sniffer context.
[ "Get", "the", "sniff", "name", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/SuppressingTrait.php#L39-L52
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/SuppressingTrait.php
SuppressingTrait.isSniffSuppressed
protected function isSniffSuppressed(?string $rule = null, ?int $stackPos = null): bool { return $this->getSuppressHelper()->isSniffSuppressed( $this->getFile(), $stackPos ?? $this->getStackPos(), $this->getSniffName($rule) ); }
php
protected function isSniffSuppressed(?string $rule = null, ?int $stackPos = null): bool { return $this->getSuppressHelper()->isSniffSuppressed( $this->getFile(), $stackPos ?? $this->getStackPos(), $this->getSniffName($rule) ); }
[ "protected", "function", "isSniffSuppressed", "(", "?", "string", "$", "rule", "=", "null", ",", "?", "int", "$", "stackPos", "=", "null", ")", ":", "bool", "{", "return", "$", "this", "->", "getSuppressHelper", "(", ")", "->", "isSniffSuppressed", "(", ...
Returns true if this sniff or a rule of this sniff is suppressed with the slevomat suppress annotation. @param null|string $rule The optional rule. @param int|null $stackPos Do you want ot overload the position for the which position the sniff is suppressed. @return bool Returns true if the sniff is suppressed.
[ "Returns", "true", "if", "this", "sniff", "or", "a", "rule", "of", "this", "sniff", "is", "suppressed", "with", "the", "slevomat", "suppress", "annotation", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/SuppressingTrait.php#L83-L90
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Commenting/RequiredDocBlockSniff.php
RequiredDocBlockSniff.areRequirementsMet
protected function areRequirementsMet(): bool { return ($this->token['code'] !== T_VARIABLE) || (new PropertyHelper($this->file))->isProperty($this->stackPos); }
php
protected function areRequirementsMet(): bool { return ($this->token['code'] !== T_VARIABLE) || (new PropertyHelper($this->file))->isProperty($this->stackPos); }
[ "protected", "function", "areRequirementsMet", "(", ")", ":", "bool", "{", "return", "(", "$", "this", "->", "token", "[", "'code'", "]", "!==", "T_VARIABLE", ")", "||", "(", "new", "PropertyHelper", "(", "$", "this", "->", "file", ")", ")", "->", "isP...
Ignore normal variables for this sniff. @return bool
[ "Ignore", "normal", "variables", "for", "this", "sniff", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Commenting/RequiredDocBlockSniff.php#L73-L76
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Commenting/RequiredDocBlockSniff.php
RequiredDocBlockSniff.checkAndRegisterMissingDocBlock
private function checkAndRegisterMissingDocBlock(): void { if (!$this->getDocCommentPos()) { $tokenIdent = $this->getTokenName(); $exception = (new CodeError( static::CODE_MISSING_DOC_BLOCK_PREFIX . ucfirst($tokenIdent), self::MESSAGE_MISSING_DOC_BLOCK, $this->stackPos ))->setPayload([lcfirst($tokenIdent)]); throw $exception; } }
php
private function checkAndRegisterMissingDocBlock(): void { if (!$this->getDocCommentPos()) { $tokenIdent = $this->getTokenName(); $exception = (new CodeError( static::CODE_MISSING_DOC_BLOCK_PREFIX . ucfirst($tokenIdent), self::MESSAGE_MISSING_DOC_BLOCK, $this->stackPos ))->setPayload([lcfirst($tokenIdent)]); throw $exception; } }
[ "private", "function", "checkAndRegisterMissingDocBlock", "(", ")", ":", "void", "{", "if", "(", "!", "$", "this", "->", "getDocCommentPos", "(", ")", ")", "{", "$", "tokenIdent", "=", "$", "this", "->", "getTokenName", "(", ")", ";", "$", "exception", "...
Checks for a missing doc block and throws an error if the doc is missing. @throws CodeWarning @return void
[ "Checks", "for", "a", "missing", "doc", "block", "and", "throws", "an", "error", "if", "the", "doc", "is", "missing", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Commenting/RequiredDocBlockSniff.php#L85-L98
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Commenting/RequiredDocBlockSniff.php
RequiredDocBlockSniff.checkAndRegisterNoMultiLine
private function checkAndRegisterNoMultiLine(): void { $docCommentPos = $this->getDocCommentPos(); $openingToken = $this->tokens[$docCommentPos]; $closingToken = $this->tokens[$openingToken['comment_closer']]; if ($openingToken['line'] === $closingToken['line']) { $tokenIdent = $this->getTokenName(); $exception = (new CodeError( static::CODE_NO_MULTI_LINE_DOC_BLOCK_PREFIX . ucfirst($tokenIdent), self::MESSAGE_NO_MULTI_LINE_DOC_BLOCK_PREFIX, $docCommentPos ))->setPayload([lcfirst($tokenIdent)]); throw $exception; } }
php
private function checkAndRegisterNoMultiLine(): void { $docCommentPos = $this->getDocCommentPos(); $openingToken = $this->tokens[$docCommentPos]; $closingToken = $this->tokens[$openingToken['comment_closer']]; if ($openingToken['line'] === $closingToken['line']) { $tokenIdent = $this->getTokenName(); $exception = (new CodeError( static::CODE_NO_MULTI_LINE_DOC_BLOCK_PREFIX . ucfirst($tokenIdent), self::MESSAGE_NO_MULTI_LINE_DOC_BLOCK_PREFIX, $docCommentPos ))->setPayload([lcfirst($tokenIdent)]); throw $exception; } }
[ "private", "function", "checkAndRegisterNoMultiLine", "(", ")", ":", "void", "{", "$", "docCommentPos", "=", "$", "this", "->", "getDocCommentPos", "(", ")", ";", "$", "openingToken", "=", "$", "this", "->", "tokens", "[", "$", "docCommentPos", "]", ";", "...
Checks and registers a multi line error. @throws CodeWarning @return void
[ "Checks", "and", "registers", "a", "multi", "line", "error", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Commenting/RequiredDocBlockSniff.php#L107-L124
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Formatting/SpaceAfterDeclareSniff.php
SpaceAfterDeclareSniff.handleNoWhitespaceFound
private function handleNoWhitespaceFound(File $phpcsFile, int $semicolonPtr): void { $fixNoWhitespace = $phpcsFile->addFixableError( self::MESSAGE_NO_WHITESPACE_FOUND, $semicolonPtr, static::CODE_NO_WHITESPACE_FOUND ); if ($fixNoWhitespace) { $phpcsFile->fixer->beginChangeset(); $phpcsFile->fixer->addNewline($semicolonPtr); $phpcsFile->fixer->endChangeset(); } }
php
private function handleNoWhitespaceFound(File $phpcsFile, int $semicolonPtr): void { $fixNoWhitespace = $phpcsFile->addFixableError( self::MESSAGE_NO_WHITESPACE_FOUND, $semicolonPtr, static::CODE_NO_WHITESPACE_FOUND ); if ($fixNoWhitespace) { $phpcsFile->fixer->beginChangeset(); $phpcsFile->fixer->addNewline($semicolonPtr); $phpcsFile->fixer->endChangeset(); } }
[ "private", "function", "handleNoWhitespaceFound", "(", "File", "$", "phpcsFile", ",", "int", "$", "semicolonPtr", ")", ":", "void", "{", "$", "fixNoWhitespace", "=", "$", "phpcsFile", "->", "addFixableError", "(", "self", "::", "MESSAGE_NO_WHITESPACE_FOUND", ",", ...
Handles when no whitespace is found. @param File $phpcsFile The php cs file @param int $semicolonPtr Pointer to the semicolon token @return void
[ "Handles", "when", "no", "whitespace", "is", "found", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Formatting/SpaceAfterDeclareSniff.php#L126-L139
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Formatting/SpaceAfterDeclareSniff.php
SpaceAfterDeclareSniff.handleMuchWhitespacesFound
private function handleMuchWhitespacesFound( File $phpcsFile, int $semicolonPtr, int $secondSpacePtr, int $nextNonSpacePtr ): void { $fixMuchWhitespaces = $phpcsFile->addFixableError( self::MESSAGE_MUCH_WHITESPACE_FOUND, $semicolonPtr, static::CODE_MUCH_WHITESPACE_FOUND ); if ($fixMuchWhitespaces) { $phpcsFile->fixer->beginChangeset(); for ($i = $secondSpacePtr; $i < $nextNonSpacePtr; $i++) { $phpcsFile->fixer->replaceToken($i, ''); } $phpcsFile->fixer->endChangeset(); } }
php
private function handleMuchWhitespacesFound( File $phpcsFile, int $semicolonPtr, int $secondSpacePtr, int $nextNonSpacePtr ): void { $fixMuchWhitespaces = $phpcsFile->addFixableError( self::MESSAGE_MUCH_WHITESPACE_FOUND, $semicolonPtr, static::CODE_MUCH_WHITESPACE_FOUND ); if ($fixMuchWhitespaces) { $phpcsFile->fixer->beginChangeset(); for ($i = $secondSpacePtr; $i < $nextNonSpacePtr; $i++) { $phpcsFile->fixer->replaceToken($i, ''); } $phpcsFile->fixer->endChangeset(); } }
[ "private", "function", "handleMuchWhitespacesFound", "(", "File", "$", "phpcsFile", ",", "int", "$", "semicolonPtr", ",", "int", "$", "secondSpacePtr", ",", "int", "$", "nextNonSpacePtr", ")", ":", "void", "{", "$", "fixMuchWhitespaces", "=", "$", "phpcsFile", ...
Handles when more than one whitespaces are found. @param File $phpcsFile The php cs file @param int $semicolonPtr Pointer to the semicolon @param int $secondSpacePtr Pointer to the second space @param int $nextNonSpacePtr Pointer to the next non space token @return void
[ "Handles", "when", "more", "than", "one", "whitespaces", "are", "found", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Formatting/SpaceAfterDeclareSniff.php#L151-L170
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Formatting/SpaceAfterDeclareSniff.php
SpaceAfterDeclareSniff.handleBlankLineInGroup
private function handleBlankLineInGroup( File $phpcsFile, int $semicolonPtr, int $secondSpacePtr, int $nextNonSpacePtr ): void { $fixGroupBlankLines = $phpcsFile->addFixableError( self::MESSAGE_GROUP_BLANK_LINE_FOUND, $semicolonPtr, static::CODE_GROUP_BLANK_LINE_FOUND ); if ($fixGroupBlankLines) { $phpcsFile->fixer->beginChangeset(); for ($i = $secondSpacePtr; $i < $nextNonSpacePtr; $i++) { $phpcsFile->fixer->replaceToken($i, ''); } $phpcsFile->fixer->endChangeset(); } }
php
private function handleBlankLineInGroup( File $phpcsFile, int $semicolonPtr, int $secondSpacePtr, int $nextNonSpacePtr ): void { $fixGroupBlankLines = $phpcsFile->addFixableError( self::MESSAGE_GROUP_BLANK_LINE_FOUND, $semicolonPtr, static::CODE_GROUP_BLANK_LINE_FOUND ); if ($fixGroupBlankLines) { $phpcsFile->fixer->beginChangeset(); for ($i = $secondSpacePtr; $i < $nextNonSpacePtr; $i++) { $phpcsFile->fixer->replaceToken($i, ''); } $phpcsFile->fixer->endChangeset(); } }
[ "private", "function", "handleBlankLineInGroup", "(", "File", "$", "phpcsFile", ",", "int", "$", "semicolonPtr", ",", "int", "$", "secondSpacePtr", ",", "int", "$", "nextNonSpacePtr", ")", ":", "void", "{", "$", "fixGroupBlankLines", "=", "$", "phpcsFile", "->...
Handles blank lines found in declare group. @param File $phpcsFile The php cs file @param int $semicolonPtr Pointer to the semicolon @param int $secondSpacePtr Pointer to the second space @param int $nextNonSpacePtr Pointer to the next non space token @return void
[ "Handles", "blank", "lines", "found", "in", "declare", "group", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Formatting/SpaceAfterDeclareSniff.php#L182-L201
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Formatting/UCVFSortingSniff.php
UCVFSortingSniff.loadTokensForPositions
private function loadTokensForPositions(array $subTokenPoss): array { $subTokens = array_map(function (int $position): array { return $this->tokens[$position]; }, $subTokenPoss); return array_combine($subTokenPoss, $subTokens); }
php
private function loadTokensForPositions(array $subTokenPoss): array { $subTokens = array_map(function (int $position): array { return $this->tokens[$position]; }, $subTokenPoss); return array_combine($subTokenPoss, $subTokens); }
[ "private", "function", "loadTokensForPositions", "(", "array", "$", "subTokenPoss", ")", ":", "array", "{", "$", "subTokens", "=", "array_map", "(", "function", "(", "int", "$", "position", ")", ":", "array", "{", "return", "$", "this", "->", "tokens", "["...
Loads the tokens for the positions. @param array $subTokenPoss @return array
[ "Loads", "the", "tokens", "for", "the", "positions", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Formatting/UCVFSortingSniff.php#L94-L101
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Formatting/UCVFSortingSniff.php
UCVFSortingSniff.removeUnwantedTokens
private function removeUnwantedTokens(array $subTokens): array { return array_filter($subTokens, function (array $subToken): bool { switch ($subToken['code']) { case T_VARIABLE: $return = (new PropertyHelper($this->file))->isProperty($subToken['pointer']); break; case T_USE: $return = UseStatementHelper::isTraitUse($this->file, $subToken['pointer']); break; default: $return = true; } return $return; }); }
php
private function removeUnwantedTokens(array $subTokens): array { return array_filter($subTokens, function (array $subToken): bool { switch ($subToken['code']) { case T_VARIABLE: $return = (new PropertyHelper($this->file))->isProperty($subToken['pointer']); break; case T_USE: $return = UseStatementHelper::isTraitUse($this->file, $subToken['pointer']); break; default: $return = true; } return $return; }); }
[ "private", "function", "removeUnwantedTokens", "(", "array", "$", "subTokens", ")", ":", "array", "{", "return", "array_filter", "(", "$", "subTokens", ",", "function", "(", "array", "$", "subToken", ")", ":", "bool", "{", "switch", "(", "$", "subToken", "...
Removes inline vars and uses for anon-functions. @param array $subTokens @return array
[ "Removes", "inline", "vars", "and", "uses", "for", "anon", "-", "functions", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Formatting/UCVFSortingSniff.php#L123-L141
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Formatting/UCVFSortingSniff.php
UCVFSortingSniff.validateSorting
private function validateSorting(array $originalTokens, array $sortedTokens): void { $sortedPositions = array_keys($sortedTokens); $sortedIndex = 0; foreach ($originalTokens as $originalPosition => $originalToken) { $sortedPosition = $sortedPositions[$sortedIndex++]; $sortedToken = $sortedTokens[$sortedPosition]; // We don't need an error if the "type block" is the same, so check the code additionally. if (($sortedPosition !== $originalPosition) && ($originalToken['code'] !== $sortedToken['code'])) { $this->file->addError( self::MESSAGE_WRONG_POSITION, $originalPosition, static::CODE_WRONG_POSITION, [ $sortedToken['type'], $sortedToken['content'] ] ); } } }
php
private function validateSorting(array $originalTokens, array $sortedTokens): void { $sortedPositions = array_keys($sortedTokens); $sortedIndex = 0; foreach ($originalTokens as $originalPosition => $originalToken) { $sortedPosition = $sortedPositions[$sortedIndex++]; $sortedToken = $sortedTokens[$sortedPosition]; // We don't need an error if the "type block" is the same, so check the code additionally. if (($sortedPosition !== $originalPosition) && ($originalToken['code'] !== $sortedToken['code'])) { $this->file->addError( self::MESSAGE_WRONG_POSITION, $originalPosition, static::CODE_WRONG_POSITION, [ $sortedToken['type'], $sortedToken['content'] ] ); } } }
[ "private", "function", "validateSorting", "(", "array", "$", "originalTokens", ",", "array", "$", "sortedTokens", ")", ":", "void", "{", "$", "sortedPositions", "=", "array_keys", "(", "$", "sortedTokens", ")", ";", "$", "sortedIndex", "=", "0", ";", "foreac...
Validates the sorting of the tokens and registers an error if wrong sorted. @param array $originalTokens @param array $sortedTokens @return void
[ "Validates", "the", "sorting", "of", "the", "tokens", "and", "registers", "an", "error", "if", "wrong", "sorted", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Formatting/UCVFSortingSniff.php#L190-L212
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Functions/FluentSetterSniff.php
FluentSetterSniff.checkForFluentSetterErrors
private function checkForFluentSetterErrors(File $phpcsFile, int $functionPos, int $classPos): void { $tokens = $phpcsFile->getTokens(); $errorData = $phpcsFile->getDeclarationName($classPos) . '::' . $phpcsFile->getDeclarationName($functionPos); $functionToken = $tokens[$functionPos]; $openBracePtr = $functionToken['scope_opener']; $closeBracePtr = $functionToken['scope_closer']; $returnPtr = $phpcsFile->findNext(T_RETURN, $openBracePtr, $closeBracePtr); if ($returnPtr === false) { $fixNoReturnFound = $phpcsFile->addFixableError( self::ERROR_NO_RETURN_FOUND, $functionPos, static::CODE_NO_RETURN_FOUND, $errorData ); if ($fixNoReturnFound) { $this->fixNoReturnFound($phpcsFile, $closeBracePtr); } return; } $this->checkAndRegisterEmptyReturnErrors($phpcsFile, $functionPos, $returnPtr, $errorData); }
php
private function checkForFluentSetterErrors(File $phpcsFile, int $functionPos, int $classPos): void { $tokens = $phpcsFile->getTokens(); $errorData = $phpcsFile->getDeclarationName($classPos) . '::' . $phpcsFile->getDeclarationName($functionPos); $functionToken = $tokens[$functionPos]; $openBracePtr = $functionToken['scope_opener']; $closeBracePtr = $functionToken['scope_closer']; $returnPtr = $phpcsFile->findNext(T_RETURN, $openBracePtr, $closeBracePtr); if ($returnPtr === false) { $fixNoReturnFound = $phpcsFile->addFixableError( self::ERROR_NO_RETURN_FOUND, $functionPos, static::CODE_NO_RETURN_FOUND, $errorData ); if ($fixNoReturnFound) { $this->fixNoReturnFound($phpcsFile, $closeBracePtr); } return; } $this->checkAndRegisterEmptyReturnErrors($phpcsFile, $functionPos, $returnPtr, $errorData); }
[ "private", "function", "checkForFluentSetterErrors", "(", "File", "$", "phpcsFile", ",", "int", "$", "functionPos", ",", "int", "$", "classPos", ")", ":", "void", "{", "$", "tokens", "=", "$", "phpcsFile", "->", "getTokens", "(", ")", ";", "$", "errorData"...
Checks if there are fluent setter errors and registers errors if needed. @param File $phpcsFile The file for this sniff. @param int $functionPos The position of the used token. @param int $classPos The position of the class. @return void
[ "Checks", "if", "there", "are", "fluent", "setter", "errors", "and", "registers", "errors", "if", "needed", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Functions/FluentSetterSniff.php#L110-L137
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Functions/FluentSetterSniff.php
FluentSetterSniff.processTokenWithinScope
protected function processTokenWithinScope( File $file, $functionPos, $classPos ): void { $this->file = new FileDecorator($file); $this->stackPos = $functionPos; $isSuppressed = $this->isSniffSuppressed(static::CODE_NO_RETURN_FOUND); if (!$isSuppressed && $this->checkIfSetterFunction($classPos, $file, $functionPos)) { $this->checkForFluentSetterErrors($file, $functionPos, $classPos); } }
php
protected function processTokenWithinScope( File $file, $functionPos, $classPos ): void { $this->file = new FileDecorator($file); $this->stackPos = $functionPos; $isSuppressed = $this->isSniffSuppressed(static::CODE_NO_RETURN_FOUND); if (!$isSuppressed && $this->checkIfSetterFunction($classPos, $file, $functionPos)) { $this->checkForFluentSetterErrors($file, $functionPos, $classPos); } }
[ "protected", "function", "processTokenWithinScope", "(", "File", "$", "file", ",", "$", "functionPos", ",", "$", "classPos", ")", ":", "void", "{", "$", "this", "->", "file", "=", "new", "FileDecorator", "(", "$", "file", ")", ";", "$", "this", "->", "...
Processes the tokens that this test is listening for. @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint @param File $file The file where this token was found. @param int $functionPos The position in the stack where this token was found. @param int $classPos The position in the tokens array that opened the scope that this test is listening for. @return void
[ "Processes", "the", "tokens", "that", "this", "test", "is", "listening", "for", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Functions/FluentSetterSniff.php#L169-L182
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Functions/FluentSetterSniff.php
FluentSetterSniff.checkIfSetterFunction
private function checkIfSetterFunction(int $classPosition, File $file, int $methodPosition): bool { $isSetter = false; $methodName = $file->getDeclarationName($methodPosition); if (substr($methodName, 0, 3) === 'set') { // We define in our styleguide, that there is only one class per file! $properties = (new PropertyHelper(new FileDecorator($file)))->getProperties( $file->getTokens()[$classPosition] ); // We require camelCase for methods and properties, // so there should be an "lcfirst-Method" without set-prefix. $isSetter = in_array(lcfirst(substr($methodName, 3)), $properties, true); } return $isSetter; }
php
private function checkIfSetterFunction(int $classPosition, File $file, int $methodPosition): bool { $isSetter = false; $methodName = $file->getDeclarationName($methodPosition); if (substr($methodName, 0, 3) === 'set') { // We define in our styleguide, that there is only one class per file! $properties = (new PropertyHelper(new FileDecorator($file)))->getProperties( $file->getTokens()[$classPosition] ); // We require camelCase for methods and properties, // so there should be an "lcfirst-Method" without set-prefix. $isSetter = in_array(lcfirst(substr($methodName, 3)), $properties, true); } return $isSetter; }
[ "private", "function", "checkIfSetterFunction", "(", "int", "$", "classPosition", ",", "File", "$", "file", ",", "int", "$", "methodPosition", ")", ":", "bool", "{", "$", "isSetter", "=", "false", ";", "$", "methodName", "=", "$", "file", "->", "getDeclara...
Checks if the given method name relates to a setter function of a property. @param int $classPosition The position of the class token. @param File $file The file of the sniff. @param int $methodPosition The position of the method token. @return bool Indicator if the given method is a setter function
[ "Checks", "if", "the", "given", "method", "name", "relates", "to", "a", "setter", "function", "of", "a", "property", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Functions/FluentSetterSniff.php#L193-L210
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Functions/FluentSetterSniff.php
FluentSetterSniff.fixNoReturnFound
private function fixNoReturnFound(File $phpcsFile, int $closingBracePtr): void { $tokens = $phpcsFile->getTokens(); $closingBraceToken = $tokens[$closingBracePtr]; $expectedReturnSpaces = str_repeat($this->identation, $closingBraceToken['level'] + 1); $phpcsFile->fixer->beginChangeset(); $phpcsFile->fixer->addNewlineBefore($closingBracePtr - 1); $phpcsFile->fixer->addContentBefore($closingBracePtr - 1, $expectedReturnSpaces . 'return $this;'); $phpcsFile->fixer->addNewlineBefore($closingBracePtr - 1); $phpcsFile->fixer->endChangeset(); }
php
private function fixNoReturnFound(File $phpcsFile, int $closingBracePtr): void { $tokens = $phpcsFile->getTokens(); $closingBraceToken = $tokens[$closingBracePtr]; $expectedReturnSpaces = str_repeat($this->identation, $closingBraceToken['level'] + 1); $phpcsFile->fixer->beginChangeset(); $phpcsFile->fixer->addNewlineBefore($closingBracePtr - 1); $phpcsFile->fixer->addContentBefore($closingBracePtr - 1, $expectedReturnSpaces . 'return $this;'); $phpcsFile->fixer->addNewlineBefore($closingBracePtr - 1); $phpcsFile->fixer->endChangeset(); }
[ "private", "function", "fixNoReturnFound", "(", "File", "$", "phpcsFile", ",", "int", "$", "closingBracePtr", ")", ":", "void", "{", "$", "tokens", "=", "$", "phpcsFile", "->", "getTokens", "(", ")", ";", "$", "closingBraceToken", "=", "$", "tokens", "[", ...
Fixes if no return statement is found. @param File $phpcsFile The php cs file @param int $closingBracePtr Pointer to the closing curly brace of the function @return void
[ "Fixes", "if", "no", "return", "statement", "is", "found", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Functions/FluentSetterSniff.php#L220-L232
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/CodeWarning.php
CodeWarning.isFixable
public function isFixable(?bool $newStatus = null): bool { $oldStatus = $this->isFixable; if ($newStatus !== null) { $this->isFixable = $newStatus; } return $oldStatus; }
php
public function isFixable(?bool $newStatus = null): bool { $oldStatus = $this->isFixable; if ($newStatus !== null) { $this->isFixable = $newStatus; } return $oldStatus; }
[ "public", "function", "isFixable", "(", "?", "bool", "$", "newStatus", "=", "null", ")", ":", "bool", "{", "$", "oldStatus", "=", "$", "this", "->", "isFixable", ";", "if", "(", "$", "newStatus", "!==", "null", ")", "{", "$", "this", "->", "isFixable...
Is this topic fixable? @param bool|null $newStatus If given the new status. @return bool Returns the "old" status if this is fixable.
[ "Is", "this", "topic", "fixable?" ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/CodeWarning.php#L101-L110
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Functions/MultipleReturnSniff.php
MultipleReturnSniff.loadReturnsOfThisFunction
private function loadReturnsOfThisFunction(): array { $returnPositions = TokenHelper::findNextAll( $this->file->getBaseFile(), [T_RETURN], $this->stackPos + 1, $this->token['scope_closer'] ); return array_filter($returnPositions, function (int $returnPos): bool { $possibleClosure = $this->file->findPrevious([T_CLOSURE, T_FUNCTION], $returnPos - 1, $this->stackPos); return $possibleClosure === $this->stackPos; }); }
php
private function loadReturnsOfThisFunction(): array { $returnPositions = TokenHelper::findNextAll( $this->file->getBaseFile(), [T_RETURN], $this->stackPos + 1, $this->token['scope_closer'] ); return array_filter($returnPositions, function (int $returnPos): bool { $possibleClosure = $this->file->findPrevious([T_CLOSURE, T_FUNCTION], $returnPos - 1, $this->stackPos); return $possibleClosure === $this->stackPos; }); }
[ "private", "function", "loadReturnsOfThisFunction", "(", ")", ":", "array", "{", "$", "returnPositions", "=", "TokenHelper", "::", "findNextAll", "(", "$", "this", "->", "file", "->", "getBaseFile", "(", ")", ",", "[", "T_RETURN", "]", ",", "$", "this", "-...
Returns the returns of this function. We check the "token level" to exclude the returns of nested closures. @return int[] The positions of the returns from the same function-scope.
[ "Returns", "the", "returns", "of", "this", "function", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Functions/MultipleReturnSniff.php#L55-L69
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Functions/MultipleReturnSniff.php
MultipleReturnSniff.processToken
protected function processToken(): void { $returnPositions = $this->loadReturnsOfThisFunction(); if (count($returnPositions) > 1) { array_shift($returnPositions); array_walk($returnPositions, function (int $returnPos): void { $this->file->addWarning( self::WARNING_MULTIPLE_RETURNS_FOUND, $returnPos, static::CODE_MULTIPLE_RETURNS_FOUND ); }); } }
php
protected function processToken(): void { $returnPositions = $this->loadReturnsOfThisFunction(); if (count($returnPositions) > 1) { array_shift($returnPositions); array_walk($returnPositions, function (int $returnPos): void { $this->file->addWarning( self::WARNING_MULTIPLE_RETURNS_FOUND, $returnPos, static::CODE_MULTIPLE_RETURNS_FOUND ); }); } }
[ "protected", "function", "processToken", "(", ")", ":", "void", "{", "$", "returnPositions", "=", "$", "this", "->", "loadReturnsOfThisFunction", "(", ")", ";", "if", "(", "count", "(", "$", "returnPositions", ")", ">", "1", ")", "{", "array_shift", "(", ...
Iterates through the returns of this function and registers warnings if there is more then one relevant return. @return void
[ "Iterates", "through", "the", "returns", "of", "this", "function", "and", "registers", "warnings", "if", "there", "is", "more", "then", "one", "relevant", "return", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Functions/MultipleReturnSniff.php#L76-L91
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/NamingConventions/CamelCaseVariableSniff.php
CamelCaseVariableSniff.areRequirementsMet
protected function areRequirementsMet(): bool { $var = $this->token['content']; // We need to check everything != $this. if ($return = $var !== '$this') { $nextPos = (int) TokenHelper::findNextEffective($this->file->getBaseFile(), $this->stackPos + 1); if ($nextPos > 0) { $isProperty = PropertyHelper::isProperty($this->file->getBaseFile(), $this->stackPos); $nextTokenCode = $this->tokens[$nextPos]['code']; // The var should be followed by an "=" or can be followed by a semicolon if its a property. $return = ($nextTokenCode === T_EQUAL) || ($nextTokenCode === T_SEMICOLON && $isProperty); } } return $return; }
php
protected function areRequirementsMet(): bool { $var = $this->token['content']; // We need to check everything != $this. if ($return = $var !== '$this') { $nextPos = (int) TokenHelper::findNextEffective($this->file->getBaseFile(), $this->stackPos + 1); if ($nextPos > 0) { $isProperty = PropertyHelper::isProperty($this->file->getBaseFile(), $this->stackPos); $nextTokenCode = $this->tokens[$nextPos]['code']; // The var should be followed by an "=" or can be followed by a semicolon if its a property. $return = ($nextTokenCode === T_EQUAL) || ($nextTokenCode === T_SEMICOLON && $isProperty); } } return $return; }
[ "protected", "function", "areRequirementsMet", "(", ")", ":", "bool", "{", "$", "var", "=", "$", "this", "->", "token", "[", "'content'", "]", ";", "// We need to check everything != $this.", "if", "(", "$", "return", "=", "$", "var", "!==", "'$this'", ")", ...
Returns true if there is a value assignment or a property declaration, but which can be without an assignment. @return bool
[ "Returns", "true", "if", "there", "is", "a", "value", "assignment", "or", "a", "property", "declaration", "but", "which", "can", "be", "without", "an", "assignment", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/NamingConventions/CamelCaseVariableSniff.php#L60-L78
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/NamingConventions/CamelCaseVariableSniff.php
CamelCaseVariableSniff.tearDown
protected function tearDown(): void { parent::tearDown(); if ($this->prevSniffedFile && $this->prevSniffedFile !== $this->file->getFilename()) { $this->sniffedVars = []; $this->prevSniffedFile = ''; } }
php
protected function tearDown(): void { parent::tearDown(); if ($this->prevSniffedFile && $this->prevSniffedFile !== $this->file->getFilename()) { $this->sniffedVars = []; $this->prevSniffedFile = ''; } }
[ "protected", "function", "tearDown", "(", ")", ":", "void", "{", "parent", "::", "tearDown", "(", ")", ";", "if", "(", "$", "this", "->", "prevSniffedFile", "&&", "$", "this", "->", "prevSniffedFile", "!==", "$", "this", "->", "file", "->", "getFilename"...
Cleans the cache of this sniff. @return void
[ "Cleans", "the", "cache", "of", "this", "sniff", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/NamingConventions/CamelCaseVariableSniff.php#L130-L138
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/ParamTagSniff.php
ParamTagSniff.checkAgainstPattern
private function checkAgainstPattern(?string $tagContent = null): bool { if (!$return = $this->isValidContent($tagContent)) { throw (new CodeError(static::CODE_TAG_MISSING_VARIABLE, self::MESSAGE_TAG_MISSING_VARIABLE, $this->stackPos)) ->setPayload([$tagContent]) ->setToken($this->token); } return $return; }
php
private function checkAgainstPattern(?string $tagContent = null): bool { if (!$return = $this->isValidContent($tagContent)) { throw (new CodeError(static::CODE_TAG_MISSING_VARIABLE, self::MESSAGE_TAG_MISSING_VARIABLE, $this->stackPos)) ->setPayload([$tagContent]) ->setToken($this->token); } return $return; }
[ "private", "function", "checkAgainstPattern", "(", "?", "string", "$", "tagContent", "=", "null", ")", ":", "bool", "{", "if", "(", "!", "$", "return", "=", "$", "this", "->", "isValidContent", "(", "$", "tagContent", ")", ")", "{", "throw", "(", "new"...
Simple check if the pattern is correct. @param string|null $tagContent @throws CodeWarning @return bool True if it matches.
[ "Simple", "check", "if", "the", "pattern", "is", "correct", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/ParamTagSniff.php#L109-L118
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/ParamTagSniff.php
ParamTagSniff.checkArgumentItself
private function checkArgumentItself(?string $tagContent = null): void { if (!$this->getArgumentTokenOfTag()) { throw (new CodeError( static::CODE_TAG_MISSING_VARIABLE, self::MESSAGE_TAG_MISSING_VARIABLE, $this->stackPos )) ->setPayload([$tagContent]) ->setToken($this->token); } }
php
private function checkArgumentItself(?string $tagContent = null): void { if (!$this->getArgumentTokenOfTag()) { throw (new CodeError( static::CODE_TAG_MISSING_VARIABLE, self::MESSAGE_TAG_MISSING_VARIABLE, $this->stackPos )) ->setPayload([$tagContent]) ->setToken($this->token); } }
[ "private", "function", "checkArgumentItself", "(", "?", "string", "$", "tagContent", "=", "null", ")", ":", "void", "{", "if", "(", "!", "$", "this", "->", "getArgumentTokenOfTag", "(", ")", ")", "{", "throw", "(", "new", "CodeError", "(", "static", "::"...
Checks if the argument of the function itself exists. @param null|string $tagContent @throws CodeWarning @return void
[ "Checks", "if", "the", "argument", "of", "the", "function", "itself", "exists", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/ParamTagSniff.php#L128-L139
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/ParamTagSniff.php
ParamTagSniff.checkDescription
private function checkDescription(): bool { if (($hasNoDesc = !@$this->matches['desc']) && ($this->descAsWarning)) { throw (new CodeWarning(static::CODE_TAG_MISSING_DESC, self::MESSAGE_TAG_MISSING_DESC, $this->stackPos)) ->setPayload([$this->matches['var']]) ->setToken($this->token); } return !$hasNoDesc; }
php
private function checkDescription(): bool { if (($hasNoDesc = !@$this->matches['desc']) && ($this->descAsWarning)) { throw (new CodeWarning(static::CODE_TAG_MISSING_DESC, self::MESSAGE_TAG_MISSING_DESC, $this->stackPos)) ->setPayload([$this->matches['var']]) ->setToken($this->token); } return !$hasNoDesc; }
[ "private", "function", "checkDescription", "(", ")", ":", "bool", "{", "if", "(", "(", "$", "hasNoDesc", "=", "!", "@", "$", "this", "->", "matches", "[", "'desc'", "]", ")", "&&", "(", "$", "this", "->", "descAsWarning", ")", ")", "{", "throw", "(...
Checks if the param contains a description. @throws CodeWarning @return bool|null Returns true if there is a desc.
[ "Checks", "if", "the", "param", "contains", "a", "description", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/ParamTagSniff.php#L148-L157
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/ParamTagSniff.php
ParamTagSniff.checkType
private function checkType(): bool { if (!@$this->matches['type']) { throw (new CodeError(static::CODE_TAG_MISSING_TYPE, self::MESSAGE_TAG_MISSING_TYPE, $this->stackPos)) ->setPayload([$this->matches['var']]) ->setToken($this->token); } if (strtolower($this->matches['type']) === 'mixed') { throw (new CodeWarning(static::CODE_TAG_MIXED_TYPE, self::MESSAGE_TAG_MIXED_TYPE, $this->stackPos)) ->setToken($this->token); } return true; }
php
private function checkType(): bool { if (!@$this->matches['type']) { throw (new CodeError(static::CODE_TAG_MISSING_TYPE, self::MESSAGE_TAG_MISSING_TYPE, $this->stackPos)) ->setPayload([$this->matches['var']]) ->setToken($this->token); } if (strtolower($this->matches['type']) === 'mixed') { throw (new CodeWarning(static::CODE_TAG_MIXED_TYPE, self::MESSAGE_TAG_MIXED_TYPE, $this->stackPos)) ->setToken($this->token); } return true; }
[ "private", "function", "checkType", "(", ")", ":", "bool", "{", "if", "(", "!", "@", "$", "this", "->", "matches", "[", "'type'", "]", ")", "{", "throw", "(", "new", "CodeError", "(", "static", "::", "CODE_TAG_MISSING_TYPE", ",", "self", "::", "MESSAGE...
Checks if the param tag contains a valid type. @throws CodeWarning @return bool True if the type is valid.
[ "Checks", "if", "the", "param", "tag", "contains", "a", "valid", "type", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/ParamTagSniff.php#L166-L181
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/ParamTagSniff.php
ParamTagSniff.findAllVariablePositions
protected function findAllVariablePositions(): array { return TokenHelper::findNextAll( $this->file->getBaseFile(), [T_VARIABLE], $this->stackPos + 1, $this->file->findNext([T_CLOSE_PARENTHESIS], $this->stackPos + 1) ); }
php
protected function findAllVariablePositions(): array { return TokenHelper::findNextAll( $this->file->getBaseFile(), [T_VARIABLE], $this->stackPos + 1, $this->file->findNext([T_CLOSE_PARENTHESIS], $this->stackPos + 1) ); }
[ "protected", "function", "findAllVariablePositions", "(", ")", ":", "array", "{", "return", "TokenHelper", "::", "findNextAll", "(", "$", "this", "->", "file", "->", "getBaseFile", "(", ")", ",", "[", "T_VARIABLE", "]", ",", "$", "this", "->", "stackPos", ...
Loads all variables of the following method. @return array
[ "Loads", "all", "variables", "of", "the", "following", "method", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/ParamTagSniff.php#L188-L196
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/ParamTagSniff.php
ParamTagSniff.getArgumentTokenOfTag
private function getArgumentTokenOfTag(): array { if ($this->argumentToken === null) { $this->argumentToken = $this->loadArgumentTokenOfTag(); } return $this->argumentToken; }
php
private function getArgumentTokenOfTag(): array { if ($this->argumentToken === null) { $this->argumentToken = $this->loadArgumentTokenOfTag(); } return $this->argumentToken; }
[ "private", "function", "getArgumentTokenOfTag", "(", ")", ":", "array", "{", "if", "(", "$", "this", "->", "argumentToken", "===", "null", ")", "{", "$", "this", "->", "argumentToken", "=", "$", "this", "->", "loadArgumentTokenOfTag", "(", ")", ";", "}", ...
Returns the name of the real function argument for this parameter tag. @return array Null if there is no matching function argument.
[ "Returns", "the", "name", "of", "the", "real", "function", "argument", "for", "this", "parameter", "tag", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/ParamTagSniff.php#L216-L223
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/ParamTagSniff.php
ParamTagSniff.loadAndCheckVarPositions
private function loadAndCheckVarPositions(): array { $varPositions = $this->findAllVariablePositions(); if (!$varPositions) { throw (new CodeError( static::CODE_TAG_MISSING_VARIABLES, self::MESSAGE_TAG_MISSING_VARIABLES, $this->stackPos ))->setToken($this->token); } $this->varTokens = array_filter($this->tokens, function (array $token) use ($varPositions): bool { return in_array($token['pointer'], $varPositions, true); }); return $varPositions; }
php
private function loadAndCheckVarPositions(): array { $varPositions = $this->findAllVariablePositions(); if (!$varPositions) { throw (new CodeError( static::CODE_TAG_MISSING_VARIABLES, self::MESSAGE_TAG_MISSING_VARIABLES, $this->stackPos ))->setToken($this->token); } $this->varTokens = array_filter($this->tokens, function (array $token) use ($varPositions): bool { return in_array($token['pointer'], $varPositions, true); }); return $varPositions; }
[ "private", "function", "loadAndCheckVarPositions", "(", ")", ":", "array", "{", "$", "varPositions", "=", "$", "this", "->", "findAllVariablePositions", "(", ")", ";", "if", "(", "!", "$", "varPositions", ")", "{", "throw", "(", "new", "CodeError", "(", "s...
Loads and checks the variables of the following method. @throws CodeWarning We have param tags, so there should be variables in the method. @return array The positions of the methods variables if there are any.
[ "Loads", "and", "checks", "the", "variables", "of", "the", "following", "method", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/ParamTagSniff.php#L232-L249
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/ParamTagSniff.php
ParamTagSniff.loadArgumentTokenOfTag
private function loadArgumentTokenOfTag(): array { // Give me the other tags of this doc block before this one. $tagPosBeforeThis = TokenHelper::findNextAll( $this->file->getBaseFile(), $this->register(), $this->file->findPrevious([T_DOC_COMMENT_OPEN_TAG], $this->stackPos), $this->stackPos - 1 ); $tagPosBeforeThis = array_filter($tagPosBeforeThis, function (int $position) { return $this->tokens[$position]['content'] === '@param'; }); return (array_values($this->varTokens)[count($tagPosBeforeThis)]) ?? []; }
php
private function loadArgumentTokenOfTag(): array { // Give me the other tags of this doc block before this one. $tagPosBeforeThis = TokenHelper::findNextAll( $this->file->getBaseFile(), $this->register(), $this->file->findPrevious([T_DOC_COMMENT_OPEN_TAG], $this->stackPos), $this->stackPos - 1 ); $tagPosBeforeThis = array_filter($tagPosBeforeThis, function (int $position) { return $this->tokens[$position]['content'] === '@param'; }); return (array_values($this->varTokens)[count($tagPosBeforeThis)]) ?? []; }
[ "private", "function", "loadArgumentTokenOfTag", "(", ")", ":", "array", "{", "// Give me the other tags of this doc block before this one.", "$", "tagPosBeforeThis", "=", "TokenHelper", "::", "findNextAll", "(", "$", "this", "->", "file", "->", "getBaseFile", "(", ")",...
Loads the function argument of this tag. @return array
[ "Loads", "the", "function", "argument", "of", "this", "tag", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/ParamTagSniff.php#L256-L271
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/Helper/DocDescriptionHelper.php
DocDescriptionHelper.checkCommentDescription
public function checkCommentDescription(bool $descriptionRequired): void { $this->descriptionRequired = $descriptionRequired; $commentStartToken = $this->docHelper->getBlockStartToken(); $commentEndToken = $this->docHelper->getBlockEndToken(); $summaryPtr = $this->summaryHelper->getCommentSummaryPosition(); if ($summaryPtr === -1) { return; } $hasTags = count($commentStartToken['comment_tags']) > 0; $descriptionStartPtr = $this->getCommentDescriptionStartPointer(); if ($descriptionStartPtr === -1) { $this->addDescriptionNotFoundError($summaryPtr); return; } $descriptionEndPtr = $this->getCommentDescriptionEndPointer(); $descEndToken = $this->tokens[$descriptionEndPtr]; $this->checkCommentDescriptionUcFirst($descriptionStartPtr); //Fix no or too much lines after description. $toLine = $commentEndToken['line']; $expectedLines = 0; if ($hasTags) { $firstTagPtr = array_shift($commentStartToken['comment_tags']); $firstTagToken = $this->tokens[$firstTagPtr]; $toLine = $firstTagToken['line']; $expectedLines = 1; } $diffLines = $toLine - $descEndToken['line'] - 1; if ($diffLines === $expectedLines) { return; } if ($diffLines < $expectedLines && $hasTags) { $fixNoLine = $this->file->addFixableError( AbstractDocSniff::MESSAGE_NO_LINE_AFTER_DESCRIPTION, $descriptionEndPtr, AbstractDocSniff::CODE_NO_LINE_AFTER_DESCRIPTION ); if ($fixNoLine) { $this->fixNoLineAfterDescription(); } return; } $fixMuchLines = $this->file->addFixableError( AbstractDocSniff::MESSAGE_MUCH_LINES_AFTER_DESCRIPTION, $descriptionEndPtr, AbstractDocSniff::CODE_MUCH_LINES_AFTER_DESCRIPTION ); if ($fixMuchLines) { $this->fixMuchLinesAfterDescription($descEndToken['line'] + 1, $toLine - 1); } }
php
public function checkCommentDescription(bool $descriptionRequired): void { $this->descriptionRequired = $descriptionRequired; $commentStartToken = $this->docHelper->getBlockStartToken(); $commentEndToken = $this->docHelper->getBlockEndToken(); $summaryPtr = $this->summaryHelper->getCommentSummaryPosition(); if ($summaryPtr === -1) { return; } $hasTags = count($commentStartToken['comment_tags']) > 0; $descriptionStartPtr = $this->getCommentDescriptionStartPointer(); if ($descriptionStartPtr === -1) { $this->addDescriptionNotFoundError($summaryPtr); return; } $descriptionEndPtr = $this->getCommentDescriptionEndPointer(); $descEndToken = $this->tokens[$descriptionEndPtr]; $this->checkCommentDescriptionUcFirst($descriptionStartPtr); //Fix no or too much lines after description. $toLine = $commentEndToken['line']; $expectedLines = 0; if ($hasTags) { $firstTagPtr = array_shift($commentStartToken['comment_tags']); $firstTagToken = $this->tokens[$firstTagPtr]; $toLine = $firstTagToken['line']; $expectedLines = 1; } $diffLines = $toLine - $descEndToken['line'] - 1; if ($diffLines === $expectedLines) { return; } if ($diffLines < $expectedLines && $hasTags) { $fixNoLine = $this->file->addFixableError( AbstractDocSniff::MESSAGE_NO_LINE_AFTER_DESCRIPTION, $descriptionEndPtr, AbstractDocSniff::CODE_NO_LINE_AFTER_DESCRIPTION ); if ($fixNoLine) { $this->fixNoLineAfterDescription(); } return; } $fixMuchLines = $this->file->addFixableError( AbstractDocSniff::MESSAGE_MUCH_LINES_AFTER_DESCRIPTION, $descriptionEndPtr, AbstractDocSniff::CODE_MUCH_LINES_AFTER_DESCRIPTION ); if ($fixMuchLines) { $this->fixMuchLinesAfterDescription($descEndToken['line'] + 1, $toLine - 1); } }
[ "public", "function", "checkCommentDescription", "(", "bool", "$", "descriptionRequired", ")", ":", "void", "{", "$", "this", "->", "descriptionRequired", "=", "$", "descriptionRequired", ";", "$", "commentStartToken", "=", "$", "this", "->", "docHelper", "->", ...
Checks for comment description. @param bool $descriptionRequired Indicator if the description is required. @return void
[ "Checks", "for", "comment", "description", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/DocDescriptionHelper.php#L75-L144
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/Helper/DocDescriptionHelper.php
DocDescriptionHelper.checkCommentDescriptionUcFirst
private function checkCommentDescriptionUcFirst(int $descriptionStartPtr): void { $descStartToken = $this->tokens[$descriptionStartPtr]; $descriptionContent = $descStartToken['content']; if (ucfirst($descriptionContent) === $descriptionContent) { return; } $fixUcFirst = $this->file->addFixableError( AbstractDocSniff::MESSAGE_DESCRIPTION_UC_FIRST, $descriptionStartPtr, AbstractDocSniff::CODE_DESCRIPTION_UC_FIRST ); if ($fixUcFirst) { $this->fixDescriptionUcFirst($descriptionStartPtr); } }
php
private function checkCommentDescriptionUcFirst(int $descriptionStartPtr): void { $descStartToken = $this->tokens[$descriptionStartPtr]; $descriptionContent = $descStartToken['content']; if (ucfirst($descriptionContent) === $descriptionContent) { return; } $fixUcFirst = $this->file->addFixableError( AbstractDocSniff::MESSAGE_DESCRIPTION_UC_FIRST, $descriptionStartPtr, AbstractDocSniff::CODE_DESCRIPTION_UC_FIRST ); if ($fixUcFirst) { $this->fixDescriptionUcFirst($descriptionStartPtr); } }
[ "private", "function", "checkCommentDescriptionUcFirst", "(", "int", "$", "descriptionStartPtr", ")", ":", "void", "{", "$", "descStartToken", "=", "$", "this", "->", "tokens", "[", "$", "descriptionStartPtr", "]", ";", "$", "descriptionContent", "=", "$", "desc...
Checks if the description starts with a capital letter. @param int $descriptionStartPtr Pointer to the start of the description. @return void
[ "Checks", "if", "the", "description", "starts", "with", "a", "capital", "letter", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/DocDescriptionHelper.php#L153-L172
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/Helper/DocDescriptionHelper.php
DocDescriptionHelper.getCommentDescriptionEndPointer
private function getCommentDescriptionEndPointer(): int { $descriptionStartPtr = $this->getCommentDescriptionStartPointer(); $commentStartToken = $this->docHelper->getBlockStartToken(); $commentEndPtr = $this->docHelper->getBlockEndPosition(); //If no tags found, possible end of search is the starting tag of the doc comment. if (count($commentStartToken['comment_tags']) === 0) { return $this->file->findPrevious( [T_DOC_COMMENT_STRING], $commentEndPtr - 1, $descriptionStartPtr ); } //else its the pointer of the first comment tag found. $firstTagPtr = array_shift($commentStartToken['comment_tags']); return $this->file->findPrevious( [T_DOC_COMMENT_STRING], $firstTagPtr - 1, $descriptionStartPtr ); }
php
private function getCommentDescriptionEndPointer(): int { $descriptionStartPtr = $this->getCommentDescriptionStartPointer(); $commentStartToken = $this->docHelper->getBlockStartToken(); $commentEndPtr = $this->docHelper->getBlockEndPosition(); //If no tags found, possible end of search is the starting tag of the doc comment. if (count($commentStartToken['comment_tags']) === 0) { return $this->file->findPrevious( [T_DOC_COMMENT_STRING], $commentEndPtr - 1, $descriptionStartPtr ); } //else its the pointer of the first comment tag found. $firstTagPtr = array_shift($commentStartToken['comment_tags']); return $this->file->findPrevious( [T_DOC_COMMENT_STRING], $firstTagPtr - 1, $descriptionStartPtr ); }
[ "private", "function", "getCommentDescriptionEndPointer", "(", ")", ":", "int", "{", "$", "descriptionStartPtr", "=", "$", "this", "->", "getCommentDescriptionStartPointer", "(", ")", ";", "$", "commentStartToken", "=", "$", "this", "->", "docHelper", "->", "getBl...
Returns pointer to the end of the description. @return int Pointer to the end of the description or false
[ "Returns", "pointer", "to", "the", "end", "of", "the", "description", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/DocDescriptionHelper.php#L179-L203
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/Helper/DocDescriptionHelper.php
DocDescriptionHelper.getCommentDescriptionStartPointer
private function getCommentDescriptionStartPointer(): int { $commentStartToken = $this->docHelper->getBlockStartToken(); $commentEndPtr = $this->docHelper->getBlockEndPosition(); $summaryPtr = $this->summaryHelper->getCommentSummaryPosition(); //If no tags the possible end of search is the closing tag of the doc comment. if (count($commentStartToken['comment_tags']) === 0) { return $this->file->findNext( [T_DOC_COMMENT_STRING], $summaryPtr + 1, $commentEndPtr ); } //else its the pointer of the first comment tag found. $firstTagPtr = array_shift($commentStartToken['comment_tags']); return $this->file->findNext( [T_DOC_COMMENT_STRING], $summaryPtr + 1, $firstTagPtr - 1 ); }
php
private function getCommentDescriptionStartPointer(): int { $commentStartToken = $this->docHelper->getBlockStartToken(); $commentEndPtr = $this->docHelper->getBlockEndPosition(); $summaryPtr = $this->summaryHelper->getCommentSummaryPosition(); //If no tags the possible end of search is the closing tag of the doc comment. if (count($commentStartToken['comment_tags']) === 0) { return $this->file->findNext( [T_DOC_COMMENT_STRING], $summaryPtr + 1, $commentEndPtr ); } //else its the pointer of the first comment tag found. $firstTagPtr = array_shift($commentStartToken['comment_tags']); return $this->file->findNext( [T_DOC_COMMENT_STRING], $summaryPtr + 1, $firstTagPtr - 1 ); }
[ "private", "function", "getCommentDescriptionStartPointer", "(", ")", ":", "int", "{", "$", "commentStartToken", "=", "$", "this", "->", "docHelper", "->", "getBlockStartToken", "(", ")", ";", "$", "commentEndPtr", "=", "$", "this", "->", "docHelper", "->", "g...
Returns pointer to the start of the long description or false if not found. @return int Pointer to the start of the description or -1
[ "Returns", "pointer", "to", "the", "start", "of", "the", "long", "description", "or", "false", "if", "not", "found", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/DocDescriptionHelper.php#L210-L234
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/Helper/DocDescriptionHelper.php
DocDescriptionHelper.addDescriptionNotFoundError
private function addDescriptionNotFoundError(int $summaryPtr): void { if ($this->descriptionRequired) { $this->file->addError( AbstractDocSniff::MESSAGE_DESCRIPTION_NOT_FOUND, $summaryPtr, AbstractDocSniff::CODE_DESCRIPTION_NOT_FOUND ); } }
php
private function addDescriptionNotFoundError(int $summaryPtr): void { if ($this->descriptionRequired) { $this->file->addError( AbstractDocSniff::MESSAGE_DESCRIPTION_NOT_FOUND, $summaryPtr, AbstractDocSniff::CODE_DESCRIPTION_NOT_FOUND ); } }
[ "private", "function", "addDescriptionNotFoundError", "(", "int", "$", "summaryPtr", ")", ":", "void", "{", "if", "(", "$", "this", "->", "descriptionRequired", ")", "{", "$", "this", "->", "file", "->", "addError", "(", "AbstractDocSniff", "::", "MESSAGE_DESC...
Adds error when description is not found. @param int $summaryPtr Pointer to summary token. @return void
[ "Adds", "error", "when", "description", "is", "not", "found", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/DocDescriptionHelper.php#L243-L252
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/Helper/DocDescriptionHelper.php
DocDescriptionHelper.fixNoLineAfterDescription
private function fixNoLineAfterDescription(): void { $descEndPtr = $this->getCommentDescriptionEndPointer(); $descEndToken = $this->tokens[$descEndPtr]; $this->file->getFixer()->beginChangeset(); $this->file->getFixer()->addContent( $descEndPtr, $this->file->getEolChar() . str_repeat(' ', $descEndToken['level']) . ' *' ); $this->file->getFixer()->endChangeset(); }
php
private function fixNoLineAfterDescription(): void { $descEndPtr = $this->getCommentDescriptionEndPointer(); $descEndToken = $this->tokens[$descEndPtr]; $this->file->getFixer()->beginChangeset(); $this->file->getFixer()->addContent( $descEndPtr, $this->file->getEolChar() . str_repeat(' ', $descEndToken['level']) . ' *' ); $this->file->getFixer()->endChangeset(); }
[ "private", "function", "fixNoLineAfterDescription", "(", ")", ":", "void", "{", "$", "descEndPtr", "=", "$", "this", "->", "getCommentDescriptionEndPointer", "(", ")", ";", "$", "descEndToken", "=", "$", "this", "->", "tokens", "[", "$", "descEndPtr", "]", "...
Fixes no line after description. @return void
[ "Fixes", "no", "line", "after", "description", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/DocDescriptionHelper.php#L259-L272
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/Helper/DocDescriptionHelper.php
DocDescriptionHelper.fixMuchLinesAfterDescription
private function fixMuchLinesAfterDescription(int $startLine, int $endLine): void { $this->file->getFixer()->beginChangeset(); (new LineHelper($this->file))->removeLines($startLine, $endLine); $this->file->getFixer()->endChangeset(); }
php
private function fixMuchLinesAfterDescription(int $startLine, int $endLine): void { $this->file->getFixer()->beginChangeset(); (new LineHelper($this->file))->removeLines($startLine, $endLine); $this->file->getFixer()->endChangeset(); }
[ "private", "function", "fixMuchLinesAfterDescription", "(", "int", "$", "startLine", ",", "int", "$", "endLine", ")", ":", "void", "{", "$", "this", "->", "file", "->", "getFixer", "(", ")", "->", "beginChangeset", "(", ")", ";", "(", "new", "LineHelper", ...
Fixes much lines after description. @param int $startLine Line to start removing @param int $endLine Line to end removing @return void
[ "Fixes", "much", "lines", "after", "description", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/DocDescriptionHelper.php#L282-L289
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/Helper/DocDescriptionHelper.php
DocDescriptionHelper.fixDescriptionUcFirst
private function fixDescriptionUcFirst(int $descriptionStartPtr): void { $descStartToken = $this->tokens[$descriptionStartPtr]; $this->file->getFixer()->beginChangeset(); $this->file->getFixer()->replaceToken( $descriptionStartPtr, ucfirst($descStartToken['content']) ); $this->file->getFixer()->endChangeset(); }
php
private function fixDescriptionUcFirst(int $descriptionStartPtr): void { $descStartToken = $this->tokens[$descriptionStartPtr]; $this->file->getFixer()->beginChangeset(); $this->file->getFixer()->replaceToken( $descriptionStartPtr, ucfirst($descStartToken['content']) ); $this->file->getFixer()->endChangeset(); }
[ "private", "function", "fixDescriptionUcFirst", "(", "int", "$", "descriptionStartPtr", ")", ":", "void", "{", "$", "descStartToken", "=", "$", "this", "->", "tokens", "[", "$", "descriptionStartPtr", "]", ";", "$", "this", "->", "file", "->", "getFixer", "(...
Fixes the description uc first. @param int $descriptionStartPtr Pointer to the description start @return void
[ "Fixes", "the", "description", "uc", "first", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/DocDescriptionHelper.php#L298-L310
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Formatting/TraitUseDeclarationSniff.php
TraitUseDeclarationSniff.checkDeclaration
private function checkDeclaration(int $usePos): void { $file = $this->getFile()->getBaseFile(); if (TokenHelper::findNextLocal($file, T_COMMA, $usePos + 1)) { $endPos = TokenHelper::findNext($file, [T_OPEN_CURLY_BRACKET, T_SEMICOLON], $usePos + 1); $tokens = $file->getTokens(); if ($tokens[$endPos]['code'] === T_OPEN_CURLY_BRACKET) { $file->addError( self::MESSAGE_MULTIPLE_TRAITS_PER_DECLARATION, $usePos, static::CODE_MULTIPLE_TRAITS_PER_DECLARATION ); } else { $fix = $file->addFixableError( self::MESSAGE_MULTIPLE_TRAITS_PER_DECLARATION, $usePos, static::CODE_MULTIPLE_TRAITS_PER_DECLARATION ); if ($fix) { $this->fixeUse($endPos, $usePos); } } } }
php
private function checkDeclaration(int $usePos): void { $file = $this->getFile()->getBaseFile(); if (TokenHelper::findNextLocal($file, T_COMMA, $usePos + 1)) { $endPos = TokenHelper::findNext($file, [T_OPEN_CURLY_BRACKET, T_SEMICOLON], $usePos + 1); $tokens = $file->getTokens(); if ($tokens[$endPos]['code'] === T_OPEN_CURLY_BRACKET) { $file->addError( self::MESSAGE_MULTIPLE_TRAITS_PER_DECLARATION, $usePos, static::CODE_MULTIPLE_TRAITS_PER_DECLARATION ); } else { $fix = $file->addFixableError( self::MESSAGE_MULTIPLE_TRAITS_PER_DECLARATION, $usePos, static::CODE_MULTIPLE_TRAITS_PER_DECLARATION ); if ($fix) { $this->fixeUse($endPos, $usePos); } } } }
[ "private", "function", "checkDeclaration", "(", "int", "$", "usePos", ")", ":", "void", "{", "$", "file", "=", "$", "this", "->", "getFile", "(", ")", "->", "getBaseFile", "(", ")", ";", "if", "(", "TokenHelper", "::", "findNextLocal", "(", "$", "file"...
Checks the declaration of the given use position and registers and error if needed. @param int $usePos @return void
[ "Checks", "the", "declaration", "of", "the", "given", "use", "position", "and", "registers", "and", "error", "if", "needed", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Formatting/TraitUseDeclarationSniff.php#L60-L86
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Formatting/TraitUseDeclarationSniff.php
TraitUseDeclarationSniff.fixeUse
protected function fixeUse(int $endPos, int $usePos): void { $indentation = $this->getIndentationForFix($usePos); $file = $this->getFile()->getBaseFile(); $fixer = $file->fixer; $fixer->beginChangeset(); $commaPointers = TokenHelper::findNextAll($file, T_COMMA, $usePos + 1, $endPos); foreach ($commaPointers as $commaPos) { $pointerAfterComma = TokenHelper::findNextEffective($file, $commaPos + 1); $fixer->replaceToken($commaPos, ';' . $file->eolChar . $indentation . 'use '); for ($i = $commaPos + 1; $i < $pointerAfterComma; $i++) { $fixer->replaceToken($i, ''); } } $fixer->endChangeset(); }
php
protected function fixeUse(int $endPos, int $usePos): void { $indentation = $this->getIndentationForFix($usePos); $file = $this->getFile()->getBaseFile(); $fixer = $file->fixer; $fixer->beginChangeset(); $commaPointers = TokenHelper::findNextAll($file, T_COMMA, $usePos + 1, $endPos); foreach ($commaPointers as $commaPos) { $pointerAfterComma = TokenHelper::findNextEffective($file, $commaPos + 1); $fixer->replaceToken($commaPos, ';' . $file->eolChar . $indentation . 'use '); for ($i = $commaPos + 1; $i < $pointerAfterComma; $i++) { $fixer->replaceToken($i, ''); } } $fixer->endChangeset(); }
[ "protected", "function", "fixeUse", "(", "int", "$", "endPos", ",", "int", "$", "usePos", ")", ":", "void", "{", "$", "indentation", "=", "$", "this", "->", "getIndentationForFix", "(", "$", "usePos", ")", ";", "$", "file", "=", "$", "this", "->", "g...
Fixes the given use position. @param int $endPos The end of the checked position. @param int $usePos @return void
[ "Fixes", "the", "given", "use", "position", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Formatting/TraitUseDeclarationSniff.php#L96-L114
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Formatting/TraitUseDeclarationSniff.php
TraitUseDeclarationSniff.getIndentationForFix
private function getIndentationForFix(int $usePos): string { $file = $this->getFile()->getBaseFile(); $indentation = ''; $currentPointer = $usePos - 1; $tokens = $file->getTokens(); while ($tokens[$currentPointer]['code'] === T_WHITESPACE && $tokens[$currentPointer]['content'] !== $file->eolChar) { $indentation .= $tokens[$currentPointer]['content']; $currentPointer--; } return $indentation; }
php
private function getIndentationForFix(int $usePos): string { $file = $this->getFile()->getBaseFile(); $indentation = ''; $currentPointer = $usePos - 1; $tokens = $file->getTokens(); while ($tokens[$currentPointer]['code'] === T_WHITESPACE && $tokens[$currentPointer]['content'] !== $file->eolChar) { $indentation .= $tokens[$currentPointer]['content']; $currentPointer--; } return $indentation; }
[ "private", "function", "getIndentationForFix", "(", "int", "$", "usePos", ")", ":", "string", "{", "$", "file", "=", "$", "this", "->", "getFile", "(", ")", "->", "getBaseFile", "(", ")", ";", "$", "indentation", "=", "''", ";", "$", "currentPointer", ...
Returns the needed indentation whitespace for fhe fixing of the uses. @param int $usePos @return string
[ "Returns", "the", "needed", "indentation", "whitespace", "for", "fhe", "fixing", "of", "the", "uses", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Formatting/TraitUseDeclarationSniff.php#L123-L137
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/Helper/UseStatementHelper.php
UseStatementHelper.getType
public static function getType(File $file, UseStatement $useStatement): string { // Satisfy php md unset($file); $type = $useStatement->getType(); return $type; }
php
public static function getType(File $file, UseStatement $useStatement): string { // Satisfy php md unset($file); $type = $useStatement->getType(); return $type; }
[ "public", "static", "function", "getType", "(", "File", "$", "file", ",", "UseStatement", "$", "useStatement", ")", ":", "string", "{", "// Satisfy php md", "unset", "(", "$", "file", ")", ";", "$", "type", "=", "$", "useStatement", "->", "getType", "(", ...
Returns the type for the given use statement. @param File $file @param UseStatement $useStatement @return string
[ "Returns", "the", "type", "for", "the", "given", "use", "statement", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/UseStatementHelper.php#L27-L35
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/Helper/UseStatementHelper.php
UseStatementHelper.getTypeName
public static function getTypeName(File $file, UseStatement $useStatement): string { return UseStatement::getTypeName(static::getType($file, $useStatement)) ?? ''; }
php
public static function getTypeName(File $file, UseStatement $useStatement): string { return UseStatement::getTypeName(static::getType($file, $useStatement)) ?? ''; }
[ "public", "static", "function", "getTypeName", "(", "File", "$", "file", ",", "UseStatement", "$", "useStatement", ")", ":", "string", "{", "return", "UseStatement", "::", "getTypeName", "(", "static", "::", "getType", "(", "$", "file", ",", "$", "useStateme...
Returns the type name for the given use statement. @param File $file @param UseStatement $useStatement @return string
[ "Returns", "the", "type", "name", "for", "the", "given", "use", "statement", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/UseStatementHelper.php#L45-L48
train
mimmi20/BrowserDetector
src/Parser/DeviceParser.php
DeviceParser.parse
public function parse(string $useragent): array { if (preg_match('/new-sogou-spider|zollard|socialradarbot|microsoft office protocol discovery|powermarks|archivebot|marketwirebot|microsoft-cryptoapi|pad-bot|james bot|winhttp|jobboerse|<|>|online-versicherungsportal\.info|versicherungssuchmaschine\.net|microsearch|microsoft data access|microsoft url control|infegyatlas|msie or firefox mutant|semantic-visions\.com crawler|labs\.topsy\.com\/butterfly|dolphin http client|google wireless transcoder|commoncrawler|ipodder|tripadvisor|nokia wap gateway|outclicksbot/i', $useragent)) { return $this->load('unknown', 'unknown', $useragent); } if (!preg_match('/freebsd|raspbian/i', $useragent) && preg_match('/darwin|cfnetwork/i', $useragent) ) { return $this->darwinParser->parse($useragent); } if ($this->mobileDevice->isMobile($useragent)) { return $this->mobileParser->parse($useragent); } if ($this->tvDevice->isTvDevice($useragent)) { return $this->tvParser->parse($useragent); } if ($this->desktopDevice->isDesktopDevice($useragent)) { return $this->desktopParser->parse($useragent); } return $this->load('unknown', 'unknown', $useragent); }
php
public function parse(string $useragent): array { if (preg_match('/new-sogou-spider|zollard|socialradarbot|microsoft office protocol discovery|powermarks|archivebot|marketwirebot|microsoft-cryptoapi|pad-bot|james bot|winhttp|jobboerse|<|>|online-versicherungsportal\.info|versicherungssuchmaschine\.net|microsearch|microsoft data access|microsoft url control|infegyatlas|msie or firefox mutant|semantic-visions\.com crawler|labs\.topsy\.com\/butterfly|dolphin http client|google wireless transcoder|commoncrawler|ipodder|tripadvisor|nokia wap gateway|outclicksbot/i', $useragent)) { return $this->load('unknown', 'unknown', $useragent); } if (!preg_match('/freebsd|raspbian/i', $useragent) && preg_match('/darwin|cfnetwork/i', $useragent) ) { return $this->darwinParser->parse($useragent); } if ($this->mobileDevice->isMobile($useragent)) { return $this->mobileParser->parse($useragent); } if ($this->tvDevice->isTvDevice($useragent)) { return $this->tvParser->parse($useragent); } if ($this->desktopDevice->isDesktopDevice($useragent)) { return $this->desktopParser->parse($useragent); } return $this->load('unknown', 'unknown', $useragent); }
[ "public", "function", "parse", "(", "string", "$", "useragent", ")", ":", "array", "{", "if", "(", "preg_match", "(", "'/new-sogou-spider|zollard|socialradarbot|microsoft office protocol discovery|powermarks|archivebot|marketwirebot|microsoft-cryptoapi|pad-bot|james bot|winhttp|jobboer...
Gets the information about the rendering engine by User Agent @param string $useragent @throws \BrowserDetector\Loader\NotFoundException @return array
[ "Gets", "the", "information", "about", "the", "rendering", "engine", "by", "User", "Agent" ]
1b90d994fcee01344a36bbe39afb14622bc8df9c
https://github.com/mimmi20/BrowserDetector/blob/1b90d994fcee01344a36bbe39afb14622bc8df9c/src/Parser/DeviceParser.php#L104-L129
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php
AbstractRequiredTagsSniff.checkAndRegisterTagMaximumCounts
private function checkAndRegisterTagMaximumCounts(): void { $allTags = $this->getAllTags(); $checkedTags = []; $tagRules = $this->getRulesWithRequirement('max'); array_walk( $allTags, // TODO: Removed Duplicates function (array $tag, int $tagPos) use (&$checkedTags, $tagRules): void { $tagContent = substr($tag['content'], 1); if (!in_array($tagContent, $checkedTags)) { $checkedTags[] = $tagContent; $tagCount = count($this->findTokensForTag($tagContent)); $maxCount = @$tagRules[$tagContent]['max'] ?? 0; if ($maxCount && ($tagCount > $maxCount)) { $this->file->addError( self::MESSAGE_TAG_OCCURRENCE_MAX, $tagPos, // We use an error code containing the tag name because we can't configure this rules from // the outside and need specific code to exclude the rule for this special tag. static::CODE_TAG_OCCURRENCE_MAX_PREFIX . ucfirst($tagContent), [ $tagContent, $maxCount, $tagCount ] ); } } } ); }
php
private function checkAndRegisterTagMaximumCounts(): void { $allTags = $this->getAllTags(); $checkedTags = []; $tagRules = $this->getRulesWithRequirement('max'); array_walk( $allTags, // TODO: Removed Duplicates function (array $tag, int $tagPos) use (&$checkedTags, $tagRules): void { $tagContent = substr($tag['content'], 1); if (!in_array($tagContent, $checkedTags)) { $checkedTags[] = $tagContent; $tagCount = count($this->findTokensForTag($tagContent)); $maxCount = @$tagRules[$tagContent]['max'] ?? 0; if ($maxCount && ($tagCount > $maxCount)) { $this->file->addError( self::MESSAGE_TAG_OCCURRENCE_MAX, $tagPos, // We use an error code containing the tag name because we can't configure this rules from // the outside and need specific code to exclude the rule for this special tag. static::CODE_TAG_OCCURRENCE_MAX_PREFIX . ucfirst($tagContent), [ $tagContent, $maxCount, $tagCount ] ); } } } ); }
[ "private", "function", "checkAndRegisterTagMaximumCounts", "(", ")", ":", "void", "{", "$", "allTags", "=", "$", "this", "->", "getAllTags", "(", ")", ";", "$", "checkedTags", "=", "[", "]", ";", "$", "tagRules", "=", "$", "this", "->", "getRulesWithRequir...
Loads the rules with amax rule and checks if there are more tags than allowed. @return void
[ "Loads", "the", "rules", "with", "amax", "rule", "and", "checks", "if", "there", "are", "more", "tags", "than", "allowed", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php#L82-L117
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php
AbstractRequiredTagsSniff.checkAndRegisterTagMinimumCounts
private function checkAndRegisterTagMinimumCounts(): void { $checkedRule = 'min'; $rulesWithReq = $this->getRulesWithRequirement($checkedRule); array_walk( $rulesWithReq, function (array $tagRule, string $tag) use ($checkedRule): void { $minCount = $tagRule[$checkedRule]; $tagCount = count($this->findTokensForTag($tag)); if ($minCount > $tagCount) { $fixCallback = $this->hasFixCallback($checkedRule, $tag); $method = $fixCallback ? 'addFixableError' : 'addError'; $fixable = $this->file->{$method}( self::MESSAGE_TAG_OCCURRENCE_MIN, $this->getDocCommentPos(), // We use an error code containing the tag name because we can't configure this rules from the // outside and need specific code to exclude the rule for this special tag. static::CODE_TAG_OCCURRENCE_MIN_PREFIX . ucfirst($tag), [ $tag, $minCount, $tagCount ] ); if ($fixable && $fixCallback) { $this->{$fixCallback}($this->getDocCommentPos(), $minCount, $tagCount, $tag); } } } ); }
php
private function checkAndRegisterTagMinimumCounts(): void { $checkedRule = 'min'; $rulesWithReq = $this->getRulesWithRequirement($checkedRule); array_walk( $rulesWithReq, function (array $tagRule, string $tag) use ($checkedRule): void { $minCount = $tagRule[$checkedRule]; $tagCount = count($this->findTokensForTag($tag)); if ($minCount > $tagCount) { $fixCallback = $this->hasFixCallback($checkedRule, $tag); $method = $fixCallback ? 'addFixableError' : 'addError'; $fixable = $this->file->{$method}( self::MESSAGE_TAG_OCCURRENCE_MIN, $this->getDocCommentPos(), // We use an error code containing the tag name because we can't configure this rules from the // outside and need specific code to exclude the rule for this special tag. static::CODE_TAG_OCCURRENCE_MIN_PREFIX . ucfirst($tag), [ $tag, $minCount, $tagCount ] ); if ($fixable && $fixCallback) { $this->{$fixCallback}($this->getDocCommentPos(), $minCount, $tagCount, $tag); } } } ); }
[ "private", "function", "checkAndRegisterTagMinimumCounts", "(", ")", ":", "void", "{", "$", "checkedRule", "=", "'min'", ";", "$", "rulesWithReq", "=", "$", "this", "->", "getRulesWithRequirement", "(", "$", "checkedRule", ")", ";", "array_walk", "(", "$", "ru...
Checks if the tag occurrences reaches their minimum counts. @return void
[ "Checks", "if", "the", "tag", "occurrences", "reaches", "their", "minimum", "counts", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php#L124-L157
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php
AbstractRequiredTagsSniff.findTokensForTag
private function findTokensForTag(string $tagName): array { $allTags = $this->getAllTags(); return array_filter($allTags, function (array $tag) use ($tagName): bool { return substr($tag['content'], 1) === $tagName; }); }
php
private function findTokensForTag(string $tagName): array { $allTags = $this->getAllTags(); return array_filter($allTags, function (array $tag) use ($tagName): bool { return substr($tag['content'], 1) === $tagName; }); }
[ "private", "function", "findTokensForTag", "(", "string", "$", "tagName", ")", ":", "array", "{", "$", "allTags", "=", "$", "this", "->", "getAllTags", "(", ")", ";", "return", "array_filter", "(", "$", "allTags", ",", "function", "(", "array", "$", "tag...
Returns only the tokens with the given tag name. @param string $tagName @return array
[ "Returns", "only", "the", "tokens", "with", "the", "given", "tag", "name", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php#L166-L173
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php
AbstractRequiredTagsSniff.getProcessedTagRules
private function getProcessedTagRules(): array { if ($this->processedTagRules === null) { $this->processedTagRules = $this->processTagRules(); } return $this->processedTagRules; }
php
private function getProcessedTagRules(): array { if ($this->processedTagRules === null) { $this->processedTagRules = $this->processTagRules(); } return $this->processedTagRules; }
[ "private", "function", "getProcessedTagRules", "(", ")", ":", "array", "{", "if", "(", "$", "this", "->", "processedTagRules", "===", "null", ")", "{", "$", "this", "->", "processedTagRules", "=", "$", "this", "->", "processTagRules", "(", ")", ";", "}", ...
Returns the rules with their resolved callbacks. @return array
[ "Returns", "the", "rules", "with", "their", "resolved", "callbacks", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php#L194-L201
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php
AbstractRequiredTagsSniff.getRulesWithRequirement
private function getRulesWithRequirement(string $requiredRule): array { $processedTagRules = $this->getProcessedTagRules(); $processedTagRules = array_filter($processedTagRules, function (array $tagRule) use ($requiredRule): bool { return array_key_exists($requiredRule, $tagRule); }); return $processedTagRules; }
php
private function getRulesWithRequirement(string $requiredRule): array { $processedTagRules = $this->getProcessedTagRules(); $processedTagRules = array_filter($processedTagRules, function (array $tagRule) use ($requiredRule): bool { return array_key_exists($requiredRule, $tagRule); }); return $processedTagRules; }
[ "private", "function", "getRulesWithRequirement", "(", "string", "$", "requiredRule", ")", ":", "array", "{", "$", "processedTagRules", "=", "$", "this", "->", "getProcessedTagRules", "(", ")", ";", "$", "processedTagRules", "=", "array_filter", "(", "$", "proce...
Returns the rules with the given requirement. @param string $requiredRule @return array
[ "Returns", "the", "rules", "with", "the", "given", "requirement", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php#L210-L218
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php
AbstractRequiredTagsSniff.hasFixCallback
private function hasFixCallback(string $rule, string $tag) { return method_exists($this, $method = sprintf('fix%s%s', ucfirst($rule), ucfirst($tag))) ? $method : false; }
php
private function hasFixCallback(string $rule, string $tag) { return method_exists($this, $method = sprintf('fix%s%s', ucfirst($rule), ucfirst($tag))) ? $method : false; }
[ "private", "function", "hasFixCallback", "(", "string", "$", "rule", ",", "string", "$", "tag", ")", "{", "return", "method_exists", "(", "$", "this", ",", "$", "method", "=", "sprintf", "(", "'fix%s%s'", ",", "ucfirst", "(", "$", "rule", ")", ",", "uc...
Returns true if there is a callback for the given rule and tag. @param string $rule @param string $tag @return bool|string
[ "Returns", "true", "if", "there", "is", "a", "callback", "for", "the", "given", "rule", "and", "tag", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php#L237-L242
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php
AbstractRequiredTagsSniff.processTagRules
private function processTagRules(): array { $processedTagRules = $this->getTagRules(); array_walk($processedTagRules, function (&$tagRule) { $tagRule = array_map(function ($valueOrCallback) { return is_callable($valueOrCallback, true) ? Closure::fromCallable($valueOrCallback)->call($this) : $valueOrCallback; }, $tagRule); }); return $processedTagRules; }
php
private function processTagRules(): array { $processedTagRules = $this->getTagRules(); array_walk($processedTagRules, function (&$tagRule) { $tagRule = array_map(function ($valueOrCallback) { return is_callable($valueOrCallback, true) ? Closure::fromCallable($valueOrCallback)->call($this) : $valueOrCallback; }, $tagRule); }); return $processedTagRules; }
[ "private", "function", "processTagRules", "(", ")", ":", "array", "{", "$", "processedTagRules", "=", "$", "this", "->", "getTagRules", "(", ")", ";", "array_walk", "(", "$", "processedTagRules", ",", "function", "(", "&", "$", "tagRule", ")", "{", "$", ...
Resolves the callbacks in the tag rules. @return array
[ "Resolves", "the", "callbacks", "in", "the", "tag", "rules", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php#L264-L277
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php
AbstractRequiredTagsSniff.tearDown
protected function tearDown(): void { parent::tearDown(); $this->resetDocCommentPos(); $this->processedTagRules = null; $this->tags = null; }
php
protected function tearDown(): void { parent::tearDown(); $this->resetDocCommentPos(); $this->processedTagRules = null; $this->tags = null; }
[ "protected", "function", "tearDown", "(", ")", ":", "void", "{", "parent", "::", "tearDown", "(", ")", ";", "$", "this", "->", "resetDocCommentPos", "(", ")", ";", "$", "this", "->", "processedTagRules", "=", "null", ";", "$", "this", "->", "tags", "="...
Resets the cached data. @return void
[ "Resets", "the", "cached", "data", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/AbstractRequiredTagsSniff.php#L295-L303
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php
TagSortingSniff.checkAndRegisterLineBreakErrors
private function checkAndRegisterLineBreakErrors(): void { $tokens = $this->getTagTokens(); $prevToken = []; $tagCounts = $this->docTagHelper->getTagCounts($tokens); $withReturn = false; foreach ($tokens as $tokenPos => $token) { $thisTagContent = $token['content']; $isReturn = $thisTagContent === '@return'; $isGroupSwitch = // Did we switch the tag ... $prevToken && ($prevToken['content'] !== $thisTagContent) && // ... but do we skip singles or are we entering the return block which should contain only 1 tag. (($tagCounts[$thisTagContent] !== 1) || ($isReturn && !$withReturn)); // Insert new line between groups or before the return tag if there is no line break already. if ($isGroupSwitch && (($prevToken['line'] + 1) === $token['line'])) { $isFixing = $this->file->addFixableWarning( static::MESSAGE_MISSING_NEWLINE_BETWEEN_TAGS, $tokenPos, static::CODE_MISSING_NEWLINE_BETWEEN_TAGS, [ $prevToken['content'] ] ); if ($isFixing) { $this->insertNewLine($token); } } $prevToken = $token; // Return should be the last element, so this is ok. $withReturn = $isReturn; } }
php
private function checkAndRegisterLineBreakErrors(): void { $tokens = $this->getTagTokens(); $prevToken = []; $tagCounts = $this->docTagHelper->getTagCounts($tokens); $withReturn = false; foreach ($tokens as $tokenPos => $token) { $thisTagContent = $token['content']; $isReturn = $thisTagContent === '@return'; $isGroupSwitch = // Did we switch the tag ... $prevToken && ($prevToken['content'] !== $thisTagContent) && // ... but do we skip singles or are we entering the return block which should contain only 1 tag. (($tagCounts[$thisTagContent] !== 1) || ($isReturn && !$withReturn)); // Insert new line between groups or before the return tag if there is no line break already. if ($isGroupSwitch && (($prevToken['line'] + 1) === $token['line'])) { $isFixing = $this->file->addFixableWarning( static::MESSAGE_MISSING_NEWLINE_BETWEEN_TAGS, $tokenPos, static::CODE_MISSING_NEWLINE_BETWEEN_TAGS, [ $prevToken['content'] ] ); if ($isFixing) { $this->insertNewLine($token); } } $prevToken = $token; // Return should be the last element, so this is ok. $withReturn = $isReturn; } }
[ "private", "function", "checkAndRegisterLineBreakErrors", "(", ")", ":", "void", "{", "$", "tokens", "=", "$", "this", "->", "getTagTokens", "(", ")", ";", "$", "prevToken", "=", "[", "]", ";", "$", "tagCounts", "=", "$", "this", "->", "docTagHelper", "-...
Checks for line break errors and registers the errors if there are any. This should be called after the sorting is already checked and fixed! @return void
[ "Checks", "for", "line", "break", "errors", "and", "registers", "the", "errors", "if", "there", "are", "any", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php#L87-L124
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php
TagSortingSniff.checkAndRegisterSortingError
private function checkAndRegisterSortingError(): void { $orgTokens = $this->getTagTokens(); $sortedTokens = $this->sortTokens($orgTokens); if (array_values($orgTokens) !== $sortedTokens) { $error = (new CodeWarning( static::CODE_WRONG_TAG_SORTING, self::MESSAGE_WRONG_TAG_SORTING, array_shift($orgTokens)['pointer'] ))->setToken($this->token); $error->isFixable(true); throw $error; } }
php
private function checkAndRegisterSortingError(): void { $orgTokens = $this->getTagTokens(); $sortedTokens = $this->sortTokens($orgTokens); if (array_values($orgTokens) !== $sortedTokens) { $error = (new CodeWarning( static::CODE_WRONG_TAG_SORTING, self::MESSAGE_WRONG_TAG_SORTING, array_shift($orgTokens)['pointer'] ))->setToken($this->token); $error->isFixable(true); throw $error; } }
[ "private", "function", "checkAndRegisterSortingError", "(", ")", ":", "void", "{", "$", "orgTokens", "=", "$", "this", "->", "getTagTokens", "(", ")", ";", "$", "sortedTokens", "=", "$", "this", "->", "sortTokens", "(", "$", "orgTokens", ")", ";", "if", ...
Checks the alphabetic sorting and registers and error if it sorted wrongly. @throws CodeWarning If the tags are not correctly sorted. @return void
[ "Checks", "the", "alphabetic", "sorting", "and", "registers", "and", "error", "if", "it", "sorted", "wrongly", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php#L133-L149
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php
TagSortingSniff.compareTokensForSorting
private function compareTokensForSorting(array $leftToken, array $rightToken, array $tagCounts): int { $leftTagName = $leftToken['content']; $rightTagName = $rightToken['content']; $realLeftTagName = $this->getRealtagName($leftTagName); $realRightTagName = $this->getRealtagName($rightTagName); // If they have the same content, leave them, where they where ... $return = $leftToken['line'] > $rightToken['line'] ? 1 : -1; // But if they are different. if ($realLeftTagName !== $realRightTagName) { $leftTagCount = $tagCounts[$leftTagName]; $rightTagCount = $tagCounts[$rightTagName]; switch (true) { // Move return to bottom everytime ... case ($realLeftTagName === '@return'): $return = 1; break; // ... yes, everytime case ($realRightTagName === '@return'): $return = -1; break; // Move single items to the top. case ($leftTagCount !== $rightTagCount): $return = $leftTagCount > $rightTagCount ? +1 : -1; break; // Compare tag name default: $return = strcasecmp($realLeftTagName, $realRightTagName) > 1 ? 1 : -1; } } return $return; }
php
private function compareTokensForSorting(array $leftToken, array $rightToken, array $tagCounts): int { $leftTagName = $leftToken['content']; $rightTagName = $rightToken['content']; $realLeftTagName = $this->getRealtagName($leftTagName); $realRightTagName = $this->getRealtagName($rightTagName); // If they have the same content, leave them, where they where ... $return = $leftToken['line'] > $rightToken['line'] ? 1 : -1; // But if they are different. if ($realLeftTagName !== $realRightTagName) { $leftTagCount = $tagCounts[$leftTagName]; $rightTagCount = $tagCounts[$rightTagName]; switch (true) { // Move return to bottom everytime ... case ($realLeftTagName === '@return'): $return = 1; break; // ... yes, everytime case ($realRightTagName === '@return'): $return = -1; break; // Move single items to the top. case ($leftTagCount !== $rightTagCount): $return = $leftTagCount > $rightTagCount ? +1 : -1; break; // Compare tag name default: $return = strcasecmp($realLeftTagName, $realRightTagName) > 1 ? 1 : -1; } } return $return; }
[ "private", "function", "compareTokensForSorting", "(", "array", "$", "leftToken", ",", "array", "$", "rightToken", ",", "array", "$", "tagCounts", ")", ":", "int", "{", "$", "leftTagName", "=", "$", "leftToken", "[", "'content'", "]", ";", "$", "rightTagName...
The callback to sort tokens. 1. @return goes to the bottom 2. Single tags are group alphabetically in the top group. 3. Groups are sorted then by occurrence, that the largest group is the last one before the return. 4. Same annotations are kept in the order of their code. @param array $leftToken Provided by usort. @param array $rightToken Provided by usort. @param array $tagCounts Saves the occurence count for every tag. @return int
[ "The", "callback", "to", "sort", "tokens", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php#L165-L203
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php
TagSortingSniff.createNewSortedTagsContent
private function createNewSortedTagsContent(): string { $file = $this->file; $eolChar = $file->getEolChar(); $newContent = ''; $prevTagContent = ''; $sortedTags = $this->sortTokens($this->getTagTokens()); $tagCounts = $this->docTagHelper->getTagCounts($sortedTags); $withReturn = false; foreach ($sortedTags as $tag) { $lineStartingPadding = str_pad('', $tag['column'] - 3, ' '); $thisTagContent = $tag['content']; $isReturn = $thisTagContent === '@return'; $isGroupSwitch = // Did we switch the tag ... $prevTagContent && ($prevTagContent !== $thisTagContent) && // ... but do we skip singles or are we entering the return block which should contain only 1 tag. (($tagCounts[$thisTagContent] !== 1) || ($isReturn && !$withReturn)); // Insert new line between groups. if ($isGroupSwitch) { $newContent .= $lineStartingPadding . '*' . $eolChar; } // Create the new Tag. // WARNING We do not need a line break in the tag summary. $newContent .= $lineStartingPadding . '* ' . trim($thisTagContent); if ($tag['contents']) { $prevLine = $tag['line']; foreach ($tag['contents'] as $subToken) { // If we have a line switch, we need to create the correct indentation from before ... if ($withLineSwitch = $subToken['line'] > $prevLine) { $newContent .= $eolChar . $lineStartingPadding . '*' . str_repeat(' ', $subToken['column'] - strlen($lineStartingPadding) - 2); $prevLine = $subToken['line']; } // ... if we have no line switch, then an additional whitespace is enough. $newContent .= ($withLineSwitch ? '' : ' ') . $subToken['content']; } } $newContent .= $eolChar; $prevTagContent = $thisTagContent; $withReturn = $isReturn; } $newContent .= $lineStartingPadding . '*/' . $eolChar; return $newContent; }
php
private function createNewSortedTagsContent(): string { $file = $this->file; $eolChar = $file->getEolChar(); $newContent = ''; $prevTagContent = ''; $sortedTags = $this->sortTokens($this->getTagTokens()); $tagCounts = $this->docTagHelper->getTagCounts($sortedTags); $withReturn = false; foreach ($sortedTags as $tag) { $lineStartingPadding = str_pad('', $tag['column'] - 3, ' '); $thisTagContent = $tag['content']; $isReturn = $thisTagContent === '@return'; $isGroupSwitch = // Did we switch the tag ... $prevTagContent && ($prevTagContent !== $thisTagContent) && // ... but do we skip singles or are we entering the return block which should contain only 1 tag. (($tagCounts[$thisTagContent] !== 1) || ($isReturn && !$withReturn)); // Insert new line between groups. if ($isGroupSwitch) { $newContent .= $lineStartingPadding . '*' . $eolChar; } // Create the new Tag. // WARNING We do not need a line break in the tag summary. $newContent .= $lineStartingPadding . '* ' . trim($thisTagContent); if ($tag['contents']) { $prevLine = $tag['line']; foreach ($tag['contents'] as $subToken) { // If we have a line switch, we need to create the correct indentation from before ... if ($withLineSwitch = $subToken['line'] > $prevLine) { $newContent .= $eolChar . $lineStartingPadding . '*' . str_repeat(' ', $subToken['column'] - strlen($lineStartingPadding) - 2); $prevLine = $subToken['line']; } // ... if we have no line switch, then an additional whitespace is enough. $newContent .= ($withLineSwitch ? '' : ' ') . $subToken['content']; } } $newContent .= $eolChar; $prevTagContent = $thisTagContent; $withReturn = $isReturn; } $newContent .= $lineStartingPadding . '*/' . $eolChar; return $newContent; }
[ "private", "function", "createNewSortedTagsContent", "(", ")", ":", "string", "{", "$", "file", "=", "$", "this", "->", "file", ";", "$", "eolChar", "=", "$", "file", "->", "getEolChar", "(", ")", ";", "$", "newContent", "=", "''", ";", "$", "prevTagCo...
Sorts the tags and creates a new doc comment part for them to replace it with the old content. @return string The new content.
[ "Sorts", "the", "tags", "and", "creates", "a", "new", "doc", "comment", "part", "for", "them", "to", "replace", "it", "with", "the", "old", "content", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php#L210-L266
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php
TagSortingSniff.fixSorting
private function fixSorting(): void { $fixer = $this->file->getFixer(); $fixer->beginChangeset(); $firstTag = $this->removeOldTagLines(); $fixer->addContent($firstTag['pointer'] - 1, $this->createNewSortedTagsContent()); $fixer->endChangeset(); }
php
private function fixSorting(): void { $fixer = $this->file->getFixer(); $fixer->beginChangeset(); $firstTag = $this->removeOldTagLines(); $fixer->addContent($firstTag['pointer'] - 1, $this->createNewSortedTagsContent()); $fixer->endChangeset(); }
[ "private", "function", "fixSorting", "(", ")", ":", "void", "{", "$", "fixer", "=", "$", "this", "->", "file", "->", "getFixer", "(", ")", ";", "$", "fixer", "->", "beginChangeset", "(", ")", ";", "$", "firstTag", "=", "$", "this", "->", "removeOldTa...
Sorts the tokens in blocks of their occurences and then alphabetically, but the return at last. @return void
[ "Sorts", "the", "tokens", "in", "blocks", "of", "their", "occurences", "and", "then", "alphabetically", "but", "the", "return", "at", "last", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php#L273-L284
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php
TagSortingSniff.getTagTokens
private function getTagTokens(): array { if ($this->loadedTagTokens === null) { $this->loadedTagTokens = $this->loadTagTokens(); } return $this->loadedTagTokens; }
php
private function getTagTokens(): array { if ($this->loadedTagTokens === null) { $this->loadedTagTokens = $this->loadTagTokens(); } return $this->loadedTagTokens; }
[ "private", "function", "getTagTokens", "(", ")", ":", "array", "{", "if", "(", "$", "this", "->", "loadedTagTokens", "===", "null", ")", "{", "$", "this", "->", "loadedTagTokens", "=", "$", "this", "->", "loadTagTokens", "(", ")", ";", "}", "return", "...
Returns the tokens of the comment tags. @return array The tokens of the comment tags.
[ "Returns", "the", "tokens", "of", "the", "comment", "tags", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php#L307-L314
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php
TagSortingSniff.insertNewLine
private function insertNewLine(array $token): void { $fixer = $this->file->getFixer(); $lineStartPadding = str_pad('', $token['column'] - 3, ' '); $fixer->beginChangeset(); // Remove the whitespace between the tag and the comments star. $fixer->replaceToken($token['pointer'] - 1, ''); $fixer->addContentBefore( $token['pointer'], $this->file->getEolChar() . $lineStartPadding . '* ' ); $fixer->endChangeset(); }
php
private function insertNewLine(array $token): void { $fixer = $this->file->getFixer(); $lineStartPadding = str_pad('', $token['column'] - 3, ' '); $fixer->beginChangeset(); // Remove the whitespace between the tag and the comments star. $fixer->replaceToken($token['pointer'] - 1, ''); $fixer->addContentBefore( $token['pointer'], $this->file->getEolChar() . $lineStartPadding . '* ' ); $fixer->endChangeset(); }
[ "private", "function", "insertNewLine", "(", "array", "$", "token", ")", ":", "void", "{", "$", "fixer", "=", "$", "this", "->", "file", "->", "getFixer", "(", ")", ";", "$", "lineStartPadding", "=", "str_pad", "(", "''", ",", "$", "token", "[", "'co...
Insert the new line before the given token. @param array $token The token where a newline should be. @return void
[ "Insert", "the", "new", "line", "before", "the", "given", "token", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php#L323-L339
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php
TagSortingSniff.loadTagTokens
private function loadTagTokens(): array { $barrier = 0; $tokens = $this->docTagHelper->getTagTokens(); $tokens = array_filter($tokens, function (array $token) use (&$barrier): bool { $allowed = true; if ($barrier) { if ($allowed = $token['column'] <= $barrier) { $barrier = 0; } } if ($allowed && array_key_exists('contents', $token)) { $barrier = $token['column']; } return $allowed; }); return $tokens; }
php
private function loadTagTokens(): array { $barrier = 0; $tokens = $this->docTagHelper->getTagTokens(); $tokens = array_filter($tokens, function (array $token) use (&$barrier): bool { $allowed = true; if ($barrier) { if ($allowed = $token['column'] <= $barrier) { $barrier = 0; } } if ($allowed && array_key_exists('contents', $token)) { $barrier = $token['column']; } return $allowed; }); return $tokens; }
[ "private", "function", "loadTagTokens", "(", ")", ":", "array", "{", "$", "barrier", "=", "0", ";", "$", "tokens", "=", "$", "this", "->", "docTagHelper", "->", "getTagTokens", "(", ")", ";", "$", "tokens", "=", "array_filter", "(", "$", "tokens", ",",...
Loads the tokens of this comment. @return array
[ "Loads", "the", "tokens", "of", "this", "comment", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php#L346-L368
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php
TagSortingSniff.processToken
protected function processToken(): void { try { $this->checkAndRegisterSortingError(); $this->checkAndRegisterLineBreakErrors(); } catch (CodeWarning $exception) { $fixable = $this->getExceptionHandler()->handleException($exception); if ($fixable) { $this->fixSorting(); } } }
php
protected function processToken(): void { try { $this->checkAndRegisterSortingError(); $this->checkAndRegisterLineBreakErrors(); } catch (CodeWarning $exception) { $fixable = $this->getExceptionHandler()->handleException($exception); if ($fixable) { $this->fixSorting(); } } }
[ "protected", "function", "processToken", "(", ")", ":", "void", "{", "try", "{", "$", "this", "->", "checkAndRegisterSortingError", "(", ")", ";", "$", "this", "->", "checkAndRegisterLineBreakErrors", "(", ")", ";", "}", "catch", "(", "CodeWarning", "$", "ex...
Processes a found registered token. @return void
[ "Processes", "a", "found", "registered", "token", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php#L375-L388
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php
TagSortingSniff.removeOldTagLines
private function removeOldTagLines(): array { $tags = $this->getTagTokens(); $firstTag = array_shift($tags); (new LineHelper($this->file)) ->removeLines( $firstTag['line'], $this->tokens[$this->token['comment_closer']]['line'] ); return $firstTag; }
php
private function removeOldTagLines(): array { $tags = $this->getTagTokens(); $firstTag = array_shift($tags); (new LineHelper($this->file)) ->removeLines( $firstTag['line'], $this->tokens[$this->token['comment_closer']]['line'] ); return $firstTag; }
[ "private", "function", "removeOldTagLines", "(", ")", ":", "array", "{", "$", "tags", "=", "$", "this", "->", "getTagTokens", "(", ")", ";", "$", "firstTag", "=", "array_shift", "(", "$", "tags", ")", ";", "(", "new", "LineHelper", "(", "$", "this", ...
Removed the lines with the wrongly sorted tags. @return array The first tag token of this doc block.
[ "Removed", "the", "lines", "with", "the", "wrongly", "sorted", "tags", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php#L405-L417
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php
TagSortingSniff.setUp
protected function setUp(): void { $this->addPointerToTokens(); $this->docTagHelper = new DocTagHelper( $this->file, $this->stackPos, $this->tokens ); }
php
protected function setUp(): void { $this->addPointerToTokens(); $this->docTagHelper = new DocTagHelper( $this->file, $this->stackPos, $this->tokens ); }
[ "protected", "function", "setUp", "(", ")", ":", "void", "{", "$", "this", "->", "addPointerToTokens", "(", ")", ";", "$", "this", "->", "docTagHelper", "=", "new", "DocTagHelper", "(", "$", "this", "->", "file", ",", "$", "this", "->", "stackPos", ","...
Do you want to setup things before processing the token? @return void
[ "Do", "you", "want", "to", "setup", "things", "before", "processing", "the", "token?" ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php#L424-L433
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php
TagSortingSniff.sortTokens
private function sortTokens(array $tokens): array { $tagCounts = $this->docTagHelper->getTagCounts($tokens); usort($tokens, function (array $leftToken, array $rightToken) use ($tagCounts): int { return $this->compareTokensForSorting($leftToken, $rightToken, $tagCounts); }); return $tokens; }
php
private function sortTokens(array $tokens): array { $tagCounts = $this->docTagHelper->getTagCounts($tokens); usort($tokens, function (array $leftToken, array $rightToken) use ($tagCounts): int { return $this->compareTokensForSorting($leftToken, $rightToken, $tagCounts); }); return $tokens; }
[ "private", "function", "sortTokens", "(", "array", "$", "tokens", ")", ":", "array", "{", "$", "tagCounts", "=", "$", "this", "->", "docTagHelper", "->", "getTagCounts", "(", "$", "tokens", ")", ";", "usort", "(", "$", "tokens", ",", "function", "(", "...
Sorts the tokens in blocks of their occurrences and then alphabetically, but the return at last. @param array $tokens The tokens. @return array The sorted tokens.
[ "Sorts", "the", "tokens", "in", "blocks", "of", "their", "occurrences", "and", "then", "alphabetically", "but", "the", "return", "at", "last", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/TagSortingSniff.php#L442-L451
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Comparisons/EmptyArrayForComparisonSniff.php
EmptyArrayForComparisonSniff.checkArrayStructure
private function checkArrayStructure(array $invalidCodes, int $searchPos): void { // Rename the var to get more readable code. $remainingInvalidCodes = $invalidCodes; unset($invalidCodes); foreach ($remainingInvalidCodes as $nextInvalidCodeIndex => $nextInvalidCode) { $foundTokenPos = TokenHelper::findNextEffective($this->getFile(), $searchPos); $foundToken = $this->tokens[$foundTokenPos]; // We can stop the search, if there is no invalid code. if ($foundToken['code'] !== $nextInvalidCode) { break; } // Check the next possible token $searchPos = $foundTokenPos + 1; unset($remainingInvalidCodes[$nextInvalidCodeIndex]); } $matchedEveryInvalidCode = !$remainingInvalidCodes; $this->file->recordMetric( $searchPos, 'Invalid array comparison', $matchedEveryInvalidCode ? 'yes' : 'no' ); if ($matchedEveryInvalidCode) { throw (new CodeError(static::CODE_EMPTY_ARRAY, self::MESSAGE_EMPTY_ARRAY, $searchPos)); } }
php
private function checkArrayStructure(array $invalidCodes, int $searchPos): void { // Rename the var to get more readable code. $remainingInvalidCodes = $invalidCodes; unset($invalidCodes); foreach ($remainingInvalidCodes as $nextInvalidCodeIndex => $nextInvalidCode) { $foundTokenPos = TokenHelper::findNextEffective($this->getFile(), $searchPos); $foundToken = $this->tokens[$foundTokenPos]; // We can stop the search, if there is no invalid code. if ($foundToken['code'] !== $nextInvalidCode) { break; } // Check the next possible token $searchPos = $foundTokenPos + 1; unset($remainingInvalidCodes[$nextInvalidCodeIndex]); } $matchedEveryInvalidCode = !$remainingInvalidCodes; $this->file->recordMetric( $searchPos, 'Invalid array comparison', $matchedEveryInvalidCode ? 'yes' : 'no' ); if ($matchedEveryInvalidCode) { throw (new CodeError(static::CODE_EMPTY_ARRAY, self::MESSAGE_EMPTY_ARRAY, $searchPos)); } }
[ "private", "function", "checkArrayStructure", "(", "array", "$", "invalidCodes", ",", "int", "$", "searchPos", ")", ":", "void", "{", "// Rename the var to get more readable code.", "$", "remainingInvalidCodes", "=", "$", "invalidCodes", ";", "unset", "(", "$", "inv...
Search starting with the given search pos for the invalid codes in consecutive order. @throws CodeError Contains the error message if there is an invalid array check. @param array $invalidCodes @param int $searchPos @return void
[ "Search", "starting", "with", "the", "given", "search", "pos", "for", "the", "invalid", "codes", "in", "consecutive", "order", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Comparisons/EmptyArrayForComparisonSniff.php#L56-L87
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/Comparisons/EmptyArrayForComparisonSniff.php
EmptyArrayForComparisonSniff.setUp
protected function setUp(): void { parent::setUp(); $this->invalidStructure = [ T_ARRAY => [T_OPEN_PARENTHESIS, T_CLOSE_PARENTHESIS], T_OPEN_SHORT_ARRAY => [T_CLOSE_SHORT_ARRAY] ]; }
php
protected function setUp(): void { parent::setUp(); $this->invalidStructure = [ T_ARRAY => [T_OPEN_PARENTHESIS, T_CLOSE_PARENTHESIS], T_OPEN_SHORT_ARRAY => [T_CLOSE_SHORT_ARRAY] ]; }
[ "protected", "function", "setUp", "(", ")", ":", "void", "{", "parent", "::", "setUp", "(", ")", ";", "$", "this", "->", "invalidStructure", "=", "[", "T_ARRAY", "=>", "[", "T_OPEN_PARENTHESIS", ",", "T_CLOSE_PARENTHESIS", "]", ",", "T_OPEN_SHORT_ARRAY", "=>...
Declares the forbidden array structure. @return void
[ "Declares", "the", "forbidden", "array", "structure", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Comparisons/EmptyArrayForComparisonSniff.php#L142-L150
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/Helper/DocTagHelper.php
DocTagHelper.getTagTokens
public function getTagTokens(): array { $iteratedPos = 0; $tagPositions = $this->getCommentStartToken()['comment_tags']; $tagTokens = []; /** @var int $tagPos */ foreach ($tagPositions as $tagPos) { if ($tagPos >= $iteratedPos) { $tagTokens[$tagPos] = $this->tokens[$tagPos] + [ 'contents' => $this->loadTagContentTokens($tagPos, $iteratedPos) ]; } } return $tagTokens; }
php
public function getTagTokens(): array { $iteratedPos = 0; $tagPositions = $this->getCommentStartToken()['comment_tags']; $tagTokens = []; /** @var int $tagPos */ foreach ($tagPositions as $tagPos) { if ($tagPos >= $iteratedPos) { $tagTokens[$tagPos] = $this->tokens[$tagPos] + [ 'contents' => $this->loadTagContentTokens($tagPos, $iteratedPos) ]; } } return $tagTokens; }
[ "public", "function", "getTagTokens", "(", ")", ":", "array", "{", "$", "iteratedPos", "=", "0", ";", "$", "tagPositions", "=", "$", "this", "->", "getCommentStartToken", "(", ")", "[", "'comment_tags'", "]", ";", "$", "tagTokens", "=", "[", "]", ";", ...
Returns array of all comment tag tokens. @return array List of all comment tag tokens indexed by token position
[ "Returns", "array", "of", "all", "comment", "tag", "tokens", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/DocTagHelper.php#L103-L119
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/Helper/DocTagHelper.php
DocTagHelper.getTagCounts
public function getTagCounts(array $tagTokens): array { $tagCounts = []; foreach ($tagTokens as $tagToken) { $tagName = $tagToken['content']; if (!array_key_exists($tagName, $tagCounts)) { $tagCounts[$tagName] = 0; } ++$tagCounts[$tagName]; } return $tagCounts; }
php
public function getTagCounts(array $tagTokens): array { $tagCounts = []; foreach ($tagTokens as $tagToken) { $tagName = $tagToken['content']; if (!array_key_exists($tagName, $tagCounts)) { $tagCounts[$tagName] = 0; } ++$tagCounts[$tagName]; } return $tagCounts; }
[ "public", "function", "getTagCounts", "(", "array", "$", "tagTokens", ")", ":", "array", "{", "$", "tagCounts", "=", "[", "]", ";", "foreach", "(", "$", "tagTokens", "as", "$", "tagToken", ")", "{", "$", "tagName", "=", "$", "tagToken", "[", "'content'...
Returns the individual count of every tag. @param array $tagTokens Array of tag tokens. @return array List of comment tags with there count of the current comment
[ "Returns", "the", "individual", "count", "of", "every", "tag", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/DocTagHelper.php#L128-L143
train
mimmi20/BrowserDetector
src/Version/Helper/Safari.php
Safari.mapSafariVersion
public function mapSafariVersion(string $detectedVersion): string { $regularVersions = [ 3.0, 3.1, 3.2, 4.0, 4.1, 4.2, 4.3, 4.4, 5.0, 5.1, 5.2, 6.0, 6.1, 6.2, 7.0, 7.1, 8.0, 8.1, 9.0, 9.1, 10.0, 10.1, 11.0, 12.0, ]; if (in_array($detectedVersion, $regularVersions)) { return $detectedVersion; } $versions = [ '14600' => '12.0', '13600' => '11.0', '12600' => '10.0', '11600' => '9.1', '10500' => '8.0', '9500' => '7.0', '8500' => '6.0', '7500' => '5.1', '6500' => '5.0', '4500' => '4.0', '600' => '5.0', '500' => '4.0', '400' => '3.0', ]; foreach ($versions as $engineVersion => $osVersion) { if (version_compare($detectedVersion, (string) $engineVersion, '>=')) { return $osVersion; } } return '0'; }
php
public function mapSafariVersion(string $detectedVersion): string { $regularVersions = [ 3.0, 3.1, 3.2, 4.0, 4.1, 4.2, 4.3, 4.4, 5.0, 5.1, 5.2, 6.0, 6.1, 6.2, 7.0, 7.1, 8.0, 8.1, 9.0, 9.1, 10.0, 10.1, 11.0, 12.0, ]; if (in_array($detectedVersion, $regularVersions)) { return $detectedVersion; } $versions = [ '14600' => '12.0', '13600' => '11.0', '12600' => '10.0', '11600' => '9.1', '10500' => '8.0', '9500' => '7.0', '8500' => '6.0', '7500' => '5.1', '6500' => '5.0', '4500' => '4.0', '600' => '5.0', '500' => '4.0', '400' => '3.0', ]; foreach ($versions as $engineVersion => $osVersion) { if (version_compare($detectedVersion, (string) $engineVersion, '>=')) { return $osVersion; } } return '0'; }
[ "public", "function", "mapSafariVersion", "(", "string", "$", "detectedVersion", ")", ":", "string", "{", "$", "regularVersions", "=", "[", "3.0", ",", "3.1", ",", "3.2", ",", "4.0", ",", "4.1", ",", "4.2", ",", "4.3", ",", "4.4", ",", "5.0", ",", "5...
maps different Safari Versions to a normalized format @param string $detectedVersion @return string
[ "maps", "different", "Safari", "Versions", "to", "a", "normalized", "format" ]
1b90d994fcee01344a36bbe39afb14622bc8df9c
https://github.com/mimmi20/BrowserDetector/blob/1b90d994fcee01344a36bbe39afb14622bc8df9c/src/Version/Helper/Safari.php#L23-L79
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/RequiredMethodTagsSniff.php
RequiredMethodTagsSniff.fixMinReturn
protected function fixMinReturn(int $stackPos): void { $closePos = $this->tokens[$stackPos]['comment_closer']; $closeTag = $this->tokens[$closePos]; $indent = str_repeat(' ', $closeTag['column'] - 1); $fileDecorator = $this->getFile(); $returnTypeHint = FunctionHelper::findReturnTypeHint( $fileDecorator->getBaseFile(), $fileDecorator->findNext([T_FUNCTION], $closePos + 1) ); $typeHint = $returnTypeHint ? $returnTypeHint->getTypeHint() : 'void'; $fixer = $fileDecorator->fixer; $fixer->beginChangeset(); $fixer->replaceToken( $closePos, "*\n{$indent}* @return {$typeHint}\n{$indent}{$closeTag['content']}" ); $fixer->endChangeset(); }
php
protected function fixMinReturn(int $stackPos): void { $closePos = $this->tokens[$stackPos]['comment_closer']; $closeTag = $this->tokens[$closePos]; $indent = str_repeat(' ', $closeTag['column'] - 1); $fileDecorator = $this->getFile(); $returnTypeHint = FunctionHelper::findReturnTypeHint( $fileDecorator->getBaseFile(), $fileDecorator->findNext([T_FUNCTION], $closePos + 1) ); $typeHint = $returnTypeHint ? $returnTypeHint->getTypeHint() : 'void'; $fixer = $fileDecorator->fixer; $fixer->beginChangeset(); $fixer->replaceToken( $closePos, "*\n{$indent}* @return {$typeHint}\n{$indent}{$closeTag['content']}" ); $fixer->endChangeset(); }
[ "protected", "function", "fixMinReturn", "(", "int", "$", "stackPos", ")", ":", "void", "{", "$", "closePos", "=", "$", "this", "->", "tokens", "[", "$", "stackPos", "]", "[", "'comment_closer'", "]", ";", "$", "closeTag", "=", "$", "this", "->", "toke...
Adds a return annotation if there is none. @param int $stackPos @return void
[ "Adds", "a", "return", "annotation", "if", "there", "is", "none", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/RequiredMethodTagsSniff.php#L31-L55
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/Sniffs/DocTags/RequiredMethodTagsSniff.php
RequiredMethodTagsSniff.isMagicFunctionWithoutReturn
private function isMagicFunctionWithoutReturn(): bool { $whitelist = [ '__construct', '__destruct', '__clone', '__wakeup', '__set', '__unset', ]; $stackToken = $this->tokens[$this->stackPos]; $functionNamePtr = $this->file->getBaseFile()->findNext( [T_STRING], $this->stackPos + 1, $stackToken['parenthesis_opener'] ); $functionNameToken = $this->tokens[$functionNamePtr]; return in_array($functionNameToken['content'], $whitelist, true); }
php
private function isMagicFunctionWithoutReturn(): bool { $whitelist = [ '__construct', '__destruct', '__clone', '__wakeup', '__set', '__unset', ]; $stackToken = $this->tokens[$this->stackPos]; $functionNamePtr = $this->file->getBaseFile()->findNext( [T_STRING], $this->stackPos + 1, $stackToken['parenthesis_opener'] ); $functionNameToken = $this->tokens[$functionNamePtr]; return in_array($functionNameToken['content'], $whitelist, true); }
[ "private", "function", "isMagicFunctionWithoutReturn", "(", ")", ":", "bool", "{", "$", "whitelist", "=", "[", "'__construct'", ",", "'__destruct'", ",", "'__clone'", ",", "'__wakeup'", ",", "'__set'", ",", "'__unset'", ",", "]", ";", "$", "stackToken", "=", ...
Checks if the listener function is a magic php function without return. @return bool Indicator if the current function is not a whitelisted function
[ "Checks", "if", "the", "listener", "function", "is", "a", "magic", "php", "function", "without", "return", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/RequiredMethodTagsSniff.php#L89-L111
train
furqansiddiqui/http-client
src/Authentication.php
Authentication.basic
public function basic(string $username, string $password) { $this->type = self::BASIC; $this->username = $username; $this->password = $password; }
php
public function basic(string $username, string $password) { $this->type = self::BASIC; $this->username = $username; $this->password = $password; }
[ "public", "function", "basic", "(", "string", "$", "username", ",", "string", "$", "password", ")", "{", "$", "this", "->", "type", "=", "self", "::", "BASIC", ";", "$", "this", "->", "username", "=", "$", "username", ";", "$", "this", "->", "passwor...
Basic HTTP authentication @param string $username @param string $password
[ "Basic", "HTTP", "authentication" ]
ecdb48f929829cd034070c481e113a31d339b87b
https://github.com/furqansiddiqui/http-client/blob/ecdb48f929829cd034070c481e113a31d339b87b/src/Authentication.php#L42-L47
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/AbstractFileDecorator.php
AbstractFileDecorator.addError
public function addError( $error, $stackPtr, $code, $data = [], $severity = 0, $fixable = false ) { return $this->__call(__FUNCTION__, func_get_args()); }
php
public function addError( $error, $stackPtr, $code, $data = [], $severity = 0, $fixable = false ) { return $this->__call(__FUNCTION__, func_get_args()); }
[ "public", "function", "addError", "(", "$", "error", ",", "$", "stackPtr", ",", "$", "code", ",", "$", "data", "=", "[", "]", ",", "$", "severity", "=", "0", ",", "$", "fixable", "=", "false", ")", "{", "return", "$", "this", "->", "__call", "(",...
Records an error against a specific token in the file. @param string $error The error message. @param int $stackPtr The stack position where the error occurred. @param string $code A violation code unique to the sniff message. @param array $data Replacements for the error message. @param int $severity The severity level for this error. A value of 0 will be converted into the default severity level. @param boolean $fixable Can the error be fixed by the sniff? @return boolean
[ "Records", "an", "error", "against", "a", "specific", "token", "in", "the", "file", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/AbstractFileDecorator.php#L65-L74
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/AbstractFileDecorator.php
AbstractFileDecorator.addErrorOnLine
public function addErrorOnLine( $error, $line, $code, $data = [], $severity = 0 ) { return $this->__call(__FUNCTION__, func_get_args()); }
php
public function addErrorOnLine( $error, $line, $code, $data = [], $severity = 0 ) { return $this->__call(__FUNCTION__, func_get_args()); }
[ "public", "function", "addErrorOnLine", "(", "$", "error", ",", "$", "line", ",", "$", "code", ",", "$", "data", "=", "[", "]", ",", "$", "severity", "=", "0", ")", "{", "return", "$", "this", "->", "__call", "(", "__FUNCTION__", ",", "func_get_args"...
Records an error against a specific line in the file. @param string $error The error message. @param int $line The line on which the error occurred. @param string $code A violation code unique to the sniff message. @param array $data Replacements for the error message. @param int $severity The severity level for this error. A value of 0 will be converted into the default severity level. @return boolean
[ "Records", "an", "error", "against", "a", "specific", "line", "in", "the", "file", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/AbstractFileDecorator.php#L88-L96
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/AbstractFileDecorator.php
AbstractFileDecorator.addFixableError
public function addFixableError( $error, $stackPtr, $code, $data = [], $severity = 0 ) { return $this->__call(__FUNCTION__, func_get_args()); }
php
public function addFixableError( $error, $stackPtr, $code, $data = [], $severity = 0 ) { return $this->__call(__FUNCTION__, func_get_args()); }
[ "public", "function", "addFixableError", "(", "$", "error", ",", "$", "stackPtr", ",", "$", "code", ",", "$", "data", "=", "[", "]", ",", "$", "severity", "=", "0", ")", "{", "return", "$", "this", "->", "__call", "(", "__FUNCTION__", ",", "func_get_...
Records a fixable error against a specific token in the file. Returns true if the error was recorded and should be fixed. @param string $error The error message. @param int $stackPtr The stack position where the error occurred. @param string $code A violation code unique to the sniff message. @param array $data Replacements for the error message. @param int $severity The severity level for this error. A value of 0 will be converted into the default severity level. @return boolean
[ "Records", "a", "fixable", "error", "against", "a", "specific", "token", "in", "the", "file", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/AbstractFileDecorator.php#L112-L120
train
bestit/PHP_CodeSniffer
src/Standards/BestIt/CodeSniffer/AbstractFileDecorator.php
AbstractFileDecorator.addFixableWarning
public function addFixableWarning( $warning, $stackPtr, $code, $data = [], $severity = 0 ) { return $this->__call(__FUNCTION__, func_get_args()); }
php
public function addFixableWarning( $warning, $stackPtr, $code, $data = [], $severity = 0 ) { return $this->__call(__FUNCTION__, func_get_args()); }
[ "public", "function", "addFixableWarning", "(", "$", "warning", ",", "$", "stackPtr", ",", "$", "code", ",", "$", "data", "=", "[", "]", ",", "$", "severity", "=", "0", ")", "{", "return", "$", "this", "->", "__call", "(", "__FUNCTION__", ",", "func_...
Records a fixable warning against a specific token in the file. Returns true if the warning was recorded and should be fixed. @param string $warning The error message. @param int $stackPtr The stack position where the error occurred. @param string $code A violation code unique to the sniff message. @param array $data Replacements for the warning message. @param int $severity The severity level for this warning. A value of 0 will be converted into the default severity level. @return boolean
[ "Records", "a", "fixable", "warning", "against", "a", "specific", "token", "in", "the", "file", "." ]
a80e1f24642858a0ad20301661037c321128d021
https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/AbstractFileDecorator.php#L136-L144
train