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

ManyToOne   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 0 Features 2
Metric Value
wmc 7
c 5
b 0
f 2
lcom 2
cbo 7
dl 0
loc 72
rs 10
ccs 22
cts 22
cp 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A createAssociation() 0 7 1
A getJoinColumn() 0 10 2
A __call() 0 14 3
1
<?php
2
3
namespace LaravelDoctrine\Fluent\Relations;
4
5
use Doctrine\ORM\Mapping\Builder\AssociationBuilder;
6
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
7
use Doctrine\ORM\Mapping\NamingStrategy;
8
use LaravelDoctrine\Fluent\Builders\Traits\Macroable;
9
use LaravelDoctrine\Fluent\Builders\Traits\QueuesMacros;
10
use LaravelDoctrine\Fluent\Extensions\Gedmo\Blameable;
11
use LaravelDoctrine\Fluent\Relations\Traits\ManyTo;
12
use LaravelDoctrine\Fluent\Relations\Traits\Owning;
13
use LaravelDoctrine\Fluent\Relations\Traits\Primary;
14
15
/**
16
 * @method $this inversedBy($fieldName)
17
 * @method $this foreignKey($foreignKey)
18
 * @method $this localKey($localKey)
19
 * @method $this target($foreignKey)
20
 * @method $this source($localKey)
21
 * @method $this setJoinColumn($joinColumn)
22
 * @method $this setReferenceColumn($referenceColumn)
23
 * @method $this nullable()
24
 * @method $this unique()
25
 * @method $this onDelete($onDelete = null)
26
 *
27
 * Extensions:
28
 * @method Blameable blameable()
29
 */
30
class ManyToOne extends AbstractRelation
31
{
32
    use ManyTo, Owning, Primary, Macroable, QueuesMacros;
33
34
    /**
35
     * @param ClassMetadataBuilder $builder
36
     * @param NamingStrategy       $namingStrategy
37
     * @param string               $relation
38
     * @param string               $entity
39
     */
40 51
    public function __construct(ClassMetadataBuilder $builder, NamingStrategy $namingStrategy, $relation, $entity)
41
    {
42 51
        parent::__construct($builder, $namingStrategy, $relation, $entity);
43
44 51
        $this->addJoinColumn($relation);
45 51
    }
46
47
    /**
48
     * @param ClassMetadataBuilder $builder
49
     * @param string               $relation
50
     * @param string               $entity
51
     *
52
     * @return AssociationBuilder
53
     */
54 51
    protected function createAssociation(ClassMetadataBuilder $builder, $relation, $entity)
55
    {
56 51
        return $this->builder->createManyToOne(
57 51
            $relation,
58
            $entity
59 51
        );
60
    }
61
62
    /**
63
     * @param callable|null $callback
64
     *
65
     * @return JoinColumn|false
66
     */
67 15
    public function getJoinColumn(callable $callback = null)
68
    {
69 15
        $joinColumn = reset($this->joinColumns);
70
71 15
        if (is_callable($callback)) {
72 1
            $callback($joinColumn);
73 1
        }
74
75 15
        return $joinColumn;
76
    }
77
78
    /**
79
     * Magic call method works as a proxy for the Doctrine associationBuilder
80
     *
81
     * @param string $method
82
     * @param array  $args
83
     *
84
     * @throws \BadMethodCallException
85
     * @return $this
86
     */
87 19
    public function __call($method, $args)
88
    {
89 19
        if ($this->hasMacro($method)) {
90 5
            return $this->queueMacro($method, $args);
91
        }
92
93 14
        if (method_exists($this->getJoinColumn(), $method)) {
94 6
            call_user_func_array([$this->getJoinColumn(), $method], $args);
95
96 6
            return $this;
97
        }
98
99 8
        parent::__call($method, $args);
100 7
    }
101
}
102