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

FunctionBecameInternal::__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 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Roave\BackwardCompatibility\DetectChanges\BCBreak\FunctionBased;
6
7
use Roave\BackwardCompatibility\Change;
8
use Roave\BackwardCompatibility\Changes;
9
use Roave\BackwardCompatibility\Formatter\ReflectionFunctionAbstractName;
10
use Roave\BetterReflection\Reflection\ReflectionFunctionAbstract;
11
use function Safe\preg_match;
12
use function Safe\sprintf;
13
14
/**
15
 * A function that is marked internal is no available to downstream consumers.
16
 */
17
final class FunctionBecameInternal implements FunctionBased
18
{
19
    /** @var ReflectionFunctionAbstractName */
20
    private $formatFunction;
21
22
    public function __construct()
23
    {
24
        $this->formatFunction = new ReflectionFunctionAbstractName();
25
    }
26
27
    public function __invoke(ReflectionFunctionAbstract $fromFunction, ReflectionFunctionAbstract $toFunction) : Changes
28
    {
29
        if ($this->isInternalDocComment($toFunction->getDocComment())
30
            && ! $this->isInternalDocComment($fromFunction->getDocComment())
31
        ) {
32
            return Changes::fromList(Change::changed(
33
                sprintf(
34
                    '%s was marked "@internal"',
35
                    $this->formatFunction->__invoke($fromFunction),
36
                ),
37
                true
38
            ));
39
        }
40
41
        return Changes::empty();
42
    }
43
44
    private function isInternalDocComment(string $comment) : bool
45
    {
46
        return preg_match('/\s+@internal\s+/', $comment) === 1;
47
    }
48
}
49