Completed
Push — master ( 160801...bd59d4 )
by Andreas
27:08
created

property::set_value()   A

Complexity

Conditions 6
Paths 6

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 8.048

Importance

Changes 0
Metric Value
cc 6
eloc 12
nc 6
nop 1
dl 0
loc 19
ccs 8
cts 13
cp 0.6153
crap 8.048
rs 9.2222
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright CONTENT CONTROL GmbH, http://www.contentcontrol-berlin.de
4
 */
5
6
namespace midcom\datamanager\storage;
7
8
use midgard_reflection_property;
9
use midcom_helper_reflector_nameresolver;
10
use midcom_helper_misc;
11
12
/**
13
 * Experimental storage class
14
 */
15
class property extends dbanode
16
{
17
    private $set = false;
18
19
    /**
20
     * {@inheritdoc}
21
     */
22 124
    public function get_value()
23
    {
24 124
        if (!$this->object->id && !$this->set && $this->config['type'] == 'number') {
25 13
            return;
26
        }
27 124
        $value = $this->object->{$this->config['storage']['location']};
28 124
        if ($value === 0) {
29 70
            $reflector = new midgard_reflection_property($this->object->__mgdschema_class_name__);
30 70
            if ($reflector->is_link($this->config['storage']['location'])) {
31 44
                return;
32
            }
33
        }
34
35 124
        return $this->cast($value);
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 38
    public function set_value($value)
42
    {
43 38
        if ($this->config['type'] === 'urlname') {
44
45 2
            if (empty($value)) {
46 1
                $title_field = (!empty($this->config['type_config']['title_field'])) ? $this->config['type_config']['title_field'] : 'title';
47 1
                $value = midcom_helper_misc::urlize($this->object->{$title_field});
48 1
            } elseif (!empty($this->config['type_config']['allow_catenate'])) {
49
                $copy = clone $this->object;
50
                $copy->{$this->config['storage']['location']} = $value;
51
                $resolver = new midcom_helper_reflector_nameresolver($copy);
52
                if (!$resolver->name_is_unique()) {
53
                    $value = $resolver->generate_unique_name();
54
                }
55
            }
56
        }
57
58 38
        $this->set = true;
59 38
        $this->object->{$this->config['storage']['location']} = $value;
60 38
    }
61
62 13
    public function save()
63
    {
64 13
    }
65
}
66