Completed
Push — extensions-support ( bcc5d6...dc7c75 )
by Patrick
03:13
created

ManyToMany::__call()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
ccs 4
cts 4
cp 1
cc 2
eloc 4
nc 2
nop 2
crap 2
1
<?php
2
3
namespace LaravelDoctrine\Fluent\Relations;
4
5
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
6
use Doctrine\ORM\Mapping\Builder\ManyToManyAssociationBuilder;
7
use Doctrine\ORM\Mapping\Builder\OneToManyAssociationBuilder;
8
use LaravelDoctrine\Fluent\Builders\Traits\Macroable;
9
use LaravelDoctrine\Fluent\Builders\Traits\QueuesMacros;
10
use LaravelDoctrine\Fluent\Relations\Traits\Indexable;
11
use LaravelDoctrine\Fluent\Relations\Traits\ManyTo;
12
use LaravelDoctrine\Fluent\Relations\Traits\Orderable;
13
use LaravelDoctrine\Fluent\Relations\Traits\Ownable;
14
use LaravelDoctrine\Fluent\Relations\Traits\Owning;
15
16
/**
17
 * @method $this mappedBy($fieldName)
18
 * @method $this inversedBy($fieldName)
19
 * @method $this orphanRemoval()
20
 */
21
class ManyToMany extends AbstractRelation
22
{
23
    use ManyTo, Owning, Ownable, Orderable, Indexable, Macroable, QueuesMacros;
24
25
    /**
26
     * @var ManyToManyAssociationBuilder
27
     */
28
    protected $association;
29
30
    /**
31
     * @param ClassMetadataBuilder $builder
32
     * @param string               $relation
33
     * @param string               $entity
34
     *
35
     * @return OneToManyAssociationBuilder
36
     */
37 49
    protected function createAssociation(ClassMetadataBuilder $builder, $relation, $entity)
38
    {
39 49
        return $this->builder->createManyToMany($relation, $entity);
40
    }
41
42
    /**
43
     * @param string $table
44
     *
45
     * @return $this
46
     */
47 3
    public function joinTable($table)
48
    {
49 3
        $this->association->setJoinTable($table);
50
51 3
        return $this;
52
    }
53
54
    /**
55
     * @param string $joinColumn
56
     * @param string $references
57
     * @param bool   $unique
58
     *
59
     * @return $this
60
     */
61 8
    public function joinColumn($joinColumn, $references = 'id', $unique = false)
62
    {
63 8
        $this->addJoinColumn(null, $joinColumn, $references, false, $unique);
64
65 8
        return $this;
66
    }
67
68
    /**
69
     * @param string $foreignKey
70
     * @param string $references
71
     * @param bool   $unique
72
     *
73
     * @return $this
74
     */
75 2
    public function foreignKey($foreignKey, $references = 'id', $unique = false)
76
    {
77 2
        return $this->joinColumn($foreignKey, $references, $unique);
78
    }
79
80
    /**
81
     * @param string $foreignKey
82
     * @param string $references
83
     * @param bool   $unique
84
     *
85
     * @return $this
86
     */
87 4
    public function source($foreignKey, $references = 'id', $unique = false)
88
    {
89 4
        return $this->joinColumn($foreignKey, $references, $unique);
90
    }
91
92
    /**
93
     * @param string $inverseKey
94
     * @param string $references
95
     * @param bool   $unique
96
     *
97
     * @return $this
98
     */
99 5
    public function inverseKey($inverseKey, $references = 'id', $unique = false)
100
    {
101 5
        $this->association->addInverseJoinColumn($inverseKey, $references, false, $unique);
102
103 5
        return $this;
104
    }
105
106
    /**
107
     * @param string $inverseKey
108
     * @param string $references
109
     * @param bool   $unique
110
     *
111
     * @return $this
112
     */
113 3
    public function target($inverseKey, $references = 'id', $unique = false)
114
    {
115 3
        return $this->inverseKey($inverseKey, $references, $unique);
116
    }
117
118
    /**
119
     * Magic call method works as a proxy for the Doctrine associationBuilder
120
     *
121
     * @param string $method
122
     * @param array  $args
123
     *
124
     * @throws \BadMethodCallException
125
     * @return $this
126
     */
127 19
    public function __call($method, $args)
128
    {
129 19
        if ($this->hasMacro($method)) {
130 4
            return $this->queueMacro($method, $args);
131
        }
132
133 15
        return parent::__call($method, $args);
134
    }
135
}
136