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

ClassBecameInternal::isInternalDocComment()   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\ClassBased;
6
7
use Roave\BackwardCompatibility\Change;
8
use Roave\BackwardCompatibility\Changes;
9
use Roave\BetterReflection\Reflection\ReflectionClass;
10
use function Safe\preg_match;
11
use function Safe\sprintf;
12
13
/**
14
 * A class that is marked internal is no available to downstream consumers.
15
 */
16
final class ClassBecameInternal implements ClassBased
17
{
18
    public function __invoke(ReflectionClass $fromClass, ReflectionClass $toClass) : Changes
19
    {
20
        if (! $this->isInternalDocComment($fromClass->getDocComment())
21
            && $this->isInternalDocComment($toClass->getDocComment())
22
        ) {
23
            return Changes::fromList(Change::changed(
24
                sprintf(
25
                    '%s was marked "@internal"',
26
                    $fromClass->getName()
27
                ),
28
                true
29
            ));
30
        }
31
32
        return Changes::empty();
33
    }
34
35
    private function isInternalDocComment(string $comment) : bool
36
    {
37
        return preg_match('/\s+@internal\s+/', $comment) === 1;
38
    }
39
}
40