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

ConstantChanged   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A compare() 0 15 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Roave\ApiCompare\Comparator\BackwardsCompatibility\ClassBased;
6
7
use Roave\ApiCompare\Changes;
8
use Roave\ApiCompare\Comparator\BackwardsCompatibility\ClassConstantBased\ConstantBased;
9
use Roave\BetterReflection\Reflection\ReflectionClass;
10
11
final class ConstantChanged implements ClassBased
12
{
13
    /** @var ConstantBased */
14
    private $checkConstant;
15
16
    public function __construct(ConstantBased $checkConstant)
17
    {
18
        $this->checkConstant = $checkConstant;
19
    }
20
21
    public function compare(ReflectionClass $fromClass, ReflectionClass $toClass) : Changes
22
    {
23
        $constantsFrom   = $fromClass->getReflectionConstants();
24
        $constantsTo     = $toClass->getReflectionConstants();
25
        $commonConstants = array_intersect_key($constantsFrom, $constantsTo);
26
27
        return array_reduce(
28
            array_keys($commonConstants),
29
            function (Changes $accumulator, string $constantName) use ($constantsFrom, $constantsTo) : Changes {
30
                return $accumulator->mergeWith($this->checkConstant->compare(
31
                    $constantsFrom[$constantName],
32
                    $constantsTo[$constantName])
33
                );
34
            },
35
            Changes::new()
36
        );
37
    }
38
}
39