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

ClassBecameInterface::compare()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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