Passed
Push — master ( 57e618...056094 )
by Andreas
03:36
created

property   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 115
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 115
ccs 33
cts 33
cp 1
rs 10
c 0
b 0
f 0
wmc 10
lcom 1
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A get_parent() 0 4 1
B set() 0 22 5
A set_multiple() 0 6 2
1
<?php
2
/**
3
 * @author CONTENT CONTROL http://www.contentcontrol-berlin.de/
4
 * @copyright CONTENT CONTROL http://www.contentcontrol-berlin.de/
5
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
6
 */
7
8
namespace midgard\portable\mgdschema;
9
10
11
class property implements node
12
{
13
    public $link;
14
15
    public $noidlink;
16
17
    /**
18
     * DB column name (defaults to $this->name)
19
     *
20
     * @var string
21
     */
22
    public $field;
23
24
    /**
25
     * Does this field point to a parent
26
     *
27
     * @var string
28
     */
29
    public $parentfield;
30
31
    /**
32
     * Field name for MdgSchema object
33
     *
34
     * @var string
35
     */
36
    public $name;
37
38
    /**
39
     * Helpttext
40
     *
41
     * @var string
42
     */
43
    public $description;
44
45
    /**
46
     * Should an index be created for the column
47
     *
48
     * @var boolean
49
     */
50
    public $index = false;
51
52
    /**
53
     * Field type as written in XML
54
     *
55
     * @var string
56
     */
57
    public $type;
58
59
    /**
60
     * DB field type (defaults to $this->type)
61
     *
62
     * @var string
63
     */
64
    public $dbtype;
65
66
    /**
67
     * Are values unique?
68
     *
69
     * @var boolean
70
     */
71
    public $unique = false;
72
73
    /**
74
     * Parent type
75
     *
76
     * @var type
77
     */
78
    private $mgdschematype;
79
80 18
    public function __construct(type $parent, $name, $type)
81
    {
82 18
        $this->mgdschematype = $parent;
83 18
        $this->name = $name;
84 18
        $this->field = $name;
85 18
        $this->type = $type;
86 18
        $this->dbtype = $type;
87
        // type guid always gets an index (but the guid field itself already has unique)
88 18
        $this->index = ($type == 'guid' && $name != 'guid');
89 18
    }
90
91 5
    public function get_parent()
92
    {
93 5
        return $this->mgdschematype;
94
    }
95
96 17
    public function set($name, $value)
97
    {
98
        switch ($name) {
99 17
            case 'unique':
100 17
            case 'index':
101 15
                $value = ($value === 'yes');
102 15
                break;
103 17
            case 'link':
104 17
                $tmp = explode(':', $value);
105 17
                $value = [];
106 17
                $value['target'] = $tmp[0];
107 17
                $value['field'] = $tmp[1];
108 17
                if ($value['field'] !== 'id') {
109 15
                    $this->noidlink = $value;
110 15
                    $value = null;
111
                    // Doctrine can't figure this out automatically, so we do it here
112 15
                    $this->index = true;
113 15
                }
114 17
                break;
115
        }
116 17
        $this->$name = $value;
117 17
    }
118
119 15
    public function set_multiple(array $attributes)
120
    {
121 15
        foreach ($attributes as $name => $value) {
122 15
            $this->set($name, $value);
123 15
        }
124 15
    }
125
}
126