Passed
Pull Request — master (#109)
by Marco
05:58 queued 03:28
created

AncestorRemoved   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 19
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 17 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Roave\BackwardCompatibility\DetectChanges\BCBreak\InterfaceBased;
6
7
use Roave\BackwardCompatibility\Change;
8
use Roave\BackwardCompatibility\Changes;
9
use Roave\BetterReflection\Reflection\ReflectionClass;
10
use function array_diff;
11
use function array_merge;
12
use function json_encode;
13
use function sprintf;
14
15
/**
16
 * An interface ancestor cannot be removed, as that breaks type checking in consumers.
17
 */
18
final class AncestorRemoved implements InterfaceBased
19
{
20
    public function __invoke(ReflectionClass $fromClass, ReflectionClass $toClass) : Changes
21
    {
22
        $removedAncestors = array_merge(
23
            array_diff($fromClass->getInterfaceNames(), $toClass->getInterfaceNames())
24
        );
25
26
        if (! $removedAncestors) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $removedAncestors of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
27
            return Changes::empty();
28
        }
29
30
        return Changes::fromList(Change::removed(
31
            sprintf(
32
                'These ancestors of %s have been removed: %s',
33
                $fromClass->getName(),
34
                json_encode($removedAncestors)
35
            ),
36
            true
37
        ));
38
    }
39
}
40