Completed
Push — 1.1 ( e7f438...feb647 )
by Patrick
06:08 queued 01:36
created

ManyTo::addJoinColumn()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 24
ccs 12
cts 12
cp 1
rs 8.9713
cc 1
eloc 19
nc 1
nop 7
crap 1
1
<?php
2
3
namespace LaravelDoctrine\Fluent\Relations\Traits;
4
5
use LaravelDoctrine\Fluent\Relations\JoinColumn;
6
7
trait ManyTo
8
{
9
    /**
10
     * @var JoinColumn[]
11
     */
12
    protected $joinColumns = [];
13
14
    /**
15
     * Build the association
16
     */
17 81
    public function build()
18
    {
19 81
        foreach ($this->getJoinColumns() as $column) {
20 56
            $this->getAssociation()->addJoinColumn(
21 56
                $column->getJoinColumn(),
22 56
                $column->getReferenceColumn(),
23 56
                $column->isNullable(),
24 56
                $column->isUnique(),
25 56
                $column->getOnDelete(),
26 56
                $column->getColumnDefinition()
27 56
            );
28 81
        }
29
30 81
        parent::build();
31 80
    }
32
33
    /**
34
     * @param string      $relation
35
     * @param string|null $joinColumn
36
     * @param string|null $referenceColumn
37
     * @param bool|false  $nullable
38
     * @param bool|false  $unique
39
     * @param string|null $onDelete
40
     * @param string|null $columnDefinition
41
     *
42
     * @return $this
43
     */
44 127
    public function addJoinColumn(
45
        $relation,
46
        $joinColumn = null,
47
        $referenceColumn = null,
48
        $nullable = false,
49
        $unique = false,
50
        $onDelete = null,
51
        $columnDefinition = null
52
    ) {
53 127
        $joinColumn = new JoinColumn(
54 127
            $this->getNamingStrategy(),
55 127
            $relation,
56 127
            $joinColumn,
57 127
            $referenceColumn,
58 127
            $nullable,
59 127
            $unique,
60 127
            $onDelete,
61
            $columnDefinition
62 127
        );
63
64 127
        $this->pushJoinColumn($joinColumn);
65
66 127
        return $this;
67
    }
68
69
    /**
70
     * @param JoinColumn $column
71
     */
72 127
    protected function pushJoinColumn(JoinColumn $column)
73
    {
74 127
        $this->joinColumns[] = $column;
75 127
    }
76
77
    /**
78
     * @return JoinColumn[]
79
     */
80 83
    public function getJoinColumns()
81
    {
82 83
        return $this->joinColumns;
83
    }
84
85
    /**
86
     * @return \Doctrine\ORM\Mapping\Builder\AssociationBuilder
87
     */
88
    abstract public function getAssociation();
89
90
    /**
91
     * @return \Doctrine\ORM\Mapping\NamingStrategy
92
     */
93
    abstract public function getNamingStrategy();
94
}
95