From 4974f4707cb6e3084bb5c2f24c45eb9d9392351d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 11 Dec 2024 21:56:51 +0100 Subject: [PATCH] Add a rule that ensures we don't use `GLOB_BRACE` This is as it does not work on all systems --- monorepo/HydeStan/HydeStan.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/monorepo/HydeStan/HydeStan.php b/monorepo/HydeStan/HydeStan.php index 279fed01ce4..96d28ff3a9c 100644 --- a/monorepo/HydeStan/HydeStan.php +++ b/monorepo/HydeStan/HydeStan.php @@ -15,6 +15,7 @@ final class HydeStan private const FILE_ANALYSERS = [ NoFixMeAnalyser::class, UnImportedFunctionAnalyser::class, + NoGlobBraceAnalyser::class, ]; private const TEST_FILE_ANALYSERS = [ @@ -370,6 +371,27 @@ public function run(string $file, string $contents): void } } +class NoGlobBraceAnalyser extends FileAnalyser +{ + public function run(string $file, string $contents): void + { + $lines = explode("\n", $contents); + + foreach ($lines as $lineNumber => $line) { + AnalysisStatisticsContainer::analysedExpression(); + + if (str_contains($line, 'GLOB_BRACE')) { + $this->fail(sprintf('Usage of `GLOB_BRACE` found in %s at line %d. This feature is not supported on all systems and should be avoided.', + realpath(BASE_PATH.'/'.$file), + $lineNumber + 1 + )); + + HydeStan::addActionsMessage('error', $file, $lineNumber + 1, 'HydeStan: NoGlobBraceError', '`GLOB_BRACE` is not supported on all systems. Consider refactoring to avoid it.'); + } + } + } +} + class NoTestReferenceAnalyser extends LineAnalyser { public function run(string $file, int $lineNumber, string $line): void