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

TraitBecameInterface   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A compare() 0 11 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Roave\ApiCompare\Comparator\BackwardsCompatibility\TraitBased;
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 trait cannot change to become a interface, as that forces all implementations
15
 * that use it to change from `use` to `implements`
16
 */
17
final class TraitBecameInterface implements TraitBased
18
{
19
    public function compare(ReflectionClass $fromTrait, ReflectionClass $toTrait) : Changes
20
    {
21
        Assert::that($fromTrait->getName())->same($toTrait->getName());
22
23
        if ($toTrait->isTrait() || ! $toTrait->isInterface() || ! $fromTrait->isTrait()) {
24
            return Changes::new();
25
        }
26
27
        return Changes::fromArray([Change::changed(
28
            sprintf('Interface %s became an interface', $fromTrait->getName()),
29
            true
30
        ),
31
        ]);
32
    }
33
}
34