@@ -138,8 +138,8 @@ public function getFlatArrayIndexOfObject( $object ) {
138138 $ this ->assertIndexIsBuild ();
139139
140140 $ i = 0 ;
141- foreach ( $ this as $ o ) {
142- if ( $ o === $ object ) {
141+ foreach ( $ this as $ o ) {
142+ if ( $ o === $ object ) {
143143 return $ i ;
144144 }
145145 $ i ++;
@@ -159,7 +159,7 @@ public function toFlatArray() {
159159 $ this ->assertIndexIsBuild ();
160160
161161 $ array = array ();
162- foreach ( $ this ->byId as $ objects ) {
162+ foreach ( $ this ->byId as $ objects ) {
163163 $ array = array_merge ( $ array , $ objects );
164164 }
165165 return $ array ;
@@ -179,8 +179,8 @@ private function getFlatArrayIndices( PropertyId $propertyId ) {
179179 $ propertyIndices = array ();
180180 $ i = 0 ;
181181
182- foreach ( $ this ->byId as $ serializedPropertyId => $ objects ) {
183- if ( $ serializedPropertyId === $ propertyId ->getSerialization () ) {
182+ foreach ( $ this ->byId as $ serializedPropertyId => $ objects ) {
183+ if ( $ serializedPropertyId === $ propertyId ->getSerialization () ) {
184184 $ propertyIndices = range ( $ i , $ i + count ( $ objects ) - 1 );
185185 break ;
186186 } else {
@@ -202,7 +202,7 @@ private function getFlatArrayIndices( PropertyId $propertyId ) {
202202 private function moveObjectInPropertyGroup ( $ object , $ toIndex ) {
203203 $ currentIndex = $ this ->getFlatArrayIndexOfObject ( $ object );
204204
205- if ( $ toIndex === $ currentIndex ) {
205+ if ( $ toIndex === $ currentIndex ) {
206206 return ;
207207 }
208208
@@ -211,11 +211,11 @@ private function moveObjectInPropertyGroup( $object, $toIndex ) {
211211 $ numericIndices = $ this ->getFlatArrayIndices ( $ propertyId );
212212 $ lastIndex = $ numericIndices [count ( $ numericIndices ) - 1 ];
213213
214- if ( $ toIndex > $ lastIndex + 1 || $ toIndex < $ numericIndices [0 ] ) {
214+ if ( $ toIndex > $ lastIndex + 1 || $ toIndex < $ numericIndices [0 ] ) {
215215 throw new OutOfBoundsException ( 'Object cannot be moved to ' . $ toIndex );
216216 }
217217
218- if ( $ toIndex >= $ lastIndex ) {
218+ if ( $ toIndex >= $ lastIndex ) {
219219 $ this ->moveObjectToEndOfPropertyGroup ( $ object );
220220 } else {
221221 $ this ->removeObject ( $ object );
@@ -287,13 +287,10 @@ private function insertObjectAtIndex( $object, $index ) {
287287 * @param int $toIndex
288288 */
289289 private function movePropertyGroup ( PropertyId $ propertyId , $ toIndex ) {
290- if ( $ this ->getPropertyGroupIndex ( $ propertyId ) === $ toIndex ) {
290+ if ( $ this ->getPropertyGroupIndex ( $ propertyId ) === $ toIndex ) {
291291 return ;
292292 }
293293
294- /**
295- * @var PropertyId
296- */
297294 $ insertBefore = null ;
298295
299296 $ oldIndex = $ this ->getPropertyGroupIndex ( $ propertyId );
@@ -302,16 +299,16 @@ private function movePropertyGroup( PropertyId $propertyId, $toIndex ) {
302299 // Remove "property group" to calculate the groups new index:
303300 unset( $ this ->byId [$ propertyId ->getSerialization ()] );
304301
305- if ( $ toIndex > $ oldIndex ) {
302+ if ( $ toIndex > $ oldIndex ) {
306303 // If the group shall be moved towards the bottom, the number of objects within the
307304 // group needs to be subtracted from the absolute toIndex:
308305 $ toIndex -= count ( $ byIdClone [$ propertyId ->getSerialization ()] );
309306 }
310307
311- foreach ( $ this ->getPropertyIds () as $ pId ) {
308+ foreach ( $ this ->getPropertyIds () as $ pId ) {
312309 // Accepting other than the exact index by using <= letting the "property group" "latch"
313310 // in the next slot.
314- if ( $ toIndex <= $ this ->getPropertyGroupIndex ( $ pId ) ) {
311+ if ( $ toIndex <= $ this ->getPropertyGroupIndex ( $ pId ) ) {
315312 $ insertBefore = $ pId ;
316313 break ;
317314 }
@@ -320,17 +317,17 @@ private function movePropertyGroup( PropertyId $propertyId, $toIndex ) {
320317 $ serializedPropertyId = $ propertyId ->getSerialization ();
321318 $ this ->byId = array ();
322319
323- foreach ( $ byIdClone as $ serializedPId => $ objects ) {
320+ foreach ( $ byIdClone as $ serializedPId => $ objects ) {
324321 $ pId = new PropertyId ( $ serializedPId );
325- if ( $ pId ->equals ( $ propertyId ) ) {
322+ if ( $ pId ->equals ( $ propertyId ) ) {
326323 continue ;
327- } elseif ( $ pId ->equals ( $ insertBefore ) ) {
324+ } elseif ( $ pId ->equals ( $ insertBefore ) ) {
328325 $ this ->byId [$ serializedPropertyId ] = $ byIdClone [$ serializedPropertyId ];
329326 }
330327 $ this ->byId [$ serializedPId ] = $ objects ;
331328 }
332329
333- if ( is_null ( $ insertBefore ) ) {
330+ if ( $ insertBefore === null ) {
334331 $ this ->byId [$ serializedPropertyId ] = $ byIdClone [$ serializedPropertyId ];
335332 }
336333
@@ -348,9 +345,9 @@ private function movePropertyGroup( PropertyId $propertyId, $toIndex ) {
348345 private function getPropertyGroupIndex ( PropertyId $ propertyId ) {
349346 $ i = 0 ;
350347
351- foreach ( $ this ->byId as $ serializedPropertyId => $ objects ) {
348+ foreach ( $ this ->byId as $ serializedPropertyId => $ objects ) {
352349 $ pId = new PropertyId ( $ serializedPropertyId );
353- if ( $ pId ->equals ( $ propertyId ) ) {
350+ if ( $ pId ->equals ( $ propertyId ) ) {
354351 return $ i ;
355352 }
356353 $ i += count ( $ objects );
@@ -373,18 +370,18 @@ private function getPropertyGroupIndex( PropertyId $propertyId ) {
373370 public function moveObjectToIndex ( $ object , $ toIndex ) {
374371 $ this ->assertIndexIsBuild ();
375372
376- if ( !in_array ( $ object , $ this ->toFlatArray () ) ) {
373+ if ( !in_array ( $ object , $ this ->toFlatArray () ) ) {
377374 throw new OutOfBoundsException ( 'Object not present in array ' );
378- } elseif ( $ toIndex < 0 || $ toIndex > count ( $ this ) ) {
375+ } elseif ( $ toIndex < 0 || $ toIndex > count ( $ this ) ) {
379376 throw new OutOfBoundsException ( 'Specified index is out of bounds ' );
380- } elseif ( $ this ->getFlatArrayIndexOfObject ( $ object ) === $ toIndex ) {
377+ } elseif ( $ this ->getFlatArrayIndexOfObject ( $ object ) === $ toIndex ) {
381378 return ;
382379 }
383380
384381 // Determine whether to simply reindex the object within its "property group":
385382 $ propertyIndices = $ this ->getFlatArrayIndices ( $ object ->getPropertyId () );
386383
387- if ( in_array ( $ toIndex , $ propertyIndices ) ) {
384+ if ( in_array ( $ toIndex , $ propertyIndices ) ) {
388385 $ this ->moveObjectInPropertyGroup ( $ object , $ toIndex );
389386 } else {
390387 $ edgeIndex = ( $ toIndex <= $ propertyIndices [0 ] )
@@ -417,14 +414,14 @@ public function addObjectAtIndex( $object, $index = null ) {
417414 $ propertyId = $ object ->getPropertyId ();
418415 $ validIndices = $ this ->getFlatArrayIndices ( $ propertyId );
419416
420- if ( count ( $ this ) === 0 ) {
417+ if ( count ( $ this ) === 0 ) {
421418 // Array is empty, just append object.
422419 $ this ->append ( $ object );
423- } elseif ( empty ( $ validIndices ) ) {
420+ } elseif ( empty ( $ validIndices ) ) {
424421 // No objects featuring that property exist. The object may be inserted at a place
425422 // between existing "property groups".
426423 $ this ->append ( $ object );
427- if ( ! is_null ( $ index ) ) {
424+ if ( $ index !== null ) {
428425 $ this ->buildIndex ();
429426 $ this ->moveObjectToIndex ( $ object , $ index );
430427 }
@@ -450,19 +447,19 @@ private function addObjectToPropertyGroup( $object, $index = null ) {
450447 $ propertyId = $ object ->getPropertyId ();
451448 $ validIndices = $ this ->getFlatArrayIndices ( $ propertyId );
452449
453- if ( empty ( $ validIndices ) ) {
450+ if ( empty ( $ validIndices ) ) {
454451 throw new OutOfBoundsException ( 'No objects featuring the object \'s property exist ' );
455452 }
456453
457454 // Add index to allow placing object after the last object of the "property group":
458455 $ validIndices [] = $ validIndices [count ( $ validIndices ) - 1 ] + 1 ;
459456
460- if ( is_null ( $ index ) ) {
457+ if ( $ index === null ) {
461458 // If index is null, append object to "property group".
462459 $ index = $ validIndices [count ( $ validIndices ) - 1 ];
463460 }
464461
465- if ( in_array ( $ index , $ validIndices ) ) {
462+ if ( in_array ( $ index , $ validIndices ) ) {
466463 // Add object at index within "property group".
467464 $ this ->byId [$ propertyId ->getSerialization ()][] = $ object ;
468465 $ this ->exchangeArray ( $ this ->toFlatArray () );
@@ -474,7 +471,7 @@ private function addObjectToPropertyGroup( $object, $index = null ) {
474471
475472 // Move new object to the edge of the "property group" to receive its designated
476473 // index:
477- if ( $ index < $ validIndices [0 ] ) {
474+ if ( $ index < $ validIndices [0 ] ) {
478475 array_unshift ( $ this ->byId [$ propertyId ->getSerialization ()], $ object );
479476 } else {
480477 $ this ->byId [$ propertyId ->getSerialization ()][] = $ object ;
0 commit comments