_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q242000
SqlToken.setChildren
validation
public function setChildren($children) { $this->_children = []; foreach ($children as $child) { $child->parent = $this; $this->_children[] = $child; } $this->updateCollectionOffsets(); }
php
{ "resource": "" }
q242001
SqlToken.getIsCollection
validation
public function getIsCollection() { return in_array($this->type, [ self::TYPE_CODE, self::TYPE_STATEMENT, self::TYPE_PARENTHESIS, ], true); }
php
{ "resource": "" }
q242002
SqlToken.getSql
validation
public function getSql() { $code = $this; while ($code->parent !== null) { $code = $code->parent; } return mb_substr($code->content, $this->startOffset, $this->endOffset - $this->startOffset, 'UTF-8'); }
php
{ "resource": "" }
q242003
SqlToken.tokensMatch
validation
private function tokensMatch(SqlToken $patternToken, SqlToken $token, $offset = 0, &$firstMatchIndex = null, &$lastMatchIndex = null) { if ( $patternToken->getIsCollection() !== $token->getIsCollection() || (!$patternToken->getIsCollection() && $patternToken->content !== $token->cont...
php
{ "resource": "" }
q242004
SqlToken.updateCollectionOffsets
validation
private function updateCollectionOffsets() { if (!empty($this->_children)) { $this->startOffset = reset($this->_children)->startOffset; $this->endOffset = end($this->_children)->endOffset; } if ($this->parent !== null) { $this->parent->updateCollectionOffs...
php
{ "resource": "" }
q242005
Command.splitStatements
validation
private function splitStatements($sql, $params) { $semicolonIndex = strpos($sql, ';'); if ($semicolonIndex === false || $semicolonIndex === StringHelper::byteLength($sql) - 1) { return false; } $tokenizer = new SqlTokenizer($sql); $codeToken = $tokenizer->tokeniz...
php
{ "resource": "" }
q242006
Command.extractUsedParams
validation
private function extractUsedParams(SqlToken $statement, $params) { preg_match_all('/(?P<placeholder>[:][a-zA-Z0-9_]+)/', $statement->getSql(), $matches, PREG_SET_ORDER); $result = []; foreach ($matches as $match) { $phName = ltrim($match['placeholder'], ':'); if (isse...
php
{ "resource": "" }
q242007
User.setIdentity
validation
public function setIdentity($identity) { if ($identity instanceof IdentityInterface) { $this->_identity = $identity; } elseif ($identity === null) { $this->_identity = null; } else { throw new InvalidValueException('The identity object must implement Ident...
php
{ "resource": "" }
q242008
User.login
validation
public function login(IdentityInterface $identity, $duration = 0) { if ($this->beforeLogin($identity, false, $duration)) { $this->switchIdentity($identity, $duration); $id = $identity->getId(); $ip = Yii::$app->getRequest()->getUserIP(); if ($this->enableSessi...
php
{ "resource": "" }
q242009
User.regenerateCsrfToken
validation
protected function regenerateCsrfToken() { $request = Yii::$app->getRequest(); if ($request->enableCsrfCookie || $this->enableSession) { $request->getCsrfToken(true); } }
php
{ "resource": "" }
q242010
ErrorException.isFatalError
validation
public static function isFatalError($error) { return isset($error['type']) && in_array($error['type'], [E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, self::E_HHVM_FATAL_ERROR]); }
php
{ "resource": "" }
q242011
ArrayExpression.getIterator
validation
public function getIterator() { $value = $this->getValue(); if ($value instanceof QueryInterface) { throw new InvalidConfigException('The ArrayExpression class can not be iterated when the value is a QueryInterface object'); } if ($value === null) { $value = [...
php
{ "resource": "" }
q242012
MessageController.actionConfig
validation
public function actionConfig($filePath) { $filePath = Yii::getAlias($filePath); $dir = dirname($filePath); if (file_exists($filePath)) { if (!$this->confirm("File '{$filePath}' already exists. Do you wish to overwrite it?")) { return ExitCode::OK; } ...
php
{ "resource": "" }
q242013
MessageController.actionConfigTemplate
validation
public function actionConfigTemplate($filePath) { $filePath = Yii::getAlias($filePath); if (file_exists($filePath)) { if (!$this->confirm("File '{$filePath}' already exists. Do you wish to overwrite it?")) { return ExitCode::OK; } } if (!copy...
php
{ "resource": "" }
q242014
MessageController.actionExtract
validation
public function actionExtract($configFile = null) { $this->initConfig($configFile); $files = FileHelper::findFiles(realpath($this->config['sourcePath']), $this->config); $messages = []; foreach ($files as $file) { $messages = array_merge_recursive($messages, $this->extr...
php
{ "resource": "" }
q242015
MessageController.extractMessages
validation
protected function extractMessages($fileName, $translator, $ignoreCategories = []) { $this->stdout('Extracting messages from '); $this->stdout($fileName, Console::FG_CYAN); $this->stdout("...\n"); $subject = file_get_contents($fileName); $messages = []; $tokens = tok...
php
{ "resource": "" }
q242016
QueryBuilder.resetSequence
validation
public function resetSequence($tableName, $value = null) { $table = $this->db->getTableSchema($tableName); if ($table !== null && $table->sequenceName !== null) { $tableName = $this->db->quoteTableName($tableName); if ($value === null) { $key = reset($table->p...
php
{ "resource": "" }
q242017
QueryBuilder.supportsFractionalSeconds
validation
private function supportsFractionalSeconds() { $version = $this->db->getSlavePdo()->getAttribute(\PDO::ATTR_SERVER_VERSION); return version_compare($version, '5.6.4', '>='); }
php
{ "resource": "" }
q242018
QueryBuilder.defaultTimeTypeMap
validation
private function defaultTimeTypeMap() { $map = [ Schema::TYPE_DATETIME => 'datetime', Schema::TYPE_TIMESTAMP => 'timestamp', Schema::TYPE_TIME => 'time', ]; if ($this->supportsFractionalSeconds()) { $map = [ Schema::TYPE_DATETI...
php
{ "resource": "" }
q242019
Captcha.checkRequirements
validation
public static function checkRequirements() { if (extension_loaded('imagick')) { $imagickFormats = (new \Imagick())->queryFormats('PNG'); if (in_array('PNG', $imagickFormats, true)) { return 'imagick'; } } if (extension_loaded('gd')) { ...
php
{ "resource": "" }
q242020
CookieCollection.get
validation
public function get($name) { return isset($this->_cookies[$name]) ? $this->_cookies[$name] : null; }
php
{ "resource": "" }
q242021
CookieCollection.getValue
validation
public function getValue($name, $defaultValue = null) { return isset($this->_cookies[$name]) ? $this->_cookies[$name]->value : $defaultValue; }
php
{ "resource": "" }
q242022
CookieCollection.has
validation
public function has($name) { return isset($this->_cookies[$name]) && $this->_cookies[$name]->value !== '' && ($this->_cookies[$name]->expire === null || $this->_cookies[$name]->expire === 0 || $this->_cookies[$name]->expire >= time()); }
php
{ "resource": "" }
q242023
CookieCollection.add
validation
public function add($cookie) { if ($this->readOnly) { throw new InvalidCallException('The cookie collection is read only.'); } $this->_cookies[$cookie->name] = $cookie; }
php
{ "resource": "" }
q242024
TranslationController.actionReport
validation
public function actionReport($sourcePath, $translationPath, $title = 'Translation report') { $sourcePath = trim($sourcePath, '/\\'); $translationPath = trim($translationPath, '/\\'); $results = []; $dir = new DirectoryIterator($sourcePath); foreach ($dir as $fileinfo) { ...
php
{ "resource": "" }
q242025
HttpCache.validateCache
validation
protected function validateCache($lastModified, $etag) { if (Yii::$app->request->headers->has('If-None-Match')) { // HTTP_IF_NONE_MATCH takes precedence over HTTP_IF_MODIFIED_SINCE // http://tools.ietf.org/html/rfc7232#section-3.3 return $etag !== null && in_array($etag, ...
php
{ "resource": "" }
q242026
HttpCache.generateEtag
validation
protected function generateEtag($seed) { $etag = '"' . rtrim(base64_encode(sha1($seed, true)), '=') . '"'; return $this->weakEtag ? 'W/' . $etag : $etag; }
php
{ "resource": "" }
q242027
Model.scenarios
validation
public function scenarios() { $scenarios = [self::SCENARIO_DEFAULT => []]; foreach ($this->getValidators() as $validator) { foreach ($validator->on as $scenario) { $scenarios[$scenario] = []; } foreach ($validator->except as $scenario) { ...
php
{ "resource": "" }
q242028
Model.formName
validation
public function formName() { $reflector = new ReflectionClass($this); if (PHP_VERSION_ID >= 70000 && $reflector->isAnonymous()) { throw new InvalidConfigException('The "formName()" method should be explicitly defined for anonymous models'); } return $reflector->getShortNa...
php
{ "resource": "" }
q242029
Model.getAttributeHint
validation
public function getAttributeHint($attribute) { $hints = $this->attributeHints(); return isset($hints[$attribute]) ? $hints[$attribute] : ''; }
php
{ "resource": "" }
q242030
Model.getFirstError
validation
public function getFirstError($attribute) { return isset($this->_errors[$attribute]) ? reset($this->_errors[$attribute]) : null; }
php
{ "resource": "" }
q242031
Model.getErrorSummary
validation
public function getErrorSummary($showAllErrors) { $lines = []; $errors = $showAllErrors ? $this->getErrors() : $this->getFirstErrors(); foreach ($errors as $es) { $lines = array_merge((array)$es, $lines); } return $lines; }
php
{ "resource": "" }
q242032
Model.addErrors
validation
public function addErrors(array $items) { foreach ($items as $attribute => $errors) { if (is_array($errors)) { foreach ($errors as $error) { $this->addError($attribute, $error); } } else { $this->addError($attribute,...
php
{ "resource": "" }
q242033
Model.clearErrors
validation
public function clearErrors($attribute = null) { if ($attribute === null) { $this->_errors = []; } else { unset($this->_errors[$attribute]); } }
php
{ "resource": "" }
q242034
Model.getAttributes
validation
public function getAttributes($names = null, $except = []) { $values = []; if ($names === null) { $names = $this->attributes(); } foreach ($names as $name) { $values[$name] = $this->$name; } foreach ($except as $name) { unset($value...
php
{ "resource": "" }
q242035
Model.activeAttributes
validation
public function activeAttributes() { $scenario = $this->getScenario(); $scenarios = $this->scenarios(); if (!isset($scenarios[$scenario])) { return []; } $attributes = array_keys(array_flip($scenarios[$scenario])); foreach ($attributes as $i => $attribute)...
php
{ "resource": "" }
q242036
Model.load
validation
public function load($data, $formName = null) { $scope = $formName === null ? $this->formName() : $formName; if ($scope === '' && !empty($data)) { $this->setAttributes($data); return true; } elseif (isset($data[$scope])) { $this->setAttributes($data[$scop...
php
{ "resource": "" }
q242037
Tokens.getAnnotationEnd
validation
public function getAnnotationEnd($index) { $currentIndex = null; if (isset($this[$index + 2])) { if ($this[$index + 2]->isType(DocLexer::T_OPEN_PARENTHESIS)) { $currentIndex = $index + 2; } elseif ( isset($this[$index + 3]) && ...
php
{ "resource": "" }
q242038
Tokens.getArrayEnd
validation
public function getArrayEnd($index) { $level = 1; for (++$index, $max = \count($this); $index < $max; ++$index) { if ($this[$index]->isType(DocLexer::T_OPEN_CURLY_BRACES)) { ++$level; } elseif ($this[$index]->isType($index, DocLexer::T_CLOSE_CURLY_BRACES)) { ...
php
{ "resource": "" }
q242039
Tokens.insertAt
validation
public function insertAt($index, Token $token) { $this->setSize($this->getSize() + 1); for ($i = $this->getSize() - 1; $i > $index; --$i) { $this[$i] = isset($this[$i - 1]) ? $this[$i - 1] : new Token(); } $this[$index] = $token; }
php
{ "resource": "" }
q242040
NoSpacesInsideParenthesisFixer.removeSpaceAroundToken
validation
private function removeSpaceAroundToken(Tokens $tokens, $index) { $token = $tokens[$index]; if ($token->isWhitespace() && false === strpos($token->getContent(), "\n")) { $tokens->clearAt($index); } }
php
{ "resource": "" }
q242041
StandardizeIncrementFixer.findStart
validation
private function findStart(Tokens $tokens, $index) { while (!$tokens[$index]->equalsAny(['$', [T_VARIABLE]])) { if ($tokens[$index]->equals(']')) { $index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_INDEX_SQUARE_BRACE, $index); } elseif ($tokens[$index]->isGivenKind(...
php
{ "resource": "" }
q242042
StandardizeIncrementFixer.clearRangeLeaveComments
validation
private function clearRangeLeaveComments(Tokens $tokens, $indexStart, $indexEnd) { for ($i = $indexStart; $i <= $indexEnd; ++$i) { $token = $tokens[$i]; if ($token->isComment()) { continue; } if ($token->isWhitespace("\n\r")) { ...
php
{ "resource": "" }
q242043
TagComparator.shouldBeTogether
validation
public static function shouldBeTogether(Tag $first, Tag $second) { $firstName = $first->getName(); $secondName = $second->getName(); if ($firstName === $secondName) { return true; } foreach (self::$groups as $group) { if (\in_array($firstName, $group...
php
{ "resource": "" }
q242044
VoidReturnFixer.hasVoidReturnAnnotation
validation
private function hasVoidReturnAnnotation(Tokens $tokens, $index) { foreach ($this->findReturnAnnotations($tokens, $index) as $return) { if (['void'] === $return->getTypes()) { return true; } } return false; }
php
{ "resource": "" }
q242045
VoidReturnFixer.hasReturnTypeHint
validation
private function hasReturnTypeHint(Tokens $tokens, $index) { $endFuncIndex = $tokens->getPrevTokenOfKind($index, [')']); $nextIndex = $tokens->getNextMeaningfulToken($endFuncIndex); return $tokens[$nextIndex]->isGivenKind(CT::T_TYPE_COLON); }
php
{ "resource": "" }
q242046
VoidReturnFixer.hasVoidReturn
validation
private function hasVoidReturn(Tokens $tokens, $startIndex, $endIndex) { $tokensAnalyzer = new TokensAnalyzer($tokens); for ($i = $startIndex; $i < $endIndex; ++$i) { if ( // skip anonymous classes ($tokens[$i]->isGivenKind(T_CLASS) && $tokensAnalyzer->is...
php
{ "resource": "" }
q242047
VoidReturnFixer.findReturnAnnotations
validation
private function findReturnAnnotations(Tokens $tokens, $index) { do { $index = $tokens->getPrevNonWhitespace($index); } while ($tokens[$index]->isGivenKind([ T_ABSTRACT, T_FINAL, T_PRIVATE, T_PROTECTED, T_PUBLIC, T_S...
php
{ "resource": "" }
q242048
NamespacedStringTokenGenerator.generate
validation
public function generate($input) { $tokens = []; $parts = explode('\\', $input); foreach ($parts as $index => $part) { $tokens[] = new Token([T_STRING, $part]); if ($index !== \count($parts) - 1) { $tokens[] = new Token([T_NS_SEPARATOR, '\\']); ...
php
{ "resource": "" }
q242049
OrderedImportsFixer.sortAlphabetically
validation
private function sortAlphabetically(array $first, array $second) { // Replace backslashes by spaces before sorting for correct sort order $firstNamespace = str_replace('\\', ' ', $this->prepareNamespace($first['namespace'])); $secondNamespace = str_replace('\\', ' ', $this->prepareNamespace(...
php
{ "resource": "" }
q242050
OrderedImportsFixer.sortByLength
validation
private function sortByLength(array $first, array $second) { $firstNamespace = (self::IMPORT_TYPE_CLASS === $first['importType'] ? '' : $first['importType'].' ').$this->prepareNamespace($first['namespace']); $secondNamespace = (self::IMPORT_TYPE_CLASS === $second['importType'] ? '' : $second['import...
php
{ "resource": "" }
q242051
NoSuperfluousPhpdocTagsFixer.toComparableNames
validation
private function toComparableNames(array $types, array $symbolShortNames) { $normalized = array_map( function ($type) use ($symbolShortNames) { $type = strtolower($type); if (isset($symbolShortNames[$type])) { return $symbolShortNames[$type]; ...
php
{ "resource": "" }
q242052
ClassAttributesSeparationFixer.fixSpaceBelowClassElement
validation
private function fixSpaceBelowClassElement(Tokens $tokens, $classEndIndex, $elementEndIndex) { for ($nextNotWhite = $elementEndIndex + 1;; ++$nextNotWhite) { if (($tokens[$nextNotWhite]->isComment() || $tokens[$nextNotWhite]->isWhitespace()) && false === strpos($tokens[$nextNotWhite]->getContent...
php
{ "resource": "" }
q242053
ClassAttributesSeparationFixer.fixSpaceBelowClassMethod
validation
private function fixSpaceBelowClassMethod(Tokens $tokens, $classEndIndex, $elementEndIndex) { $nextNotWhite = $tokens->getNextNonWhitespace($elementEndIndex); $this->correctLineBreaks($tokens, $elementEndIndex, $nextNotWhite, $nextNotWhite === $classEndIndex ? 1 : 2); }
php
{ "resource": "" }
q242054
ClassAttributesSeparationFixer.fixSpaceAboveClassElement
validation
private function fixSpaceAboveClassElement(Tokens $tokens, $classStartIndex, $elementIndex) { static $methodAttr = [T_PRIVATE, T_PROTECTED, T_PUBLIC, T_ABSTRACT, T_FINAL, T_STATIC]; // find out where the element definition starts $firstElementAttributeIndex = $elementIndex; for ($i ...
php
{ "resource": "" }
q242055
MultilineWhitespaceBeforeSemicolonsFixer.getNewLineIndex
validation
private function getNewLineIndex($index, Tokens $tokens) { $lineEnding = $this->whitespacesConfig->getLineEnding(); for ($index, $count = \count($tokens); $index < $count; ++$index) { if (false !== strstr($tokens[$index]->getContent(), $lineEnding)) { return $index; ...
php
{ "resource": "" }
q242056
PhpdocNoEmptyReturnFixer.fixAnnotation
validation
private function fixAnnotation(DocBlock $doc, Annotation $annotation) { $types = $annotation->getNormalizedTypes(); if (1 === \count($types) && ('null' === $types[0] || 'void' === $types[0])) { $annotation->remove(); } }
php
{ "resource": "" }
q242057
TernaryToNullCoalescingFixer.getMeaningfulSequence
validation
private function getMeaningfulSequence(Tokens $tokens, $start, $end) { $sequence = []; $index = $start; while ($index < $end) { $index = $tokens->getNextMeaningfulToken($index); if ($index >= $end || null === $index) { break; } ...
php
{ "resource": "" }
q242058
MethodArgumentSpaceFixer.fixFunction
validation
private function fixFunction(Tokens $tokens, $startFunctionIndex) { $endFunctionIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startFunctionIndex); $isMultiline = false; $firstWhitespaceIndex = $this->findWhitespaceIndexAfterParenthesis($tokens, $startFunctionIndex, $...
php
{ "resource": "" }
q242059
MethodArgumentSpaceFixer.fixNewline
validation
private function fixNewline(Tokens $tokens, $index, $indentation, $override = true) { if ($tokens[$index + 1]->isComment()) { return; } if ($tokens[$index + 2]->isComment()) { $nextMeaningfulTokenIndex = $tokens->getNextMeaningfulToken($index + 2); if (!$...
php
{ "resource": "" }
q242060
MethodArgumentSpaceFixer.isCommentLastLineToken
validation
private function isCommentLastLineToken(Tokens $tokens, $index) { if (!$tokens[$index]->isComment() || !$tokens[$index + 1]->isWhitespace()) { return false; } $content = $tokens[$index + 1]->getContent(); return $content !== ltrim($content, "\r\n"); }
php
{ "resource": "" }
q242061
BacktickToShellExecFixer.fixBackticks
validation
private function fixBackticks(Tokens $tokens, array $backtickTokens) { // Track indexes for final override ksort($backtickTokens); $openingBacktickIndex = key($backtickTokens); end($backtickTokens); $closingBacktickIndex = key($backtickTokens); // Strip enclosing bac...
php
{ "resource": "" }
q242062
PhpUnitInternalClassFixer.splitUpDocBlock
validation
private function splitUpDocBlock($lines, Tokens $tokens, $docBlockIndex) { $lineContent = $this->getSingleLineDocBlockEntry($lines); $lineEnd = $this->whitespacesConfig->getLineEnding(); $originalIndent = $this->detectIndent($tokens, $tokens->getNextNonWhitespace($docBlockIndex)); r...
php
{ "resource": "" }
q242063
NoEmptyStatementFixer.fixSemicolonAfterCurlyBraceClose
validation
private function fixSemicolonAfterCurlyBraceClose(Tokens $tokens, $index, $curlyCloseIndex) { static $beforeCurlyOpeningKinds = null; if (null === $beforeCurlyOpeningKinds) { $beforeCurlyOpeningKinds = [T_ELSE, T_FINALLY, T_NAMESPACE, T_OPEN_TAG]; } $curlyOpeningIndex = ...
php
{ "resource": "" }
q242064
CombineConsecutiveUnsetsFixer.getPreviousUnsetCall
validation
private function getPreviousUnsetCall(Tokens $tokens, $index) { $previousUnsetSemicolon = $tokens->getPrevMeaningfulToken($index); if (null === $previousUnsetSemicolon) { return $index; } if (!$tokens[$previousUnsetSemicolon]->equals(';')) { return $previousU...
php
{ "resource": "" }
q242065
Tag.getName
validation
public function getName() { if (null === $this->name) { Preg::matchAll('/@[a-zA-Z0-9_-]+(?=\s|$)/', $this->line->getContent(), $matches); if (isset($matches[0][0])) { $this->name = ltrim($matches[0][0], '@'); } else { $this->name = 'other'...
php
{ "resource": "" }
q242066
Tag.setName
validation
public function setName($name) { $current = $this->getName(); if ('other' === $current) { throw new \RuntimeException('Cannot set name on unknown tag.'); } $this->line->setContent(Preg::replace("/@{$current}/", "@{$name}", $this->line->getContent(), 1)); $this-...
php
{ "resource": "" }
q242067
CommentsAnalyzer.isBeforeStructuralElement
validation
public function isBeforeStructuralElement(Tokens $tokens, $index) { $token = $tokens[$index]; if (!$token->isGivenKind([T_COMMENT, T_DOC_COMMENT])) { throw new \InvalidArgumentException('Given index must point to a comment.'); } $nextIndex = $index; do { ...
php
{ "resource": "" }
q242068
CommentsAnalyzer.getCommentBlockIndices
validation
public function getCommentBlockIndices(Tokens $tokens, $index) { if (!$tokens[$index]->isGivenKind(T_COMMENT)) { throw new \InvalidArgumentException('Given index must point to a comment.'); } $commentType = $this->getCommentType($tokens[$index]->getContent()); $indices =...
php
{ "resource": "" }
q242069
CommentsAnalyzer.isValidVariable
validation
private function isValidVariable(Tokens $tokens, $index) { if (!$tokens[$index]->isGivenKind(T_VARIABLE)) { return false; } $nextIndex = $tokens->getNextMeaningfulToken($index); return $tokens[$nextIndex]->equals('='); }
php
{ "resource": "" }
q242070
ExplicitStringVariableFixer.isStringPartToken
validation
private function isStringPartToken(Token $token) { return $token->isGivenKind(T_ENCAPSED_AND_WHITESPACE) || $token->isGivenKind(T_START_HEREDOC) || '"' === $token->getContent() || 'b"' === strtolower($token->getContent()) ; }
php
{ "resource": "" }
q242071
Runner.processException
validation
private function processException($name, $e) { $this->dispatchEvent( FixerFileProcessedEvent::NAME, new FixerFileProcessedEvent(FixerFileProcessedEvent::STATUS_EXCEPTION) ); $this->errorsManager->report(new Error(Error::TYPE_EXCEPTION, $name, $e)); }
php
{ "resource": "" }
q242072
NoPhp4ConstructorFixer.fixConstructor
validation
private function fixConstructor(Tokens $tokens, $className, $classStart, $classEnd) { $php4 = $this->findFunction($tokens, $className, $classStart, $classEnd); if (null === $php4) { // no PHP4-constructor! return; } if (!empty($php4['modifiers'][T_ABSTRACT])...
php
{ "resource": "" }
q242073
NoPhp4ConstructorFixer.fixParent
validation
private function fixParent(Tokens $tokens, $classStart, $classEnd) { // check calls to the parent constructor foreach ($tokens->findGivenKind(T_EXTENDS) as $index => $token) { $parentIndex = $tokens->getNextMeaningfulToken($index); $parentClass = $tokens[$parentIndex]->getCon...
php
{ "resource": "" }
q242074
NoPhp4ConstructorFixer.findFunction
validation
private function findFunction(Tokens $tokens, $name, $startIndex, $endIndex) { $function = $tokens->findSequence([ [T_FUNCTION], [T_STRING, $name], '(', ], $startIndex, $endIndex, false); if (null === $function) { return null; } ...
php
{ "resource": "" }
q242075
NoSpacesAfterFunctionNameFixer.getFunctionyTokenKinds
validation
private function getFunctionyTokenKinds() { static $tokens = [ T_ARRAY, T_ECHO, T_EMPTY, T_EVAL, T_EXIT, T_INCLUDE, T_INCLUDE_ONCE, T_ISSET, T_LIST, T_PRINT, T_REQUIRE, ...
php
{ "resource": "" }
q242076
AbstractFunctionReferenceFixer.find
validation
protected function find($functionNameToSearch, Tokens $tokens, $start = 0, $end = null) { // make interface consistent with findSequence $end = null === $end ? $tokens->count() : $end; // find raw sequence which we can analyse for context $candidateSequence = [[T_STRING, $functionNa...
php
{ "resource": "" }
q242077
Tokens.clearCache
validation
public static function clearCache($key = null) { if (null === $key) { self::$cache = []; return; } if (self::hasCache($key)) { unset(self::$cache[$key]); } }
php
{ "resource": "" }
q242078
Tokens.detectBlockType
validation
public static function detectBlockType(Token $token) { foreach (self::getBlockEdgeDefinitions() as $type => $definition) { if ($token->equals($definition['start'])) { return ['type' => $type, 'isStart' => true]; } if ($token->equals($definition['end'])) {...
php
{ "resource": "" }
q242079
Tokens.fromArray
validation
public static function fromArray($array, $saveIndexes = null) { $tokens = new self(\count($array)); if (null === $saveIndexes || $saveIndexes) { foreach ($array as $key => $val) { $tokens[$key] = $val; } } else { $index = 0; f...
php
{ "resource": "" }
q242080
Tokens.fromCode
validation
public static function fromCode($code) { $codeHash = self::calculateCodeHash($code); if (self::hasCache($codeHash)) { $tokens = self::getCache($codeHash); // generate the code to recalculate the hash $tokens->generateCode(); if ($codeHash === $token...
php
{ "resource": "" }
q242081
Tokens.setSize
validation
public function setSize($size) { if ($this->getSize() !== $size) { $this->changed = true; parent::setSize($size); } }
php
{ "resource": "" }
q242082
Tokens.offsetUnset
validation
public function offsetUnset($index) { $this->changed = true; $this->unregisterFoundToken($this[$index]); parent::offsetUnset($index); }
php
{ "resource": "" }
q242083
Tokens.offsetSet
validation
public function offsetSet($index, $newval) { $this->blockEndCache = []; if (!$this[$index] || !$this[$index]->equals($newval)) { $this->changed = true; if (isset($this[$index])) { $this->unregisterFoundToken($this[$index]); } $this->...
php
{ "resource": "" }
q242084
Tokens.clearChanged
validation
public function clearChanged() { $this->changed = false; if (self::isLegacyMode()) { foreach ($this as $token) { $token->clearChanged(); } } }
php
{ "resource": "" }
q242085
Tokens.clearEmptyTokens
validation
public function clearEmptyTokens() { $limit = $this->count(); $index = 0; for (; $index < $limit; ++$index) { if ($this->isEmptyAt($index)) { break; } } // no empty token found, therefore there is no need to override collection ...
php
{ "resource": "" }
q242086
Tokens.ensureWhitespaceAtIndex
validation
public function ensureWhitespaceAtIndex($index, $indexOffset, $whitespace) { $removeLastCommentLine = static function (self $tokens, $index, $indexOffset, $whitespace) { $token = $tokens[$index]; if (1 === $indexOffset && $token->isGivenKind(T_OPEN_TAG)) { if (0 === ...
php
{ "resource": "" }
q242087
Tokens.generatePartialCode
validation
public function generatePartialCode($start, $end) { $code = ''; for ($i = $start; $i <= $end; ++$i) { $code .= $this[$i]->getContent(); } return $code; }
php
{ "resource": "" }
q242088
Tokens.getNextTokenOfKind
validation
public function getNextTokenOfKind($index, array $tokens = [], $caseSensitive = true) { return $this->getTokenOfKindSibling($index, 1, $tokens, $caseSensitive); }
php
{ "resource": "" }
q242089
Tokens.getNonWhitespaceSibling
validation
public function getNonWhitespaceSibling($index, $direction, $whitespaces = null) { while (true) { $index += $direction; if (!$this->offsetExists($index)) { return null; } $token = $this[$index]; if (!$token->isWhitespace($whitesp...
php
{ "resource": "" }
q242090
Tokens.getPrevTokenOfKind
validation
public function getPrevTokenOfKind($index, array $tokens = [], $caseSensitive = true) { return $this->getTokenOfKindSibling($index, -1, $tokens, $caseSensitive); }
php
{ "resource": "" }
q242091
Tokens.getTokenOfKindSibling
validation
public function getTokenOfKindSibling($index, $direction, array $tokens = [], $caseSensitive = true) { if (!self::isLegacyMode()) { $tokens = array_filter($tokens, function ($token) { return $this->isTokenKindFound($this->extractTokenKind($token)); }); } ...
php
{ "resource": "" }
q242092
Tokens.getTokenNotOfKindSibling
validation
public function getTokenNotOfKindSibling($index, $direction, array $tokens = []) { while (true) { $index += $direction; if (!$this->offsetExists($index)) { return null; } if ($this->isEmptyAt($index)) { continue; }...
php
{ "resource": "" }
q242093
Tokens.getMeaningfulTokenSibling
validation
public function getMeaningfulTokenSibling($index, $direction) { return $this->getTokenNotOfKindSibling( $index, $direction, [[T_WHITESPACE], [T_COMMENT], [T_DOC_COMMENT]] ); }
php
{ "resource": "" }
q242094
Tokens.getNonEmptySibling
validation
public function getNonEmptySibling($index, $direction) { while (true) { $index += $direction; if (!$this->offsetExists($index)) { return null; } if (!$this->isEmptyAt($index)) { return $index; } } }
php
{ "resource": "" }
q242095
Tokens.findSequence
validation
public function findSequence(array $sequence, $start = 0, $end = null, $caseSensitive = true) { $sequenceCount = \count($sequence); if (0 === $sequenceCount) { throw new \InvalidArgumentException('Invalid sequence.'); } // $end defaults to the end of the collection ...
php
{ "resource": "" }
q242096
Tokens.insertAt
validation
public function insertAt($index, $items) { $items = \is_array($items) || $items instanceof self ? $items : [$items]; $itemsCnt = \count($items); if (0 === $itemsCnt) { return; } $oldSize = \count($this); $this->changed = true; $this->blockEndCach...
php
{ "resource": "" }
q242097
Tokens.overrideAt
validation
public function overrideAt($index, $token) { @trigger_error(__METHOD__.' is deprecated and will be removed in 3.0, use offsetSet instead.', E_USER_DEPRECATED); self::$isLegacyMode = true; $this[$index]->override($token); $this->registerFoundToken($token); }
php
{ "resource": "" }
q242098
Tokens.overrideRange
validation
public function overrideRange($indexStart, $indexEnd, $items) { $oldCode = $this->generatePartialCode($indexStart, $indexEnd); $newCode = ''; foreach ($items as $item) { $newCode .= $item->getContent(); } // no changes, return if ($oldCode === $newCode) ...
php
{ "resource": "" }
q242099
Tokens.setCode
validation
public function setCode($code) { // No need to work when the code is the same. // That is how we avoid a lot of work and setting changed flag. if ($code === $this->generateCode()) { return; } // clear memory $this->setSize(0); $tokens = \defined(...
php
{ "resource": "" }