Completed
Push — master ( 85853a...5df06c )
by James
20s queued 12s
created

ExcludeInternalMethod   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 22
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 7 2
A __construct() 0 3 1
A isInternalDocComment() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Roave\BackwardCompatibility\DetectChanges\BCBreak\MethodBased;
6
7
use Roave\BackwardCompatibility\Changes;
8
use Roave\BetterReflection\Reflection\ReflectionMethod;
9
use function Safe\preg_match;
10
11
/**
12
 * Methods marked "internal" (docblock) are not affected by BC checks.
13
 */
14
final class ExcludeInternalMethod implements MethodBased
15
{
16
    /** @var MethodBased */
17
    private $check;
18
19
    public function __construct(MethodBased $check)
20
    {
21
        $this->check = $check;
22
    }
23
24
    public function __invoke(ReflectionMethod $fromMethod, ReflectionMethod $toMethod) : Changes
25
    {
26
        if ($this->isInternalDocComment($fromMethod->getDocComment())) {
27
            return Changes::empty();
28
        }
29
30
        return $this->check->__invoke($fromMethod, $toMethod);
31
    }
32
33
    private function isInternalDocComment(string $comment) : bool
34
    {
35
        return preg_match('/\s+@internal\s+/', $comment) === 1;
36
    }
37
}
38