ModelRelation::hasRelation()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 1
Metric Value
c 4
b 1
f 1
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 1
1
<?php namespace Mascame\Artificer\Model;
2
3
use Mascame\Artificer\Options\ModelOption;
4
5
class ModelRelation
6
{
7
8
    /**
9
     * @var
10
     */
11
    public $relations;
12
13
14
    /**
15
     * @return array|mixed
16
     */
17
    public function get()
18
    {
19
        if (!empty($this->relations)) {
20
            return $this->relations;
21
        }
22
23
        $fields = ModelOption::get('fields');
24
25
        if (empty($fields)) {
26
            return array();
27
        }
28
29
        return $this->relations = $this->getFieldsWithRelations($fields);
30
    }
31
32
    /**
33
     * @param $field
34
     * @return bool
35
     */
36
    private function hasRelation($field)
37
    {
38
        return (isset($field['relationship']) && isset($field['relationship']['method']));
39
    }
40
41
    /**
42
     * @param $fields
43
     * @return array
44
     */
45
    private function getFieldsWithRelations($fields)
46
    {
47
        $relations = array();
48
49
        foreach ($fields as $field) {
50
            if ($this->hasRelation($field)) {
51
                $relations = $field['relationship']['method'];
52
            }
53
        }
54
55
        return $relations;
56
    }
57
58
59
}