From a1766086c51bf2c1f55af5ca6b63a5b2cd4f655d Mon Sep 17 00:00:00 2001 From: wapmorgan Date: Sat, 15 Apr 2017 21:20:21 +0300 Subject: [PATCH] Fix errors on ::class code --- src/PhpCodeFixer.php | 45 ++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/PhpCodeFixer.php b/src/PhpCodeFixer.php index 68149a6..b28a440 100644 --- a/src/PhpCodeFixer.php +++ b/src/PhpCodeFixer.php @@ -174,29 +174,34 @@ static public function checkFile($file, IssuesBank $issues, Report $report = nul $total = count($tokens); $i = array_search_column($tokens, T_CLASS, 0); $class_start = $i; - $class_name = $tokens[$i+2][1]; - $braces = 1; - $i += 5; - while (($braces > 0) && (($i+1) <= $total)) { - if ($tokens[$i] == '{') { - $braces++; - /*echo '++';*/ - } else if ($tokens[$i] == '}') { - $braces--; - /*echo '--';*/ - } else if (is_array($tokens[$i]) && $tokens[$i][0] == T_FUNCTION && is_array($tokens[$i+2])) { - $function_name = $tokens[$i+2][1]; - foreach ($methods_naming as $methods_naming_checker) { - $checker = ltrim($methods_naming_checker[0], '@'); - require_once dirname(dirname(__FILE__)).'/data/'.$checker.'.php'; - $checker = __NAMESPACE__.'\\'.$checker; - $result = $checker($class_name, $function_name); - if ($result) { - $report->add($methods_naming_checker[1], 'method_name', $function_name.':'.$class_name.' ('.$methods_naming_checker[0].')', null, $file, $tokens[$i][2]); - } + if (!is_array($tokens[$class_start-1]) || $tokens[$class_start-1][1] != '::') { + $class_name = $tokens[$i+2][1]; + $braces = 1; + $i += 5; + while (($braces > 0) && (($i+1) <= $total)) { + if ($tokens[$i] == '{') { + $braces++; + /*echo '++';*/ + } else if ($tokens[$i] == '}') { + $braces--; + /*echo '--';*/ + } else if (is_array($tokens[$i]) && $tokens[$i][0] == T_FUNCTION && is_array($tokens[$i+2])) { + $function_name = $tokens[$i+2][1]; + foreach ($methods_naming as $methods_naming_checker) { + $checker = ltrim($methods_naming_checker[0], '@'); + require_once dirname(dirname(__FILE__)).'/data/'.$checker.'.php'; + $checker = __NAMESPACE__.'\\'.$checker; + $result = $checker($class_name, $function_name); + if ($result) { + $report->add($methods_naming_checker[1], 'method_name', $function_name.':'.$class_name.' ('.$methods_naming_checker[0].')', null, $file, $tokens[$i][2]); + } + } } + $i++; } + } else { + // ::class $i++; } array_splice($tokens, $class_start, $i - $class_start);