Code Duplication    Length = 13-13 lines in 2 locations

src/Map.php 2 locations

@@ 530-542 (lines=13) @@
527
     *
528
     * @param callable|null $comparator Accepts two values to be compared.
529
     */
530
    public function sort(callable $comparator = null)
531
    {
532
        if ($comparator) {
533
            usort($this->pairs, function($a, $b) use ($comparator) {
534
                return $comparator($a->value, $b->value);
535
            });
536
537
        } else {
538
            usort($this->pairs, function($a, $b) {
539
                return $a->value <=> $b->value;
540
            });
541
        }
542
    }
543
544
    /**
545
     * Returns a sorted copy of the map, based on an optional callable
@@ 577-589 (lines=13) @@
574
     *
575
     * @param callable|null $comparator Accepts two keys to be compared.
576
     */
577
    public function ksort(callable $comparator = null)
578
    {
579
        if ($comparator) {
580
            usort($this->pairs, function($a, $b) use ($comparator) {
581
                return $comparator($a->key, $b->key);
582
            });
583
584
        } else {
585
            usort($this->pairs, function($a, $b) {
586
                return $a->key <=> $b->key;
587
            });
588
        }
589
    }
590
591
    /**
592
     * Returns a sorted copy of the map, based on an optional callable