Skip to content

Commit

Permalink
Add a rule that ensures we don't use GLOB_BRACE
Browse files Browse the repository at this point in the history
This is as it does not work on all systems
  • Loading branch information
caendesilva committed Dec 11, 2024
1 parent 4a0c1c8 commit 4974f47
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions monorepo/HydeStan/HydeStan.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ final class HydeStan
private const FILE_ANALYSERS = [
NoFixMeAnalyser::class,
UnImportedFunctionAnalyser::class,
NoGlobBraceAnalyser::class,
];

private const TEST_FILE_ANALYSERS = [
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4974f47

Please sign in to comment.