Completed
Pull Request — master (#38)
by Marco
03:08
created

PropertyDefaultValueChanged::compare()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 12
nc 2
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\ApiCompare\Formatter\ReflectionPropertyName;
10
use Roave\BetterReflection\Reflection\ReflectionProperty;
11
12
final class PropertyDefaultValueChanged implements PropertyBased
13
{
14
    /** @var ReflectionPropertyName */
15
    private $formatProperty;
16
17
    public function __construct()
18
    {
19
        $this->formatProperty = new ReflectionPropertyName();
20
    }
21
22
    public function compare(ReflectionProperty $fromProperty, ReflectionProperty $toProperty) : Changes
23
    {
24
        $fromPropertyDefaultValue = $fromProperty->getDefaultValue();
25
        $toPropertyDefaultValue   = $toProperty->getDefaultValue();
26
27
        if ($fromPropertyDefaultValue === $toPropertyDefaultValue) {
28
            return Changes::new();
29
        }
30
31
        return Changes::fromArray([
32
            Change::changed(
33
                sprintf(
34
                    'Property %s changed default value from %s to %s',
35
                    $this->formatProperty->__invoke($fromProperty),
36
                    var_export($fromPropertyDefaultValue, true),
37
                    var_export($toPropertyDefaultValue, true)
38
                ),
39
                true
40
            )
41
        ]);
42
    }
43
}
44