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

PropertyDefaultValueChanged   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\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