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

HasCollectionResults   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 29
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A newCollection() 0 9 1
A getCollectionClass() 0 9 2
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