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

ExcludeInternalInterface::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 7
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Roave\BackwardCompatibility\DetectChanges\BCBreak\InterfaceBased;
6
7
use Roave\BackwardCompatibility\Changes;
8
use Roave\BetterReflection\Reflection\ReflectionClass;
9
use function Safe\preg_match;
10
11
/**
12
 * Interfaces marked "internal" (docblock) are not affected by BC checks.
13
 */
14
final class ExcludeInternalInterface implements InterfaceBased
15
{
16
    /** @var InterfaceBased */
17
    private $check;
18
19
    public function __construct(InterfaceBased $check)
20
    {
21
        $this->check = $check;
22
    }
23
24
    public function __invoke(ReflectionClass $fromInterface, ReflectionClass $toInterface) : Changes
25
    {
26
        if ($this->isInternalDocComment($fromInterface->getDocComment())) {
27
            return Changes::empty();
28
        }
29
30
        return $this->check->__invoke($fromInterface, $toInterface);
31
    }
32
33
    private function isInternalDocComment(string $comment) : bool
34
    {
35
        return preg_match('/\s+@internal\s+/', $comment) === 1;
36
    }
37
}
38