ClassConstantValueChanged   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 3

1 Method

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