| Conditions | 7 |
| Paths | 6 |
| Total Lines | 32 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 29 | public function __invoke(Iterator $source, Iterator $target, callable $add, callable $remove) |
||
| 30 | { |
||
| 31 | $s = $source->current(); |
||
| 32 | $t = $target->current(); |
||
| 33 | |||
| 34 | while (!is_null($s) or !is_null($t)) { |
||
| 35 | if (is_null($t)) { |
||
| 36 | // Reached at the end of target. Add all reminding source elements. |
||
| 37 | $add($s); |
||
| 38 | $source->next(); |
||
| 39 | $s = $source->current(); |
||
| 40 | } else if (is_null($s)) { |
||
| 41 | // Reached at the end of source. Remove all remaining target elements. |
||
| 42 | $remove($t); |
||
| 43 | $target->next(); |
||
| 44 | $t = $target->current(); |
||
| 45 | } else { |
||
| 46 | $sv = strval($s); |
||
| 47 | $tv = strval($t); |
||
| 48 | if ($sv === $tv) { |
||
| 49 | $source->next(); |
||
| 50 | $s = $source->current(); |
||
| 51 | $target->next(); |
||
| 52 | $t = $target->current(); |
||
| 53 | } else if ($sv < $tv) { |
||
| 54 | $add($s); |
||
| 55 | $source->next(); |
||
| 56 | $s = $source->current(); |
||
| 57 | } else { // $s > $t |
||
| 58 | $remove($t); |
||
| 59 | $target->next(); |
||
| 60 | $t = $target->current(); |
||
| 61 | } |
||
| 65 | } |