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\BackwardCompatibility\DetectChanges\BCBreak\MethodBased\MethodBased; |
10
|
|
|
use Roave\BetterReflection\Reflection\ReflectionClass; |
11
|
|
|
use Roave\BetterReflection\Reflection\ReflectionMethod; |
12
|
|
|
use function array_intersect_key; |
13
|
|
|
use function array_keys; |
14
|
|
|
use function array_map; |
15
|
|
|
use function Safe\array_combine; |
16
|
|
|
use function strtolower; |
17
|
|
|
|
18
|
|
|
final class MethodChanged implements ClassBased |
19
|
|
|
{ |
20
|
|
|
/** @var MethodBased */ |
21
|
|
|
private $checkMethod; |
22
|
|
|
|
23
|
|
|
public function __construct(MethodBased $checkMethod) |
24
|
|
|
{ |
25
|
|
|
$this->checkMethod = $checkMethod; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function __invoke(ReflectionClass $fromClass, ReflectionClass $toClass) : Changes |
29
|
|
|
{ |
30
|
|
|
return Changes::fromIterator($this->checkSymbols($this->methods($fromClass), $this->methods($toClass))); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param ReflectionMethod[] $from |
35
|
|
|
* @param ReflectionMethod[] $to |
36
|
|
|
* |
37
|
|
|
* @return iterable|Change[] |
38
|
|
|
*/ |
39
|
|
|
private function checkSymbols(array $from, array $to) : iterable |
40
|
|
|
{ |
41
|
|
|
foreach (array_keys(array_intersect_key($from, $to)) as $name) { |
42
|
|
|
yield from $this->checkMethod->__invoke($from[$name], $to[$name]); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** @return ReflectionMethod[] indexed by lower case method name */ |
47
|
|
|
private function methods(ReflectionClass $class) : array |
48
|
|
|
{ |
49
|
|
|
$methods = $class->getMethods(); |
50
|
|
|
|
51
|
|
|
return array_combine( |
52
|
|
|
array_map(static function (ReflectionMethod $method) : string { |
53
|
|
|
return strtolower($method->getName()); |
54
|
|
|
}, $methods), |
55
|
|
|
$methods |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|