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

RelationshipTrait::with()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 9.4285
c 1
b 0
f 0
cc 3
eloc 6
nc 4
nop 1
crap 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