InterfaceBecameClass::isClass()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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 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 __invoke(ReflectionClass $fromInterface, ReflectionClass $toInterface) : Changes
19
    {
20
        if (! $this->isClass($toInterface) || ! $fromInterface->isInterface()) {
21
            // checking whether a class became an interface is done in `ClassBecameInterface`
22
            return Changes::empty();
23
        }
24
25
        return Changes::fromList(Change::changed(
26
            sprintf('Interface %s became a class', $fromInterface->getName()),
27
            true
28
        ));
29
    }
30
31
    /**
32
     * According to the current state of the PHP ecosystem, we only have traits, interfaces and classes
33
     */
34
    private function isClass(ReflectionClass $class) : bool
35
    {
36
        return ! ($class->isTrait() || $class->isInterface());
37
    }
38
}
39