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

ExcludeInternalInterface   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 __construct() 0 3 1
A __invoke() 0 7 2
A isInternalDocComment() 0 3 1
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