Completed
Pull Request — master (#2)
by Rougin
02:28
created

RelationshipTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 46
ccs 12
cts 12
cp 1
rs 10
c 1
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
 * @property array $belongs_to
12
 */
13
trait RelationshipTrait
14
{
15
    /**
16
     * @var array
17
     */
18
    private $_with = [];
19
20
    /**
21
     * Returns "belongs to" relationships.
22
     *
23
     * @return
24
     */
25 18
    public function getBelongsToRelationships()
26
    {
27 18
        return $this->belongs_to;
28
    }
29
30
    /**
31
     * Gets the defined relationships.
32
     *
33
     * @return
34
     */
35 18
    public function getRelationships()
36
    {
37 18
        return $this->_with;
38
    }
39
40
    /**
41
     * Adds a relationship/s to the model.
42
     *
43
     * @param  string|array $relationships
44
     * @return self
45
     */
46 3
    public function with($relationships)
47
    {
48 3
        if (is_string($relationships)) {
49 3
            $relationships = [ $relationships ];
50 3
        }
51
52 3
        foreach ($relationships as $relationship) {
53 3
            array_push($this->_with, $relationship);
54 3
        }
55
56 3
        return $this;
57
    }
58
}
59