ClassBecameTrait::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 2
nop 2
dl 0
loc 9
rs 10
c 0
b 0
f 0
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 a trait without introducing an explicit BC break, since
14
 * all child classes or implementors need to be changed from `extends` to `use`,
15
 * and all instantiations start failing
16
 */
17
final class ClassBecameTrait implements ClassBased
18
{
19
    public function __invoke(ReflectionClass $fromClass, ReflectionClass $toClass) : Changes
20
    {
21
        if ($fromClass->isTrait() || ! $toClass->isTrait()) {
22
            return Changes::empty();
23
        }
24
25
        return Changes::fromList(Change::changed(
26
            sprintf('Class %s became a trait', $fromClass->getName()),
27
            true
28
        ));
29
    }
30
}
31