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

PropertyBecameInternal   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 30
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 15 3
A __construct() 0 3 1
A isInternalDocComment() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Roave\BackwardCompatibility\DetectChanges\BCBreak\PropertyBased;
6
7
use Roave\BackwardCompatibility\Change;
8
use Roave\BackwardCompatibility\Changes;
9
use Roave\BackwardCompatibility\Formatter\ReflectionPropertyName;
10
use Roave\BetterReflection\Reflection\ReflectionProperty;
11
use function Safe\preg_match;
12
use function Safe\sprintf;
13
14
/**
15
 * A property that is marked internal is no available to downstream consumers.
16
 */
17
final class PropertyBecameInternal implements PropertyBased
18
{
19
    /** @var ReflectionPropertyName */
20
    private $formatProperty;
21
22
    public function __construct()
23
    {
24
        $this->formatProperty = new ReflectionPropertyName();
25
    }
26
27
    public function __invoke(ReflectionProperty $fromProperty, ReflectionProperty $toProperty) : Changes
28
    {
29
        if ($this->isInternalDocComment($toProperty->getDocComment())
30
            && ! $this->isInternalDocComment($fromProperty->getDocComment())
31
        ) {
32
            return Changes::fromList(Change::changed(
33
                sprintf(
34
                    'Property %s was marked "@internal"',
35
                    $this->formatProperty->__invoke($fromProperty),
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