Completed
Pull Request — master (#1)
by Rougin
02:14
created

RelationshipTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 53
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getBelongsToRelationships() 0 4 1
A getRelationships() 0 4 1
A with() 0 12 3
1
<?php
2
3
namespace Rougin\Wildfire\Traits;
4
5
/**
6
 * Relationship Trait
7
 *
8
 * @package Wildfire
9
 * @author  Rougin Royce Gutib <[email protected]>
10
 */
11
trait RelationshipTrait
12
{
13
    /**
14
     * Defines an inverse one-to-one or many relationship.
15
     *
16
     * @var array
17
     */
18
    protected $belongs_to = [];
19
20
    /**
21
     * @var array
22
     */
23
    protected $with = [];
24
25
    /**
26
     * Returns "belongs to" relationships.
27
     *
28
     * @return
29
     */
30
    public function getBelongsToRelationships()
31
    {
32
        return $this->belongs_to;
33
    }
34
35
    /**
36
     * Gets the defined relationships.
37
     *
38
     * @return
39
     */
40
    public function getRelationships()
41
    {
42
        return $this->with;
43
    }
44
45
    /**
46
     * Adds a relationship/s to the model.
47
     *
48
     * @param  string|array $relationships
49
     * @return self
50
     */
51
    public function with($relationships)
52
    {
53
        if (is_string($relationships)) {
54
            $relationships = [ $relationships ];
55
        }
56
57
        foreach ($relationships as $relationship) {
58
            array_push($this->with, $relationship);
59
        }
60
61
        return $this;
62
    }
63
}
64