UK
games/alis / tools / undefined.php · commit 9c722cf
<?php// Lists functions called in src/Alis/fn but defined nowhere (and not PHP built-ins); and duplicates.$defined = []; $calls = [];foreach (glob(__DIR__ . '/../src/Alis/fn/*.php') as $f) {    $t = token_get_all(file_get_contents($f));    $n = count($t);    for ($i = 0; $i < $n; $i++) {        if (!is_array($t[$i])) continue;        if ($t[$i][0] === T_FUNCTION) {            for ($j = $i + 1; $j < $n && is_array($t[$j]) && $t[$j][0] === T_WHITESPACE; $j++);            if (is_array($t[$j]) && $t[$j][0] === T_STRING) { $defined[strtolower($t[$j][1])][] = basename($f) . ':' . $t[$j][2]; }            continue;        }        if ($t[$i][0] === T_STRING) {            for ($j = $i + 1; $j < $n && is_array($t[$j]) && $t[$j][0] === T_WHITESPACE; $j++);            if (($t[$j] ?? null) !== '(') continue;            for ($k = $i - 1; $k >= 0 && is_array($t[$k]) && $t[$k][0] === T_WHITESPACE; $k--);            $prev = $t[$k];            if (is_array($prev) && in_array($prev[0], [T_OBJECT_OPERATOR, T_DOUBLE_COLON, T_FUNCTION, T_NEW, T_NULLSAFE_OBJECT_OPERATOR], true)) continue;            $calls[strtolower($t[$i][1])][] = basename($f) . ':' . $t[$i][2];        }    }}foreach ($defined as $name => $where) if (count($where) > 1) echo "DUP $name: " . implode(' ', $where) . "\n";foreach ($calls as $name => $where) {    if (isset($defined[$name]) || function_exists($name) || in_array($name, ['array','list','isset','empty','unset','exit','die','eval','match','fn','declare'])) continue;    echo "UNDEF $name: " . implode(' ', array_slice($where, 0, 4)) . (count($where) > 4 ? ' ...' : '') . "\n";}