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

PropertyDefaultValueChanged   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A compare() 0 18 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