Completed
Pull Request — master (#38)
by Marco
03:08
created

MultiConstantBased::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\ClassConstantBased;
6
7
use Roave\ApiCompare\Changes;
8
use Roave\BetterReflection\Reflection\ReflectionClassConstant;
9
10
final class MultiConstantBased implements ConstantBased
11
{
12
    /** @var ConstantBased[] */
13
    private $checks;
14
15
    public function __construct(ConstantBased ...$checks)
16
    {
17
        $this->checks = $checks;
18
    }
19
20
    public function compare(ReflectionClassConstant $fromConstant, ReflectionClassConstant $toConstant) : Changes
21
    {
22
        return array_reduce(
23
            $this->checks,
24
            function (Changes $changes, ConstantBased $check) use ($fromConstant, $toConstant) : Changes {
25
                return $changes->mergeWith($check->compare($fromConstant, $toConstant));
26
            },
27
            Changes::new()
28
        );
29
    }
30
}
31