Results::addItem()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
namespace EngineWorks\Pivot;
3
4
class Results extends Collection
5
{
6
    protected $itemsInstanceOf = Result::class;
7
8
    /** @var Result */
9
    private $parent;
10
11 10
    public function __construct(Result $parent)
12
    {
13 10
        $this->parent = $parent;
14 10
    }
15
16 8
    public function addItem($item, $key = null)
17
    {
18
        /* @var Result $item */
19 8
        $item->parent = $this->parent;
20 8
        return parent::addItem($item, $key);
21
    }
22
23 4
    public function orderBy(ResultOrdering $ordering)
24
    {
25
        // uasort — Sort an array with a user-defined comparison function and maintain index association
26 4
        uasort($this->items, [$ordering, 'orderItems']);
27 4
    }
28
}
29