PropertyDefaultValueChanged   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __invoke() 0 17 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Roave\BackwardCompatibility\DetectChanges\BCBreak\PropertyBased;
6
7
use Roave\BackwardCompatibility\Change;
8
use Roave\BackwardCompatibility\Changes;
9
use Roave\BackwardCompatibility\Formatter\ReflectionPropertyName;
10
use Roave\BetterReflection\Reflection\ReflectionProperty;
11
use function Safe\sprintf;
12
use function var_export;
13
14
final class PropertyDefaultValueChanged implements PropertyBased
15
{
16
    /** @var ReflectionPropertyName */
17
    private $formatProperty;
18
19
    public function __construct()
20
    {
21
        $this->formatProperty = new ReflectionPropertyName();
22
    }
23
24
    public function __invoke(ReflectionProperty $fromProperty, ReflectionProperty $toProperty) : Changes
25
    {
26
        $fromPropertyDefaultValue = $fromProperty->getDefaultValue();
27
        $toPropertyDefaultValue   = $toProperty->getDefaultValue();
28
29
        if ($fromPropertyDefaultValue === $toPropertyDefaultValue) {
30
            return Changes::empty();
31
        }
32
33
        return Changes::fromList(Change::changed(
34
            sprintf(
35
                'Property %s changed default value from %s to %s',
36
                $this->formatProperty->__invoke($fromProperty),
37
                var_export($fromPropertyDefaultValue, true),
38
                var_export($toPropertyDefaultValue, true)
39
            ),
40
            true
41
        ));
42
    }
43
}
44