Passed
Pull Request — master (#108)
by Marco
02:35
created

ConstantChanged::checkSymbols()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
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
The expression YieldFromNode returns the type Generator which is incompatible with the documented return type iterable|Roave\BackwardCompatibility\Change[].
Loading history...
43
        }
44
    }
45
}
46