Passed
Pull Request — master (#38)
by Marco
02:19
created

ClassBecameTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A compare() 0 11 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Roave\ApiCompare\Comparator\BackwardsCompatibility\ClassBased;
6
7
use Assert\Assert;
8
use Roave\ApiCompare\Change;
9
use Roave\ApiCompare\Changes;
10
use Roave\BetterReflection\Reflection\ReflectionClass;
11
use function sprintf;
12
13
/**
14
 * A class cannot become a trait without introducing an explicit BC break, since
15
 * all child classes or implementors need to be changed from `extends` to `use`,
16
 * and all instantiations start failing
17
 */
18
final class ClassBecameTrait implements ClassBased
19
{
20
    public function compare(ReflectionClass $fromClass, ReflectionClass $toClass) : Changes
21
    {
22
        Assert::that($fromClass->getName())->same($toClass->getName());
23
24
        if ($fromClass->isTrait() || ! $toClass->isTrait()) {
25
            return Changes::new();
26
        }
27
28
        return Changes::fromArray([Change::changed(
29
            sprintf('Class %s became a trait', $fromClass->getName()),
30
            true
31
        ),
32
        ]);
33
    }
34
}
35