Passed
Push — master ( 9659cc...3ceb44 )
by Rougin
05:44
created

Mixed::all()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Rougin\Windstorm\Relation;
4
5
use Rougin\Windstorm\ChildInterface;
6
use Rougin\Windstorm\MixedInterface;
7
use Rougin\Windstorm\QueryInterface;
8
9
/**
10
 * Mixed
11
 *
12
 * @package Windstorm
13
 * @author  Rougin Gutib <[email protected]>
14
 */
15
class Mixed extends Wrappable implements MixedInterface
16
{
17
    /**
18
     * @var \Rougin\Windstorm\ChildInterface[]
19
     */
20
    protected $children = array();
21
22
    /**
23
     * @var string
24
     */
25
    protected $primary;
26
27
    /**
28
     * Initializes the mixed instance.
29
     *
30
     * @param \Rougin\Windstorm\QueryInterface $query
31
     * @param string                           $primary
32
     */
33 3
    public function __construct(QueryInterface $query, $primary)
34
    {
35 3
        parent::__construct($query);
36
37 3
        $this->primary = $primary;
38 3
    }
39
40
    /**
41
     * Creates a new child instance and adds it to its children.
42
     *
43
     * @param  \Rougin\Windstorm\ChildInterface $child
44
     * @param  string                           $field
45
     * @return self
46
     */
47 3
    public function add(ChildInterface $child, $field)
48
    {
49 3
        $this->children[$field] = $child;
50
51 3
        return $this;
52
    }
53
54
    /**
55
     * Returns all added child instances.
56
     *
57
     * @return \Rougin\Windstorm\ChildInterface[]
58
     */
59 3
    public function all()
60
    {
61 3
        return $this->children;
62
    }
63
64
    /**
65
     * Returns the primary key of the parent table.
66
     *
67
     * @return string
68
     */
69 3
    public function primary()
70
    {
71 3
        return $this->primary;
72
    }
73
}
74