ModelRelation   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 4
Bugs 1 Features 1
Metric Value
wmc 8
c 4
b 1
f 1
lcom 1
cbo 1
dl 0
loc 55
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 14 3
A hasRelation() 0 4 2
A getFieldsWithRelations() 0 12 3
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
}