findUseAliases($path, $relative)); } return $errors; } /** @return list */ private function findUseAliases(string $path, string $relative): array { $errors = []; $inUse = false; $braceDepth = 0; foreach (file($path) as $idx => $raw) { $code = explode('//', $raw, 2)[0]; $stripped = trim($code); if (!$inUse) { if (!preg_match(self::USE_ALIAS_START_RE, $stripped)) { continue; } $inUse = true; $braceDepth = 0; } if (preg_match_all('/\bas\s+([A-Za-z_][A-Za-z0-9_]*)/', $code, $m)) { foreach ($m[1] as $name) { if ($name === '_') { continue; } if (preg_match(self::PASCAL_CASE_RE, $name)) { continue; } $errors[] = "{$relative}:" . ($idx + 1) . ": `as {$name}` aliasing in `use` statement"; } } $braceDepth += substr_count($code, '{') - substr_count($code, '}'); if ($braceDepth <= 0 && str_ends_with(rtrim($code), ';')) { $inUse = false; $braceDepth = 0; } } return $errors; } }