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

ClassBecameInternal   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isInternalDocComment() 0 3 1
A __invoke() 0 15 3
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