From 63e9d3ff43f2e26b57b380212503d0ebe19ce489 Mon Sep 17 00:00:00 2001 From: Danny Herpol <15183537+hdcore@users.noreply.github.com> Date: Thu, 28 Sep 2023 05:39:07 +0200 Subject: [PATCH] PHP 8.2 fix for dynamic property $exclude (#653) * PHP 8.2 fix for dynamic property $exclude * Add phpdoc value type for iterable type array * formatting --------- Co-authored-by: Danny Herpol Co-authored-by: Chris Gmyr --- src/Domain/InsightLoader/SniffLoader.php | 10 +++++++++- src/Domain/Insights/SniffDecorator.php | 21 ++++++++------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/Domain/InsightLoader/SniffLoader.php b/src/Domain/InsightLoader/SniffLoader.php index 6d830287..b08152b4 100644 --- a/src/Domain/InsightLoader/SniffLoader.php +++ b/src/Domain/InsightLoader/SniffLoader.php @@ -28,10 +28,18 @@ public function load(string $insightClass, string $dir, array $config, Collector /** @var SniffContract $sniff */ $sniff = new $insightClass(); + $excludeConfig = []; + + if (isset($config['exclude'])) { + /** @var array $excludeConfig */ + $excludeConfig = $config['exclude']; + unset($config['exclude']); + } + foreach ($config as $property => $value) { $sniff->{$property} = $value; } - return new SniffDecorator($sniff, $dir); + return new SniffDecorator($sniff, $dir, $excludeConfig); } } diff --git a/src/Domain/Insights/SniffDecorator.php b/src/Domain/Insights/SniffDecorator.php index 7d8daa0a..0ae0ec1c 100644 --- a/src/Domain/Insights/SniffDecorator.php +++ b/src/Domain/Insights/SniffDecorator.php @@ -34,13 +34,18 @@ final class SniffDecorator implements Sniff, Insight, DetailsCarrier, Fixable */ private array $excludedFiles; - public function __construct(Sniff $sniff, string $dir) + /** + * SniffDecorator constructor. + * + * @param array $exclude + */ + public function __construct(Sniff $sniff, string $dir, array $exclude) { $this->sniff = $sniff; $this->excludedFiles = []; - if ($this->getIgnoredFilesPath() !== []) { - $this->excludedFiles = Files::find($dir, $this->getIgnoredFilesPath()); + if ($exclude !== []) { + $this->excludedFiles = Files::find($dir, $exclude); } } @@ -131,14 +136,4 @@ private function skipFilesFromIgnoreFiles(InsightFile $file): bool $this->excludedFiles ); } - - /** - * Contains the setting for all files which the sniff should ignore. - * - * @return array - */ - private function getIgnoredFilesPath(): array - { - return $this->sniff->exclude ?? []; - } }