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

ConstantChanged   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 5 1
A checkSymbols() 0 4 2
A __construct() 0 3 1
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