Test Setup Failed
Push — master ( 3bfa70...333906 )
by Gabriel
13:19
created

HasCollectionResults::getCollectionClass()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 4
cts 5
cp 0.8
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2.032
1
<?php
2
3
namespace Nip\Records\Relations\Traits;
4
5
use Nip\Records\Collections\Associated as AssociatedCollection;
6
7
/**
8
 * Trait HasCollectionResults
9
 * @package Nip\Records\Relations\Traits
10
 *
11
 * @method string getParam($name)
12
 */
13
trait HasCollectionResults
14
{
15
16
    /**
17
     * @return AssociatedCollection
18
     */
19 1
    public function newCollection()
20
    {
21 1
        $class = $this->getCollectionClass();
22 1
        $collection = new $class();
23
        /** @var AssociatedCollection $collection */
24 1
        $collection->initFromRelation($this);
25
26 1
        return $collection;
27
    }
28
29
    /**
30
     * @return mixed|string
31
     */
32 1
    public function getCollectionClass()
33
    {
34 1
        $collection = $this->getParam('collection');
35 1
        if ($collection) {
36
            return $collection;
37
        }
38
39 1
        return AssociatedCollection::class;
40
    }
41
}
42