Passed
Pull Request — master (#50)
by Marco
02:36
created

TraitBecameClass::isClass()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Roave\BackwardCompatibility\DetectChanges\BCBreak\TraitBased;
6
7
use Roave\BackwardCompatibility\Change;
8
use Roave\BackwardCompatibility\Changes;
9
use Roave\BetterReflection\Reflection\ReflectionClass;
10
use function sprintf;
11
12
/**
13
 * A trait cannot change to become a class, as that forces all implementations
14
 * that use it to change from `use` to inheritance (if even possible)
15
 */
16
final class TraitBecameClass implements TraitBased
17
{
18
    public function __invoke(ReflectionClass $fromTrait, ReflectionClass $toTrait) : Changes
19
    {
20
        if ($this->isClass($fromTrait) || ! $this->isClass($toTrait)) {
21
            return Changes::empty();
22
        }
23
24
        return Changes::fromList(Change::changed(
25
            sprintf('Trait %s became a class', $fromTrait->getName()),
26
            true
27
        ));
28
    }
29
30
    /**
31
     * According to the current state of the PHP ecosystem, we only have traits, interfaces and classes
32
     */
33
    private function isClass(ReflectionClass $class) : bool
34
    {
35
        return ! ($class->isTrait() || $class->isInterface());
36
    }
37
}
38