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

ClassBecameInterface::compare()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
eloc 6
nc 2
nop 2
cc 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Roave\ApiCompare\Comparator\BackwardsCompatibility\ClassBased;
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 class cannot become an interface without introducing an explicit BC break, since
15
 * all child classes or implementors need to be changed from `extends` to `implements`,
16
 * and all instantiations start failing
17
 */
18
final class ClassBecameInterface implements ClassBased
19
{
20
    public function compare(ReflectionClass $fromClass, ReflectionClass $toClass) : Changes
21
    {
22
        Assert::that($fromClass->getName())->same($toClass->getName());
23
24
        if ($fromClass->isInterface() || ! $toClass->isInterface()) {
25
            // checking whether a class became an interface is done in `InterfaceBecameClass`
26
            return Changes::new();
27
        }
28
29
        return Changes::fromArray([Change::changed(
30
            sprintf('Class %s became an interface', $fromClass->getName()),
31
            true
32
        ),
33
        ]);
34
    }
35
}
36