Skip to content

Commit

Permalink
token_get_all() can trigger error
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed May 12, 2020
1 parent 5d2002f commit 2d0879e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static function utf8Checker(string $contents, Result $result): void

public static function invalidPhpDocChecker(string $contents, Result $result): void
{
foreach (token_get_all($contents) as $token) {
foreach (@token_get_all($contents) as $token) { // @ can trigger error
if ($token[0] === T_COMMENT && Strings::match($token[1], '#/\*(?!\*).*(?<!\w)@[a-z]#isA')) {
$result->warning('Missing /** in phpDoc comment', $token[2]);

Expand All @@ -54,7 +54,7 @@ public static function shortArraySyntaxFixer(string &$contents, Result $result):
$out = '';
$brackets = [];
try {
$tokens = token_get_all($contents, TOKEN_PARSE);
$tokens = @token_get_all($contents, TOKEN_PARSE); // @ can trigger error
} catch (\ParseError $e) {
return;
}
Expand Down Expand Up @@ -88,7 +88,7 @@ public static function shortArraySyntaxFixer(string &$contents, Result $result):
public static function strictTypesDeclarationChecker(string $contents, Result $result): void
{
$declarations = '';
$tokens = token_get_all($contents);
$tokens = @token_get_all($contents); // @ can trigger error
for ($i = 0; $i < count($tokens); $i++) {
if ($tokens[$i][0] === T_DECLARE) {
while (isset($tokens[++$i]) && $tokens[$i] !== ';') {
Expand All @@ -107,7 +107,7 @@ public static function strictTypesDeclarationChecker(string $contents, Result $r
public static function invalidDoubleQuotedStringChecker(string $contents, Result $result): void
{
$prev = null;
foreach (token_get_all($contents) as $token) {
foreach (@token_get_all($contents) as $token) { // @ can trigger error
if (($token[0] === T_ENCAPSED_AND_WHITESPACE && ($prev[0] !== T_START_HEREDOC || !strpos($prev[1], "'")))
|| ($token[0] === T_CONSTANT_ENCAPSED_STRING && $token[1][0] === '"')
) {
Expand Down Expand Up @@ -254,7 +254,7 @@ public static function tabIndentationChecker(string $contents, Result $result, s
public static function tabIndentationPhpChecker(string $contents, Result $result): void
{
$s = ''; // remove strings from code
foreach (token_get_all($contents) as $token) {
foreach (@token_get_all($contents) as $token) { // @ can trigger error
if (is_array($token) && in_array($token[0], [T_ENCAPSED_AND_WHITESPACE, T_CONSTANT_ENCAPSED_STRING], true)) {
$token[1] = preg_replace('#\s#', '.', $token[1]);
}
Expand Down

0 comments on commit 2d0879e

Please sign in to comment.