1 | <?php |
||
32 | final class NamespacesAwareComparator extends AbstractComparator |
||
33 | { |
||
34 | /** @var array */ |
||
35 | private $namespaces; |
||
36 | |||
37 | /** @var ComparatorInterface */ |
||
38 | private $fallbackComparator; |
||
39 | |||
40 | /** |
||
41 | * NamespacesAwareComparator constructor. |
||
42 | * |
||
43 | * @param ComparatorInterface $fallbackComparator |
||
44 | * @param array $namespaces Namespaces with keys ordered by priority (highest priority first) |
||
45 | * |
||
46 | * @throws ComparatorException |
||
47 | */ |
||
48 | 14 | public function __construct(ComparatorInterface $fallbackComparator, array $namespaces) |
|
53 | |||
54 | /** |
||
55 | * @param array $namespaces |
||
56 | * @throws ComparatorException |
||
57 | */ |
||
58 | 14 | private function setNamespaces($namespaces) |
|
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | * |
||
74 | * Given the following $namespaces passed in the constructor: |
||
75 | * - Taz (lowest priority) |
||
76 | * - Bar |
||
77 | * - Foo (highest priority) |
||
78 | * |
||
79 | * Will produce the following results based on the migration's FQCN: |
||
80 | * - (Foo\v200012, Bar\v201612) => -1 |
||
81 | * - (Taz\v201612, Foo\v200012) => 1 |
||
82 | * - (FooBar\v201612, Taz\v200012) => 1 |
||
83 | * - (Taz\v201612, Taz\v201601) => delegate to fallback |
||
84 | * - (FooBar\v201612, FooBar\v200012) => delegate to fallback |
||
85 | * |
||
86 | * @param DeltaInterface $version1 |
||
87 | * @param DeltaInterface $version2 |
||
88 | * |
||
89 | * @return int |
||
90 | * |
||
91 | * @throws InvalidArgumentException |
||
92 | */ |
||
93 | 12 | public function compare(DeltaInterface $version1, DeltaInterface $version2) |
|
112 | |||
113 | /** |
||
114 | * Compare using namespaces |
||
115 | * |
||
116 | * @param $class1 |
||
117 | * @param $class2 |
||
118 | * @return int|null |
||
119 | */ |
||
120 | 10 | private function compareNamespaces($class1, $class2) |
|
138 | } |
||
139 |