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

ClassConstantValueChanged::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
use function sprintf;
11
use function var_export;
12
13
final class ClassConstantValueChanged implements ClassConstantBased
14
{
15
    public function compare(ReflectionClassConstant $fromConstant, ReflectionClassConstant $toConstant) : Changes
16
    {
17
        if ($fromConstant->isPrivate()) {
18
            return Changes::new();
19
        }
20
21
        $fromValue = $fromConstant->getValue();
22
        $toValue   = $toConstant->getValue();
23
24
        if ($fromValue === $toValue) {
25
            return Changes::new();
26
        }
27
28
        return Changes::fromArray([
29
            Change::changed(
30
                sprintf(
31
                    'Value of constant %s::%s changed from %s to %s',
32
                    $fromConstant->getDeclaringClass()->getName(),
33
                    $fromConstant->getName(),
34
                    var_export($fromValue, true),
35
                    var_export($toValue, true)
36
                ),
37
                true
38
            ),
39
        ]);
40
    }
41
}
42