@@ -117,7 +117,7 @@ public function hasReference( Reference $reference ) {
117117 }
118118
119119 /**
120- * Returns the index of a reference or false if the reference could not be found.
120+ * Returns the index of the Reference object or false if the Reference could not be found.
121121 *
122122 * @since 0.5
123123 *
@@ -160,29 +160,31 @@ public function hasReferenceHash( $referenceHash ) {
160160 }
161161
162162 /**
163- * Removes the reference with the provided hash if it exists in the list.
163+ * Looks for the first Reference object in this list with the provided hash.
164+ * Removes all occurences of that object.
164165 *
165166 * @since 0.3
166167 *
167168 * @param string $referenceHash `
168169 */
169170 public function removeReferenceHash ( $ referenceHash ) {
170- foreach ( $ this ->references as $ index => $ reference ) {
171- if ( $ reference ->getHash () === $ referenceHash ) {
172- $ this ->removeReferenceAtIndex ( $ index );
171+ $ reference = $ this ->getReference ( $ referenceHash );
172+
173+ if ( $ reference === null ) {
174+ return ;
175+ }
176+
177+ foreach ( $ this ->references as $ index => $ ref ) {
178+ if ( $ ref === $ reference ) {
179+ unset( $ this ->references [$ index ] );
173180 }
174181 }
175- }
176182
177- /**
178- * @param int $index
179- */
180- private function removeReferenceAtIndex ( $ index ) {
181- array_splice ( $ this ->references , $ index , 1 );
183+ $ this ->references = array_values ( $ this ->references );
182184 }
183185
184186 /**
185- * Returns the reference with the provided hash, or
187+ * Returns the first Reference object with the provided hash, or
186188 * null if there is no such reference in the list.
187189 *
188190 * @since 0.3
0 commit comments