| Conditions | 6 |
| Paths | 10 |
| Total Lines | 23 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 14 |
| CRAP Score | 6 |
| Changes | 0 | ||
| 1 | <?php |
||
| 36 | 16 | public function patch( array $base, Diff $diff ) { |
|
| 37 | 16 | if ( $diff->looksAssociative() ) { |
|
| 38 | 1 | $this->handleError( 'ListPatcher can only patch using non-associative diffs' ); |
|
| 39 | } |
||
| 40 | |||
| 41 | 16 | foreach ( $diff as $diffOp ) { |
|
| 42 | 11 | if ( $diffOp instanceof DiffOpAdd ) { |
|
| 43 | 8 | $base[] = $diffOp->getNewValue(); |
|
| 44 | 7 | } elseif ( $diffOp instanceof DiffOpRemove ) { |
|
| 45 | 7 | $needle = $diffOp->getOldValue(); |
|
| 46 | 7 | $key = array_search( $needle, $base, !is_object( $needle ) ); |
|
| 47 | |||
| 48 | 7 | if ( $key === false ) { |
|
| 49 | 2 | $this->handleError( 'Cannot remove an element from a list if it is not present' ); |
|
| 50 | 2 | continue; |
|
| 51 | } |
||
| 52 | |||
| 53 | 10 | unset( $base[$key] ); |
|
| 54 | } |
||
| 55 | } |
||
| 56 | |||
| 57 | 16 | return $base; |
|
| 58 | } |
||
| 59 | |||
| 61 |