From 1a261efb5e9d0ba881fe2fea5ddba9803a0981cb Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 7 Jul 2024 11:02:25 +0200 Subject: [PATCH] Extract helper function --- monorepo/HydeStan/HydeStan.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/monorepo/HydeStan/HydeStan.php b/monorepo/HydeStan/HydeStan.php index 643c1c69bb7..7b2069e45fe 100644 --- a/monorepo/HydeStan/HydeStan.php +++ b/monorepo/HydeStan/HydeStan.php @@ -303,13 +303,7 @@ public function run(string $file, string $contents): void // Check for false positives $commonlyStringCastables = ['$article', '$document', 'getXmlElement()', '$url->loc', '$page->markdown', '$post->data(\'author\')']; - $strContainsAny = false; - foreach ($commonlyStringCastables as $commonlyStringCastable) { - AnalysisStatisticsContainer::analysedExpression(); - if (str_contains($line, $commonlyStringCastable)) { - $strContainsAny = true; - } - } + $strContainsAny = check_str_contains_any($commonlyStringCastables, $line); if ($strContainsAny) { continue; @@ -426,3 +420,15 @@ public function __construct(string $file, int $lineNumber, string $line); public function run(string $file, int $lineNumber, string $line): void; } + +function check_str_contains_any(array $searches, string $line): bool +{ + $strContainsAny = false; + foreach ($searches as $search) { + AnalysisStatisticsContainer::analysedExpression(); + if (str_contains($line, $search)) { + $strContainsAny = true; + } + } + return $strContainsAny; +}