Passed
Push — master ( 859fdf...61ca2a )
by Rougin
03:25
created

Mixed::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 10
cc 1
nc 1
nop 2
crap 2
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
    public function __construct(QueryInterface $query, $primary)
34
    {
35
        parent::__construct($query);
36
37
        $this->primary = $primary;
38
    }
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
    public function add(ChildInterface $child, $field)
48
    {
49
        $this->children[$field] = $child;
50
51
        return $this;
52
    }
53
54
    /**
55
     * Returns all added child instances.
56
     *
57
     * @return \Rougin\Windstorm\ChildInterface[]
58
     */
59
    public function all()
60
    {
61
        return $this->children;
62
    }
63
64
    /**
65
     * Returns the primary key of the parent table.
66
     *
67
     * @return string
68
     */
69
    public function primary()
70
    {
71
        return $this->primary;
72
    }
73
}
74