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

ClassBecameAbstract::compare()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.2
c 0
b 0
f 0
eloc 8
nc 3
nop 2
cc 4
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
12
/**
13
 * A class cannot become abstract without introducing an explicit BC break, since
14
 * all child classes or implementors need to be changed to implement its abstract API,
15
 * and all instantiations start to fail.
16
 */
17
final class ClassBecameAbstract implements ClassBased
18
{
19
    public function compare(ReflectionClass $fromClass, ReflectionClass $toClass) : Changes
20
    {
21
        Assert::that($fromClass->getName())->same($toClass->getName());
22
23
        if ($fromClass->isInterface() !== $toClass->isInterface()) {
24
            // checking whether a class became an interface is done in `ClassBecameInterface`
25
            return Changes::new();
26
        }
27
28
        if ($fromClass->isAbstract() || ! $toClass->isAbstract()) {
29
            return Changes::new();
30
        }
31
32
        return Changes::fromArray([Change::changed(
33
            sprintf('Class %s became abstract', $fromClass->getName()),
34
            true
35
        )]);
36
    }
37
}
38