Skip to content

Commit

Permalink
PHP 8.2 fix for dynamic property $exclude (#653)
Browse files Browse the repository at this point in the history
* PHP 8.2 fix for dynamic property $exclude

* Add phpdoc value type for iterable type array

* formatting

---------

Co-authored-by: Danny Herpol <hdcore@lachjekrom.com>
Co-authored-by: Chris Gmyr <cmgmyr@gmail.com>
  • Loading branch information
3 people committed Sep 28, 2023
1 parent 692d9e4 commit 63e9d3f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
10 changes: 9 additions & 1 deletion src/Domain/InsightLoader/SniffLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> $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);
}
}
21 changes: 8 additions & 13 deletions src/Domain/Insights/SniffDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> $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);
}
}

Expand Down Expand Up @@ -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<int, string>
*/
private function getIgnoredFilesPath(): array
{
return $this->sniff->exclude ?? [];
}
}

0 comments on commit 63e9d3f

Please sign in to comment.