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

MethodBecameFinal   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 15
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A compare() 0 13 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