ClassConstantValueChanged::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

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