Code Duplication    Length = 8-9 lines in 7 locations

src/BoxList.php 1 location

@@ 34-41 (lines=8) @@
31
    /**
32
     * @return Traversable
33
     */
34
    public function getIterator(): Traversable
35
    {
36
        if (!$this->isSorted) {
37
            usort($this->list, [$this, 'compare']);
38
            $this->isSorted = true;
39
        }
40
        return new ArrayIterator($this->list);
41
    }
42
43
    /**
44
     * @param Box $item

src/PackedBoxList.php 2 locations

@@ 41-48 (lines=8) @@
38
    /**
39
     * @return Traversable
40
     */
41
    public function getIterator(): Traversable
42
    {
43
        if (!$this->isSorted) {
44
            usort($this->list, [$this, 'compare']);
45
            $this->isSorted = true;
46
        }
47
        return new ArrayIterator($this->list);
48
    }
49
50
    /**
51
     * Number of items in list
@@ 83-90 (lines=8) @@
80
     * @internal
81
     * @return PackedBox
82
     */
83
    public function top(): PackedBox
84
    {
85
        if (!$this->isSorted) {
86
            usort($this->list, [$this, 'compare']);
87
            $this->isSorted = true;
88
        }
89
        return reset($this->list);
90
    }
91
92
    /**
93
     * @param PackedBox $boxA

src/PackedItemList.php 1 location

@@ 42-49 (lines=8) @@
39
    /**
40
     * @return Traversable
41
     */
42
    public function getIterator(): Traversable
43
    {
44
        if (!$this->isSorted) {
45
            usort($this->list, [$this, 'compare']);
46
            $this->isSorted = true;
47
        }
48
        return new ArrayIterator($this->list);
49
    }
50
51
    /**
52
     * Number of items in list

src/ItemList.php 3 locations

@@ 43-50 (lines=8) @@
40
     * @internal
41
     * @return Item
42
     */
43
    public function extract(): Item
44
    {
45
        if (!$this->isSorted) {
46
            usort($this->list, [$this, 'compare']);
47
            $this->isSorted = true;
48
        }
49
        return array_shift($this->list);
50
    }
51
52
    /**
53
     * @internal
@@ 56-64 (lines=9) @@
53
     * @internal
54
     * @return Item
55
     */
56
    public function top(): Item
57
    {
58
        if (!$this->isSorted) {
59
            usort($this->list, [$this, 'compare']);
60
            $this->isSorted = true;
61
        }
62
        $temp = $this->list;
63
        return reset($temp);
64
    }
65
66
    /**
67
     * @return Traversable
@@ 69-76 (lines=8) @@
66
    /**
67
     * @return Traversable
68
     */
69
    public function getIterator(): Traversable
70
    {
71
        if (!$this->isSorted) {
72
            usort($this->list, [$this, 'compare']);
73
            $this->isSorted = true;
74
        }
75
        return new ArrayIterator($this->list);
76
    }
77
78
    /**
79
     * Number of items in list