Passed
Pull Request — master (#38)
by Marco
03:11
created

PropertyDefaultValueChanged::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\PropertyBased;
6
7
use Roave\ApiCompare\Change;
8
use Roave\ApiCompare\Changes;
9
use Roave\BetterReflection\Reflection\ReflectionProperty;
10
11
final class PropertyDefaultValueChanged implements PropertyBased
12
{
13
    public function compare(ReflectionProperty $fromProperty, ReflectionProperty $toProperty) : Changes
14
    {
15
        if ($fromProperty->isPrivate()) {
16
            return Changes::new();
17
        }
18
19
        $fromPropertyDefaultValue = $fromProperty->getDefaultValue();
20
        $toPropertyDefaultValue   = $toProperty->getDefaultValue();
21
22
        if ($fromPropertyDefaultValue === $toPropertyDefaultValue) {
23
            return Changes::new();
24
        }
25
26
        return Changes::fromArray([
27
            Change::changed(
28
                sprintf(
29
                    'Property %s::$%s changed default value from %s to %s',
30
                    $fromProperty->getDeclaringClass()->getName(),
31
                    $fromProperty->getName(),
32
                    var_export($fromPropertyDefaultValue, true),
33
                    var_export($toPropertyDefaultValue, true)
34
                ),
35
                true
36
            )
37
        ]);
38
    }
39
}
40