| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassBased; |
||
| 6 | |||
| 7 | use Roave\BackwardCompatibility\Change; |
||
| 8 | use Roave\BackwardCompatibility\Changes; |
||
| 9 | use Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassConstantBased\ClassConstantBased; |
||
| 10 | use Roave\BetterReflection\Reflection\ReflectionClass; |
||
| 11 | use Roave\BetterReflection\Reflection\ReflectionClassConstant; |
||
| 12 | use function array_intersect_key; |
||
| 13 | use function array_keys; |
||
| 14 | |||
| 15 | final class ConstantChanged implements ClassBased |
||
| 16 | { |
||
| 17 | /** @var ClassConstantBased */ |
||
| 18 | private $checkConstant; |
||
| 19 | |||
| 20 | public function __construct(ClassConstantBased $checkConstant) |
||
| 21 | { |
||
| 22 | $this->checkConstant = $checkConstant; |
||
| 23 | } |
||
| 24 | |||
| 25 | public function __invoke(ReflectionClass $fromClass, ReflectionClass $toClass) : Changes |
||
| 26 | { |
||
| 27 | return Changes::fromIterator($this->checkSymbols( |
||
| 28 | $fromClass->getReflectionConstants(), |
||
| 29 | $toClass->getReflectionConstants() |
||
| 30 | )); |
||
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @param ReflectionClassConstant[] $from |
||
| 35 | * @param ReflectionClassConstant[] $to |
||
| 36 | * |
||
| 37 | * @return iterable|Change[] |
||
| 38 | */ |
||
| 39 | private function checkSymbols(array $from, array $to) : iterable |
||
| 40 | { |
||
| 41 | foreach (array_keys(array_intersect_key($from, $to)) as $name) { |
||
| 42 | yield from $this->checkConstant->__invoke($from[$name], $to[$name]); |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 43 | } |
||
| 44 | } |
||
| 45 | } |
||
| 46 |