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

Associated   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 65%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 64
ccs 13
cts 20
cp 0.65
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A save() 0 4 1
A getWithRelation() 0 4 1
A getItem() 0 4 1
A initFromRelation() 0 10 2
A setWithRelation() 0 4 1
A setItem() 0 4 1
1
<?php
2
3
namespace Nip\Records\Collections;
4
5
use Nip\Records\Collections\Collection as RecordCollection;
6
use Nip\Records\Record as Record;
7
use Nip\Records\Relations\HasOneOrMany as Relation;
8
use Nip\Records\Relations\Traits\HasCollectionResults;
9
10
class Associated extends RecordCollection
11
{
12
13
    /**
14
     * @var Relation
15
     */
16
    protected $_withRelation;
17
18
    /**
19
     * @var Record
20
     */
21
    protected $_item;
22
23
    /**
24
     * @param HasCollectionResults $relation
0 ignored issues
show
introduced by
The type HasCollectionResults for parameter $relation is a trait, and thus cannot be used for type-hinting in PHP. Maybe consider adding an interface and use that for type-hinting?
Loading history...
25
     */
26 1
    public function initFromRelation($relation)
27
    {
28 1
        $this->setWithRelation($relation);
29 1
        $this->setManager($relation->getWith());
0 ignored issues
show
Bug introduced by
It seems like getWith() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
30 1
        $this->setItem($relation->getItem());
0 ignored issues
show
Bug introduced by
It seems like getItem() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
31 1
        $indexKey = $relation->getParam('indexKey');
32 1
        if ($indexKey) {
33
            $this->setIndexKey($indexKey);
34
        }
35 1
    }
36
37
    public function save()
38
    {
39
        return $this->getWithRelation()->save();
40
    }
41
42
    /**
43
     * @return Relation
44
     */
45
    public function getWithRelation()
46
    {
47
        return $this->_withRelation;
48
    }
49
50
    /**
51
     * @param Relation $relation
52
     */
53 1
    public function setWithRelation($relation)
54
    {
55 1
        $this->_withRelation = $relation;
56 1
    }
57
58
    /**
59
     * @return Record
60
     */
61
    public function getItem()
62
    {
63
        return $this->_item;
64
    }
65
66
    /**
67
     * @param Record $item
68
     */
69 1
    public function setItem($item)
70
    {
71 1
        $this->_item = $item;
72 1
    }
73
}
74