mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-11 13:42:22 +00:00
6ab38a869f
2ac26e77e6
Cache comment consistency (#5461)
48 lines
1.4 KiB
PHP
48 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\Skipper\SkipCriteriaResolver;
|
|
|
|
use Rector\Configuration\Option;
|
|
use Rector\Configuration\Parameter\SimpleParameterProvider;
|
|
use Rector\Testing\PHPUnit\StaticPHPUnitEnvironment;
|
|
final class SkippedClassResolver
|
|
{
|
|
/**
|
|
* @var null|array<string, string[]|null>
|
|
*/
|
|
private $skippedClasses = null;
|
|
/**
|
|
* @return array<string, string[]|null>
|
|
*/
|
|
public function resolve() : array
|
|
{
|
|
// disable cache in tests
|
|
if (StaticPHPUnitEnvironment::isPHPUnitRun()) {
|
|
$this->skippedClasses = null;
|
|
}
|
|
// already cached, even only empty array
|
|
if ($this->skippedClasses !== null) {
|
|
return $this->skippedClasses;
|
|
}
|
|
$skip = SimpleParameterProvider::provideArrayParameter(Option::SKIP);
|
|
$this->skippedClasses = [];
|
|
foreach ($skip as $key => $value) {
|
|
// e.g. [SomeClass::class] → shift values to [SomeClass::class => null]
|
|
if (\is_int($key)) {
|
|
$key = $value;
|
|
$value = null;
|
|
}
|
|
if (!\is_string($key)) {
|
|
continue;
|
|
}
|
|
// this only checks for Rector rules, that are always autoloaded
|
|
if (!\class_exists($key) && !\interface_exists($key)) {
|
|
continue;
|
|
}
|
|
$this->skippedClasses[$key] = $value;
|
|
}
|
|
return $this->skippedClasses;
|
|
}
|
|
}
|