Code Duplication    Length = 13-13 lines in 2 locations

src/Map.php 2 locations

@@ 505-517 (lines=13) @@
502
     *
503
     * @param callable|null $comparator Accepts two values to be compared.
504
     */
505
    public function sort(callable $comparator = null)
506
    {
507
        if ($comparator) {
508
            usort($this->pairs, function($a, $b) use ($comparator) {
509
                return $comparator($a->value, $b->value);
510
            });
511
512
        } else {
513
            usort($this->pairs, function($a, $b) {
514
                return $a->value <=> $b->value;
515
            });
516
        }
517
    }
518
519
    /**
520
     * Returns a sorted copy of the map, based on an optional callable
@@ 541-553 (lines=13) @@
538
     *
539
     * @param callable|null $comparator Accepts two keys to be compared.
540
     */
541
    public function ksort(callable $comparator = null)
542
    {
543
        if ($comparator) {
544
            usort($this->pairs, function($a, $b) use ($comparator) {
545
                return $comparator($a->key, $b->key);
546
            });
547
548
        } else {
549
            usort($this->pairs, function($a, $b) {
550
                return $a->key <=> $b->key;
551
            });
552
        }
553
    }
554
555
    /**
556
     * Returns a sorted copy of the map, based on an optional callable