public getTokenList ( ) : HippoPHP\Tokenizer\TokenListIterator | ||
리턴 | HippoPHP\Tokenizer\TokenListIterator |
/** * checkFileInternal(): defined by AbstractCheck. * * @see AbstractCheck::checkFileInternal() * * @param CheckContext $checkContext * @param Config $config */ protected function checkFileInternal(CheckContext $checkContext, Config $config) { $file = $checkContext->getFile(); $tokens = $checkContext->getTokenList(); $firstToken = $tokens->rewind()->current(); if (!$firstToken->isType(T_OPEN_TAG)) { $this->addViolation($file, 1, 1, 'Files must begin with the PHP open tag.'); } }
/** * checkFileInternal(): defined by AbstractCheck. * * @see AbstractCheck::checkFileInternal() * * @param CheckContext $checkContext * @param Config $config */ protected function checkFileInternal(CheckContext $checkContext, Config $config) { $file = $checkContext->getFile(); $tokens = $checkContext->getTokenList(); $endToken = $tokens->end()->current(); if (count($file) > 0) { if ($config->get('endwith') && !$endToken->isType(T_CLOSE_TAG)) { $this->addViolation($file, $endToken->getLine(), 0, 'Files must end with a closing tag.'); } elseif (!$config->get('endwith') && $endToken->isType(T_CLOSE_TAG)) { $this->addViolation($file, $endToken->getLine(), 0, 'Files must not end with a closing tag.'); } } }
/** * checkFileInternal(): defined by AbstractCheck. * * @see AbstractCheck::checkFileInternal() * * @param CheckContext $checkContext * @param Config $config */ protected function checkFileInternal(CheckContext $checkContext, Config $config) { $file = $checkContext->getFile(); $tokens = $checkContext->getTokenList(); try { do { // Jump us to the next token we want to check. $token = $tokens->seekToType(T_COMMENT)->current(); if (strpos($token->getContent(), '#') === 0) { $this->addViolation($file, $token->getLine(), $token->getColumn(), 'Avoid using bash style comments.', Violation::SEVERITY_ERROR); } } while ($tokens->valid()); } catch (\HippoPHP\Tokenizer\Exception\OutOfBoundsException $e) { // Ignore the exception, we're at the end of the file. } }
/** * checkFileInternal(): defined by AbstractCheck. * * @see AbstractCheck::checkFileInternal() * * @param CheckContext $checkContext * @param Config $config */ protected function checkFileInternal(CheckContext $checkContext, Config $config) { $file = $checkContext->getFile(); $tokens = $checkContext->getTokenList(); try { do { // Jump us to the next token we want to check. $token = $tokens->seekToType($this->tokens)->current(); $using = $token->getContent(); $should = $this->useLookup[$token->getType()]; $this->addViolation($file, trim($token->getLine()), trim($token->getColumn()), sprintf('Use bitwise condition %s instead of %s', $using, $should)); } while ($tokens->valid()); } catch (\HippoPHP\Tokenizer\Exception\OutOfBoundsException $e) { // Ignore the exception, we're at the end of the file. } }
/** * checkFileInternal(): defined by AbstractCheck. * * @see AbstractCheck::checkFileInternal() * * @param CheckContext $checkContext * @param Config $config */ protected function checkFileInternal(CheckContext $checkContext, Config $config) { $file = $checkContext->getFile(); $tokens = $checkContext->getTokenList(); try { do { // Jump us to the next token we want to check. $tokens->seekToType([T_IS_EQUAL, T_IS_NOT_EQUAL]); $token = $tokens->current(); if (in_array($token->getContent(), $this->sources)) { $this->addViolation($file, $token->getLine(), $token->getColumn(), sprintf('Avoid the use of the non-strict operator `%s`.', $token->getContent()), Violation::SEVERITY_WARNING); } } while ($tokens->valid()); } catch (\HippoPHP\Tokenizer\Exception\OutOfBoundsException $e) { // Ignore the exception, we're at the end of the file. } }
/** * checkFileInternal(): defined by AbstractCheck. * * @see AbstractCheck::checkFileInternal() * * @param CheckContext $checkContext * @param Config $config */ protected function checkFileInternal(CheckContext $checkContext, Config $config) { $file = $checkContext->getFile(); $tokens = $checkContext->getTokenList(); try { do { // Jump us to the next token we want to check. $tokens->seekToType(T_ELSE)->skipToNextNonWhitespace(); if ($tokens->current()->isType(T_IF)) { $token = $tokens->current(); $this->addViolation($file, $token->getLine(), $token->getColumn(), 'Use `elseif` rather than `else if`'); } } while ($tokens->valid()); } catch (\HippoPHP\Tokenizer\Exception\OutOfBoundsException $e) { // Ignore the exception, we're at the end of the file. } }
/** * checkFileInternal(): defined by AbstractCheck. * * @see AbstractCheck::checkFileInternal() * * @param CheckContext $checkContext * @param Config $config */ protected function checkFileInternal(CheckContext $checkContext, Config $config) { $file = $checkContext->getFile(); $tokens = $checkContext->getTokenList(); $this->setPattern($config->get('pattern', $this->pattern)); try { do { // Jump us to the next token we want to check. $tokens->seekToType(T_PRIVATE)->skipToNextNonWhitespace(); $token = $tokens->current(); if ($token->isType(T_VARIABLE)) { if (!preg_match($this->pattern, $token->getContent())) { $this->addViolation($file, $token->getLine(), $token->getColumn(), sprintf('Private variable `%s` should follow a `%s` pattern', $token->getContent(), addslashes($this->pattern)), Violation::SEVERITY_ERROR); } } } while ($tokens->valid()); } catch (\HippoPHP\Tokenizer\Exception\OutOfBoundsException $e) { // Ignore the exception, we're at the end of the file. } }
/** * checkFileInternal(): defined by AbstractCheck. * * @see AbstractCheck::checkFileInternal() * * @param CheckContext $checkContext * @param Config $config */ protected function checkFileInternal(CheckContext $checkContext, Config $config) { $file = $checkContext->getFile(); $tokens = $checkContext->getTokenList(); try { do { // Jump us to the next token we want to check. $token = $tokens->seekToType(T_STRING)->current(); $tokenContent = $token->getContent(); $lowerContent = strtolower($tokenContent); if ($token->isNativeConstant()) { if ($tokenContent !== $lowerContent) { $this->addViolation($file, $token->getLine(), $token->getColumn(), sprintf('`%s` should be in lowercase.', $tokenContent), Violation::SEVERITY_INFO); } } } while ($tokens->valid()); } catch (\HippoPHP\Tokenizer\Exception\OutOfBoundsException $e) { // Ignore the exception, we're at the end of the file. } }
/** * checkFileInternal(): defined by AbstractCheck. * * @see AbstractCheck::checkFileInternal() * * @param CheckContext $checkContext * @param Config $config */ protected function checkFileInternal(CheckContext $checkContext, Config $config) { $file = $checkContext->getFile(); $tokens = $checkContext->getTokenList(); try { do { // Jump us to the next token we want to check. $tokens->seekToType(T_USE)->skipToNextNonWhitespace()->current(); if ($tokens->current()->getContent() !== '(') { // Now if the next token does not equal T_NS_SEPARATOR we are not fully qualified. if (!$tokens->current()->isType(T_NS_SEPARATOR)) { $token = $tokens->current(); $this->addViolation($file, $token->getLine(), $token->getColumn(), 'Use fully qualified namespaces.'); } } } while ($tokens->valid()); } catch (\HippoPHP\Tokenizer\Exception\OutOfBoundsException $e) { // Ignore the exception, we're at the end of the file. } }
/** * checkFileInternal(): defined by AbstractCheck. * * @see AbstractCheck::checkFileInternal() * * @param CheckContext $checkContext * @param Config $config */ protected function checkFileInternal(CheckContext $checkContext, Config $config) { $file = $checkContext->getFile(); $tokens = $checkContext->getTokenList(); try { do { // Jump us to the next token we want to check. $tokens->seekToType(T_VARIABLE); $token = $tokens->current(); // If the content !== $ then go back a token, is that $? if ($token->getContent() !== '$') { $prevTokenList = clone $tokens; $prevToken = $prevTokenList->prev()->current(); if ($prevToken->getContent() === '$') { $this->addViolation($file, $token->getLine(), $token->getColumn(), 'Do not use variable variables.', Violation::SEVERITY_ERROR); } } } while ($tokens->valid()); } catch (\HippoPHP\Tokenizer\Exception\OutOfBoundsException $e) { // Ignore the exception, we're at the end of the file. } }
/** * checkFileInternal(): defined by AbstractCheck. * * @see AbstractCheck::checkFileInternal() * * @param CheckContext $checkContext * @param Config $config */ protected function checkFileInternal(CheckContext $checkContext, Config $config) { $file = $checkContext->getFile(); $tokens = $checkContext->getTokenList(); $this->setQuoteStyle($config->get('style', $this->style)); try { do { // Jump us to the next token we want to check. $tokens->seekToType(T_CONSTANT_ENCAPSED_STRING); $token = $tokens->current(); if ($this->isBadStyle($token)) { // Work out what style we shouldn't be using. $styles = $this->styles; unset($styles[$this->style]); $badStyle = array_keys($styles)[0]; $this->addViolation($file, $token->getLine(), $token->getColumn(), sprintf('Prefer %s quotes to %s', addslashes($this->style), $badStyle), Violation::SEVERITY_INFO); } } while ($tokens->valid()); } catch (\HippoPHP\Tokenizer\Exception\OutOfBoundsException $e) { // Ignore the exception, we're at the end of the file. } }
/** * checkFileInternal(): defined by AbstractCheck. * * @see AbstractCheck::checkFileInternal() * * @param \HippoPHP\Hippo\CheckContext $checkContext * @param \HippoPHP\Hippo\Config\Config $config */ protected function checkFileInternal(CheckContext $checkContext, Config $config) { $file = $checkContext->getFile(); $this->setIndentStyle($config->get('style', $this->indentStyle)); $this->setIndentCount($config->get('count', $this->indentCount)); $indentation = $this->getBaseIndentation(); $lines = $this->getLines($checkContext->getTokenList()); $level = 0; foreach ($lines as $lineNumber => $line) { $actualIndentation = ''; if (count($line) > 0) { if ($line[0]->isType(T_WHITESPACE)) { $actualIndentation = $line[0]->getContent(); } } foreach ($line as $token) { $content = $token->getContent(); if ($content === '}' || $content === ')' || $content === ']') { $level--; } } $expectedIndentation = $level > 0 ? str_repeat($indentation, $level) : ''; if ($expectedIndentation !== $actualIndentation) { $this->addViolation($file, $lineNumber, count($line) > 0 ? $line[0]->getColumn() + strlen($line[0]->getContent()) : 1, sprintf('Unexpected indentation (expected: %s, actual: %s)', $this->escape($expectedIndentation), $this->escape($actualIndentation)), Violation::SEVERITY_WARNING); } foreach ($line as $token) { $content = $token->getContent(); if ($content === '{' || $content === '(' || $content === '[') { $level++; } } } }