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

ExcludeInternalMethod::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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