Passed
Push — 4.2 ( 598e93...7915fe )
by Sam
06:52
created

ViewableData_Customised::__isset()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 1
nc 3
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\View;
4
5
class ViewableData_Customised extends ViewableData
6
{
7
8
    /**
9
     * @var ViewableData
10
     */
11
    protected $original, $customised;
0 ignored issues
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
12
13
    /**
14
     * Instantiate a new customised ViewableData object
15
     *
16
     * @param ViewableData $originalObject
17
     * @param ViewableData $customisedObject
18
     */
19
    public function __construct(ViewableData $originalObject, ViewableData $customisedObject)
20
    {
21
        $this->original = $originalObject;
22
        $this->customised = $customisedObject;
23
24
        $this->original->setCustomisedObj($this);
25
26
        parent::__construct();
27
    }
28
29
    public function __call($method, $arguments)
30
    {
31
        if ($this->customised->hasMethod($method)) {
32
            return call_user_func_array(array($this->customised, $method), $arguments);
33
        }
34
35
        return call_user_func_array(array($this->original, $method), $arguments);
36
    }
37
38
    public function __get($property)
39
    {
40
        if (isset($this->customised->$property)) {
41
            return $this->customised->$property;
42
        }
43
44
        return $this->original->$property;
45
    }
46
47
    public function __set($property, $value)
48
    {
49
        $this->customised->$property = $this->original->$property = $value;
50
    }
51
52
    public function __isset($property)
53
    {
54
        return isset($this->customised->$property) || isset($this->original->$property) || parent::__isset($property);
55
    }
56
57
    public function hasMethod($method)
58
    {
59
        return $this->customised->hasMethod($method) || $this->original->hasMethod($method);
60
    }
61
62
    public function cachedCall($field, $arguments = null, $identifier = null)
63
    {
64
        if ($this->customised->hasMethod($field) || $this->customised->hasField($field)) {
65
            return $this->customised->cachedCall($field, $arguments, $identifier);
66
        }
67
        return $this->original->cachedCall($field, $arguments, $identifier);
68
    }
69
70
    public function obj($fieldName, $arguments = null, $cache = false, $cacheName = null)
71
    {
72
        if ($this->customised->hasField($fieldName) || $this->customised->hasMethod($fieldName)) {
73
            return $this->customised->obj($fieldName, $arguments, $cache, $cacheName);
74
        }
75
        return $this->original->obj($fieldName, $arguments, $cache, $cacheName);
76
    }
77
}
78