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

ConstantValueChanged::compare()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
cc 3
eloc 15
nc 3
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Roave\ApiCompare\Comparator\BackwardsCompatibility\ClassConstantBased;
6
7
use Roave\ApiCompare\Change;
8
use Roave\ApiCompare\Changes;
9
use Roave\BetterReflection\Reflection\ReflectionClassConstant;
10
11
final class ConstantValueChanged implements ConstantBased
12
{
13
    public function compare(ReflectionClassConstant $fromConstant, ReflectionClassConstant $toConstant) : Changes
14
    {
15
        if ($fromConstant->isPrivate()) {
16
            return Changes::new();
17
        }
18
19
        $fromValue = $fromConstant->getValue();
20
        $toValue   = $toConstant->getValue();
21
22
        if ($fromValue === $toValue) {
23
            return Changes::new();
24
        }
25
26
        return Changes::fromArray([
27
            Change::changed(
28
                sprintf(
29
                    'Value of constant %s::%s changed from %s to %s',
30
                    $fromConstant->getDeclaringClass()->getName(),
31
                    $fromConstant->getName(),
32
                    var_export($fromValue, true),
33
                    var_export($toValue, true)
34
                ),
35
                true
36
            ),
37
        ]);
38
    }
39
}
40