Passed
Pull Request — master (#38)
by Marco
02:55
created

MethodBecameFinal::compare()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
eloc 8
nc 2
nop 2
cc 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Roave\ApiCompare\Comparator\BackwardsCompatibility\MethodBased;
6
7
use Roave\ApiCompare\Change;
8
use Roave\ApiCompare\Changes;
9
use Roave\BetterReflection\Reflection\ReflectionMethod;
10
use function sprintf;
11
12
/**
13
 * A method that changes from non-final to final breaks all child classes that
14
 * override it.
15
 */
16
final class MethodBecameFinal implements MethodBased
17
{
18
    public function compare(ReflectionMethod $fromMethod, ReflectionMethod $toMethod) : Changes
19
    {
20
        if ($fromMethod->isFinal() || ! $toMethod->isFinal()) {
21
            return Changes::new();
22
        }
23
24
        return Changes::fromArray([Change::changed(
25
            sprintf(
26
                'Method %s() of class %s became final',
27
                $fromMethod->getName(),
28
                $fromMethod->getDeclaringClass()->getName()
29
            ),
30
            true
31
        )]);
32
    }
33
}
34