1 | <?php |
||
30 | class PathMappingCollection |
||
31 | { |
||
32 | /** |
||
33 | * @var TwoDimensionalHashMap |
||
34 | */ |
||
35 | private $map; |
||
36 | |||
37 | /** |
||
38 | * @var bool |
||
39 | */ |
||
40 | private $primaryKeysSorted = false; |
||
41 | |||
42 | /** |
||
43 | * Creates the store. |
||
44 | */ |
||
45 | 63 | public function __construct() |
|
49 | |||
50 | /** |
||
51 | * Adds a path mapping. |
||
52 | * |
||
53 | * @param PathMapping $mapping The path mapping. |
||
54 | */ |
||
55 | 57 | public function add(PathMapping $mapping) |
|
56 | { |
||
57 | 57 | $this->map->set($mapping->getRepositoryPath(), $mapping->getContainingPackage()->getName(), $mapping); |
|
58 | 57 | $this->primaryKeysSorted = false; |
|
59 | 57 | } |
|
60 | |||
61 | /** |
||
62 | * Sets a path mapping for a specific repository path. |
||
63 | * |
||
64 | * @param string $repositoryPath The repository path. |
||
65 | * @param PathMapping $mapping The path mapping. |
||
66 | */ |
||
67 | 54 | public function set($repositoryPath, PathMapping $mapping) |
|
68 | { |
||
69 | 54 | $this->map->set($repositoryPath, $mapping->getContainingPackage()->getName(), $mapping); |
|
70 | 54 | $this->primaryKeysSorted = false; |
|
71 | 54 | } |
|
72 | |||
73 | /** |
||
74 | * Removes a path mapping. |
||
75 | * |
||
76 | * This method ignores non-existing path mappings. |
||
77 | * |
||
78 | * @param string $repositoryPath The repository path of the mapping. |
||
79 | * @param string $packageName The package containing the mapping. |
||
80 | */ |
||
81 | 15 | public function remove($repositoryPath, $packageName) |
|
85 | |||
86 | /** |
||
87 | * Returns a path mapping. |
||
88 | * |
||
89 | * @param string $repositoryPath The repository path of the mapping. |
||
90 | * @param string $packageName The package containing the mapping. |
||
91 | * |
||
92 | * @return PathMapping The path mapping. |
||
93 | * |
||
94 | * @throws OutOfBoundsException If no path mapping was set for the |
||
95 | * given repository path/package. |
||
96 | */ |
||
97 | 27 | public function get($repositoryPath, $packageName) |
|
101 | |||
102 | /** |
||
103 | * Returns whether a path mapping was set for the given repository |
||
104 | * path/package. |
||
105 | * |
||
106 | * @param string $repositoryPath The repository path of the mapping. |
||
107 | * @param string|null $packageName The package containing the mapping. |
||
108 | * |
||
109 | * @return bool Returns `true` if a path mapping was set for the given |
||
110 | * repository path/package. |
||
111 | */ |
||
112 | 19 | public function contains($repositoryPath, $packageName = null) |
|
116 | |||
117 | /** |
||
118 | * Returns all path mappings set for the given repository path. |
||
119 | * |
||
120 | * @param string $repositoryPath The repository path of the mapping. |
||
121 | * |
||
122 | * @return PathMapping[] The path mappings. |
||
123 | * |
||
124 | * @throws OutOfBoundsException If no path mapping was set for the |
||
125 | * given repository path. |
||
126 | */ |
||
127 | public function listByRepositoryPath($repositoryPath) |
||
131 | |||
132 | /** |
||
133 | * Returns all path mappings set for the given package name. |
||
134 | * |
||
135 | * @param string $packageName The package name. |
||
136 | * |
||
137 | * @return PathMapping[] The path mappings. |
||
138 | * |
||
139 | * @throws OutOfBoundsException If no path mapping was set for the |
||
140 | * given package name. |
||
141 | */ |
||
142 | 13 | public function listByPackageName($packageName) |
|
143 | { |
||
144 | 13 | if ($this->primaryKeysSorted) { |
|
145 | $this->lazySortPrimaryKeys(); |
||
146 | } |
||
147 | |||
148 | 13 | return $this->map->listBySecondaryKey($packageName); |
|
149 | } |
||
150 | |||
151 | /** |
||
152 | * Returns the names of the packages defining mappings with the given |
||
153 | * repository path. |
||
154 | * |
||
155 | * @param string|null $repositoryPath The repository path of the mapping. |
||
156 | * |
||
157 | * @return string[] The package names. |
||
|
|||
158 | * |
||
159 | * @throws OutOfBoundsException If no path mapping was set for the |
||
160 | * given repository path. |
||
161 | */ |
||
162 | 14 | public function getPackageNames($repositoryPath = null) |
|
166 | |||
167 | /** |
||
168 | * Returns the repository paths of all path mappings. |
||
169 | * |
||
170 | * @return string[] The repository paths of the stored mappings. |
||
171 | */ |
||
172 | 63 | public function getRepositoryPaths() |
|
180 | |||
181 | /** |
||
182 | * Returns the contents of the collection as array. |
||
183 | * |
||
184 | * @return PathMapping[][] An array containing all path mappings indexed |
||
185 | * first by repository, then by package name. |
||
186 | */ |
||
187 | 33 | public function toArray() |
|
195 | |||
196 | /** |
||
197 | * Returns whether the collection is empty. |
||
198 | * |
||
199 | * @return bool Returns `true` if the collection is empty and `false` |
||
200 | * otherwise. |
||
201 | */ |
||
202 | 2 | public function isEmpty() |
|
206 | |||
207 | /** |
||
208 | * Sorts the map primary keys, if necessary. |
||
209 | */ |
||
210 | private function lazySortPrimaryKeys() |
||
215 | } |
||
216 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.