1 | <?php |
||
13 | class Index implements \Countable, \IteratorAggregate |
||
14 | { |
||
15 | /** |
||
16 | * @var IndexNode |
||
17 | */ |
||
18 | protected $rootNode; |
||
19 | |||
20 | public function __construct() |
||
24 | |||
25 | /** |
||
26 | * Adds the given object to the index. |
||
27 | * |
||
28 | * @param IndexObject $indexObject |
||
29 | * @return Index |
||
30 | * @throws Exception |
||
31 | */ |
||
32 | public function addObject(IndexObject $indexObject): Index |
||
55 | |||
56 | /** |
||
57 | * Returns an index object by a given relative path. |
||
58 | * |
||
59 | * @param string $path |
||
60 | * @return IndexObject|null |
||
61 | */ |
||
62 | public function getObjectByPath(string $path): ?IndexObject |
||
68 | |||
69 | /** |
||
70 | * Returns an index object by a given blob id. |
||
71 | * |
||
72 | * @param string $blobId |
||
73 | * @return IndexObject|null |
||
74 | */ |
||
75 | public function getObjectByBlobId(string $blobId): ?IndexObject |
||
89 | |||
90 | /** |
||
91 | * Compares this index to the given index and returns the comparison result as boolean indicator. |
||
92 | * |
||
93 | * @param Index|null $other |
||
94 | * @return bool |
||
95 | */ |
||
96 | public function equals(Index $other = null): bool |
||
105 | |||
106 | /** |
||
107 | * Returns true if this index is a subset of the given index. |
||
108 | * |
||
109 | * @param Index $other |
||
110 | * @return bool |
||
111 | */ |
||
112 | public function isSubsetOf(Index $other): bool |
||
126 | |||
127 | /** |
||
128 | * Returns the difference between this and the given index. |
||
129 | * The resulting difference contains objects from this index that are not present in or different to the |
||
130 | * corresponding object in the given index and objects from the given index that do not have a correspondence in |
||
131 | * this index. |
||
132 | * |
||
133 | * @param Index $other |
||
134 | * @return IndexDifference |
||
135 | */ |
||
136 | public function getDifference(Index $other): IndexDifference |
||
145 | |||
146 | /** |
||
147 | * Merges the given index into this index instance. |
||
148 | * Eventually existing objects with the same path are overridden. |
||
149 | * The contents of directories under the same path are merged together. |
||
150 | * |
||
151 | * @param Index $other |
||
152 | * @return Index |
||
153 | */ |
||
154 | public function merge(Index $other): Index |
||
179 | |||
180 | /** |
||
181 | * {@inheritdoc} |
||
182 | */ |
||
183 | public function count(): int |
||
187 | |||
188 | /** |
||
189 | * {@inheritdoc} |
||
190 | */ |
||
191 | public function getIterator(): \Traversable |
||
195 | |||
196 | /** |
||
197 | * Returns all those objects in this index that are not existent or are different in the given index. |
||
198 | * |
||
199 | * @param Index $other |
||
200 | * @param IndexDifference $indexDifference |
||
201 | * @return IndexDifference |
||
202 | */ |
||
203 | protected function addDiffTo(Index $other, IndexDifference $indexDifference): IndexDifference |
||
219 | } |
||
220 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: