PHPで==,!=演算子が使われていないかチェックする奴書いた
某所でもキモいといわれている==演算子が使われていないかチェックするスクリプトを書いた。
ソース
<?php // eqfind.php while ($path = rtrim(fgets(STDIN))) analyze_file($path); function analyze_file($path) { if (!file_exists($path)) throw new Exception("'{$path}' is not found."); $result = array(); foreach (token_get_all(file_get_contents($path)) as $token) if ($_ = analyze_token($token)) $result[] = $_; display($result, $path); } function display($result, $path) { if (!count($result)) { return; } echo "{$path}:" . PHP_EOL; foreach ($result as $_) echo " '{$_[1]}' is found on line {$_[2]}" . PHP_EOL; echo PHP_EOL; } function analyze_token($token) { return is_array($token) && ($token[1] === '==' || $token[1] === '!=') ? $token : false; }