Passed
Pull Request — master (#38)
by Marco
02:40
created

MultipleChecksOnAProperty::compare()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Roave\ApiCompare\Comparator\BackwardsCompatibility\PropertyBased;
6
7
use Roave\ApiCompare\Changes;
8
use Roave\BetterReflection\Reflection\ReflectionProperty;
9
use function array_reduce;
10
11
final class MultipleChecksOnAProperty implements PropertyBased
12
{
13
    /** @var PropertyBased[] */
14
    private $checks;
15
16
    public function __construct(PropertyBased ...$checks)
17
    {
18
        $this->checks = $checks;
19
    }
20
21
    public function compare(ReflectionProperty $fromProperty, ReflectionProperty $toProperty) : Changes
22
    {
23
        return array_reduce(
24
            $this->checks,
25
            function (Changes $changes, PropertyBased $check) use ($fromProperty, $toProperty) : Changes {
26
                return $changes->mergeWith($check->compare($fromProperty, $toProperty));
27
            },
28
            Changes::new()
29
        );
30
    }
31
}
32