InterfaceBecameTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 12
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 10 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Roave\BackwardCompatibility\DetectChanges\BCBreak\InterfaceBased;
6
7
use Roave\BackwardCompatibility\Change;
8
use Roave\BackwardCompatibility\Changes;
9
use Roave\BetterReflection\Reflection\ReflectionClass;
10
use function Safe\sprintf;
11
12
/**
13
 * An interface cannot become a trait without introducing an explicit BC break, since
14
 * all implementors need to be changed to implement it instead of extending it.
15
 */
16
final class InterfaceBecameTrait implements InterfaceBased
17
{
18
    public function __invoke(ReflectionClass $fromInterface, ReflectionClass $toInterface) : Changes
19
    {
20
        if (! $toInterface->isTrait() || ! $fromInterface->isInterface()) {
21
            // checking whether an interface became an class is done in `InterfaceBecameClass`
22
            return Changes::empty();
23
        }
24
25
        return Changes::fromList(Change::changed(
26
            sprintf('Interface %s became a trait', $fromInterface->getName()),
27
            true
28
        ));
29
    }
30
}
31