|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassConstantBased; |
|
6
|
|
|
|
|
7
|
|
|
use Roave\BackwardCompatibility\Change; |
|
8
|
|
|
use Roave\BackwardCompatibility\Changes; |
|
9
|
|
|
use Roave\BetterReflection\Reflection\ReflectionClassConstant; |
|
10
|
|
|
use function Safe\sprintf; |
|
11
|
|
|
|
|
12
|
|
|
final class ClassConstantVisibilityReduced implements ClassConstantBased |
|
13
|
|
|
{ |
|
14
|
|
|
private const VISIBILITY_PRIVATE = 'private'; |
|
15
|
|
|
|
|
16
|
|
|
private const VISIBILITY_PROTECTED = 'protected'; |
|
17
|
|
|
|
|
18
|
|
|
private const VISIBILITY_PUBLIC = 'public'; |
|
19
|
|
|
|
|
20
|
|
|
public function __invoke(ReflectionClassConstant $fromConstant, ReflectionClassConstant $toConstant) : Changes |
|
21
|
|
|
{ |
|
22
|
|
|
$visibilityFrom = $this->propertyVisibility($fromConstant); |
|
23
|
|
|
$visibilityTo = $this->propertyVisibility($toConstant); |
|
24
|
|
|
|
|
25
|
|
|
// Works because private, protected and public are sortable: |
|
26
|
|
|
if ($visibilityFrom <= $visibilityTo) { |
|
27
|
|
|
return Changes::empty(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
return Changes::fromList(Change::changed( |
|
31
|
|
|
sprintf( |
|
32
|
|
|
'Constant %s::%s visibility reduced from %s to %s', |
|
33
|
|
|
$fromConstant->getDeclaringClass()->getName(), |
|
34
|
|
|
$fromConstant->getName(), |
|
35
|
|
|
$visibilityFrom, |
|
36
|
|
|
$visibilityTo |
|
37
|
|
|
), |
|
38
|
|
|
true |
|
39
|
|
|
)); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
private function propertyVisibility(ReflectionClassConstant $property) : string |
|
43
|
|
|
{ |
|
44
|
|
|
if ($property->isPublic()) { |
|
45
|
|
|
return self::VISIBILITY_PUBLIC; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
if ($property->isProtected()) { |
|
49
|
|
|
return self::VISIBILITY_PROTECTED; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
return self::VISIBILITY_PRIVATE; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|