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

PropertyChanged::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\PropertyBased\PropertyBased;
10
use Roave\BetterReflection\Reflection\ReflectionClass;
11
use Roave\BetterReflection\Reflection\ReflectionProperty;
12
use function array_intersect_key;
13
use function array_keys;
14
15
final class PropertyChanged implements ClassBased
16
{
17
    /** @var PropertyBased */
18
    private $checkProperty;
19
20
    public function __construct(PropertyBased $checkProperty)
21
    {
22
        $this->checkProperty = $checkProperty;
23
    }
24
25
    public function __invoke(ReflectionClass $fromClass, ReflectionClass $toClass) : Changes
26
    {
27
        return Changes::fromIterator($this->checkSymbols(
28
            $fromClass->getProperties(),
29
            $toClass->getProperties()
30
        ));
31
    }
32
33
    /**
34
     * @param ReflectionProperty[] $from
35
     * @param ReflectionProperty[] $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->checkProperty->__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