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

ConstantValueChanged   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A compare() 0 23 3
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