Relation   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 18
c 1
b 0
f 0
dl 0
loc 102
ccs 18
cts 18
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getRelated() 0 3 1
A __construct() 0 5 1
A __call() 0 13 3
A getBuilder() 0 3 1
A getParent() 0 3 1
1
<?php
2
3
namespace Spinen\ClickUp\Support\Relations;
4
5
use Illuminate\Support\Traits\ForwardsCalls;
6
use Illuminate\Support\Traits\Macroable;
7
use Spinen\ClickUp\Exceptions\InvalidRelationshipException;
8
use Spinen\ClickUp\Support\Builder;
9
use Spinen\ClickUp\Support\Model;
10
11
/**
12
 * Class Relation
13
 *
14
 * @package Spinen\ClickUp\Support\Relations
15
 */
16
abstract class Relation
17
{
18
    use ForwardsCalls, Macroable {
0 ignored issues
show
Bug introduced by
The trait Illuminate\Support\Traits\Macroable requires the property $name which is not provided by Spinen\ClickUp\Support\Relations\Relation.
Loading history...
19
        __call as macroCall;
20
    }
21
22
    /**
23
     * The Eloquent builder builder instance.
24
     *
25
     * @var Builder
26
     */
27
    protected $builder;
28
29
    /**
30
     * The parent model instance.
31
     *
32
     * @var Model
33
     */
34
    protected $parent;
35
36
    /**
37
     * The related model instance.
38
     *
39
     * @var Model
40
     */
41
    protected $related;
42
43
    /**
44
     * Create a new relation instance.
45
     *
46
     * @param Builder $builder
47
     * @param Model $parent
48
     *
49
     * @return void
50
     * @throws InvalidRelationshipException
51
     */
52 77
    public function __construct(Builder $builder, Model $parent)
53
    {
54 77
        $this->builder = $builder;
55 77
        $this->parent = $parent;
56 77
        $this->related = $builder->getModel();
57 77
    }
58
59
    /**
60
     * Handle dynamic method calls to the relationship.
61
     *
62
     * @param string $method
63
     * @param array $parameters
64
     *
65
     * @return mixed
66
     */
67 3
    public function __call($method, $parameters)
68
    {
69 3
        if (static::hasMacro($method)) {
70 1
            return $this->macroCall($method, $parameters);
0 ignored issues
show
Bug introduced by
The method macroCall() does not exist on Spinen\ClickUp\Support\Relations\Relation. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

70
            return $this->/** @scrutinizer ignore-call */ macroCall($method, $parameters);
Loading history...
71
        }
72
73 2
        $result = $this->forwardCallTo($this->getBuilder(), $method, $parameters);
74
75 2
        if ($result === $this->getBuilder()) {
76 1
            return $this;
77
        }
78
79 1
        return $result;
80
    }
81
82
    /**
83
     * Get the Builder instance
84
     *
85
     * @return Builder
86
     */
87 11
    public function getBuilder(): Builder
88
    {
89 11
        return $this->builder;
90
    }
91
92
    /**
93
     * Get the parent Model instance
94
     *
95
     * @return Model
96
     */
97 4
    public function getParent(): Model
98
    {
99 4
        return $this->parent;
100
    }
101
102
    /**
103
     * Get the related Model instance
104
     *
105
     * @return Model
106
     */
107 1
    public function getRelated(): Model
108
    {
109 1
        return $this->related;
110
    }
111
112
    /**
113
     * Get the results of the relationship.
114
     *
115
     * @return mixed
116
     */
117
    abstract public function getResults();
118
}
119