Completed
Pull Request — master (#38)
by Marco
03:08
created

InterfaceBecameClass   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A compare() 0 12 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Roave\ApiCompare\Comparator\BackwardsCompatibility\InterfaceBased;
6
7
use Assert\Assert;
8
use Roave\ApiCompare\Change;
9
use Roave\ApiCompare\Changes;
10
use Roave\BetterReflection\Reflection\ReflectionClass;
11
12
/**
13
 * An interface cannot become abstract 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
        Assert::that($fromClass->getName())->same($toClass->getName());
21
22
        if ($toClass->isInterface() || ! $fromClass->isInterface()) {
23
            // checking whether a class became an interface is done in `ClassBecameInterface`
24
            return Changes::new();
25
        }
26
27
        return Changes::fromArray([Change::changed(
28
            sprintf('Interface %s became a class', $fromClass->getName()),
29
            true
30
        )]);
31
    }
32
}
33