Completed
Push — master ( 901cc6...ad6830 )
by James
15s queued 11s
created

InterfaceBecameClass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 22
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isClass() 0 3 2
A compare() 0 10 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Roave\ApiCompare\Comparator\BackwardsCompatibility\InterfaceBased;
6
7
use Roave\ApiCompare\Change;
8
use Roave\ApiCompare\Changes;
9
use Roave\BetterReflection\Reflection\ReflectionClass;
10
use function sprintf;
11
12
/**
13
 * An interface cannot become concrete 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 InterfaceBecameClass implements InterfaceBased
17
{
18
    public function compare(ReflectionClass $fromClass, ReflectionClass $toClass) : Changes
19
    {
20
        if (! $this->isClass($toClass) || ! $fromClass->isInterface()) {
21
            // checking whether a class became an interface is done in `ClassBecameInterface`
22
            return Changes::new();
23
        }
24
25
        return Changes::fromArray([Change::changed(
26
            sprintf('Interface %s became a class', $fromClass->getName()),
27
            true
28
        ),
29
        ]);
30
    }
31
32
    /**
33
     * According to the current state of the PHP ecosystem, we only have traits, interfaces and classes
34
     */
35
    private function isClass(ReflectionClass $class) : bool
36
    {
37
        return ! ($class->isTrait() || $class->isInterface());
38
    }
39
}
40