ClassBecameAbstract   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 16
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 14 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassBased;
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
 * 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 __invoke(ReflectionClass $fromClass, ReflectionClass $toClass) : Changes
20
    {
21
        if ($fromClass->isInterface() !== $toClass->isInterface()) {
22
            // checking whether a class became an interface is done in `ClassBecameInterface`
23
            return Changes::empty();
24
        }
25
26
        if ($fromClass->isAbstract() || ! $toClass->isAbstract()) {
27
            return Changes::empty();
28
        }
29
30
        return Changes::fromList(Change::changed(
31
            sprintf('Class %s became abstract', $fromClass->getName()),
32
            true
33
        ));
34
    }
35
}
36