Test Setup Failed
Push — test ( 528f91...abcbcc )
by Jonathan
03:20
created

BasicObject::getOperator()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 4
nop 0
dl 0
loc 12
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace Kint\Object;
4
5
use Kint\Object\Representation\Representation;
6
7
class BasicObject
8
{
9
    const ACCESS_NONE = null;
10
    const ACCESS_PUBLIC = 1;
11
    const ACCESS_PROTECTED = 2;
12
    const ACCESS_PRIVATE = 3;
13
14
    const OPERATOR_NONE = null;
15
    const OPERATOR_ARRAY = 1;
16
    const OPERATOR_OBJECT = 2;
17
    const OPERATOR_STATIC = 3;
18
19
    public $name;
20
    public $type;
21
    public $static = false;
22
    public $const = false;
23
    public $access = self::ACCESS_NONE;
24
    public $owner_class;
0 ignored issues
show
Coding Style introduced by
$owner_class does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
25
    public $access_path;
0 ignored issues
show
Coding Style introduced by
$access_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
26
    public $operator = self::OPERATOR_NONE;
27
    public $reference = false;
28
    public $size = null;
29
    public $depth = 0;
30
    public $value = null;
31
    public $hints = array();
32
33
    protected $representations = array();
34
35
    public function __construct()
36
    {
37
    }
38
39
    public function addRepresentation(Representation $rep, $pos = null)
0 ignored issues
show
Coding Style introduced by
function addRepresentation() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
40
    {
41
        if (isset($this->representations[$rep->getName()])) {
42
            return false;
43
        }
44
45
        if ($pos === null) {
46
            $this->representations[$rep->getName()] = $rep;
47
        } else {
48
            $this->representations = array_merge(
49
                array_slice($this->representations, 0, $pos),
50
                array($rep->getName() => $rep),
51
                array_slice($this->representations, $pos)
52
            );
53
        }
54
55
        return true;
56
    }
57
58
    public function replaceRepresentation(Representation $rep, $pos = null)
59
    {
60
        if ($pos === null) {
61
            $this->representations[$rep->getName()] = $rep;
62
        } else {
63
            $this->removeRepresentation($rep);
64
            $this->addRepresentation($rep, $pos);
65
        }
66
    }
67
68
    public function removeRepresentation($rep)
69
    {
70
        if ($rep instanceof Representation) {
71
            unset($this->representations[$rep->getName()]);
72
        } elseif (is_string($rep)) {
73
            unset($this->representations[$rep]);
74
        }
75
    }
76
77
    public function getRepresentation($name)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
78
    {
79
        if (isset($this->representations[$name])) {
80
            return $this->representations[$name];
81
        }
82
    }
83
84
    public function getRepresentations()
85
    {
86
        return $this->representations;
87
    }
88
89
    public function clearRepresentations()
90
    {
91
        $this->representations = array();
92
    }
93
94
    public function getType()
95
    {
96
        return $this->type;
97
    }
98
99
    public function getModifiers()
100
    {
101
        $out = $this->getAccess();
102
103
        if ($this->const) {
104
            $out .= ' const';
105
        }
106
107
        if ($this->static) {
108
            $out .= ' static';
109
        }
110
111
        if (strlen($out)) {
112
            return ltrim($out);
113
        }
114
    }
115
116
    public function getAccess()
117
    {
118
        switch ($this->access) {
119
            case self::ACCESS_PRIVATE:
120
                return 'private';
121
            case self::ACCESS_PROTECTED:
122
                return 'protected';
123
            case self::ACCESS_PUBLIC:
124
                return 'public';
125
        }
126
    }
127
128
    public function getName()
129
    {
130
        return $this->name;
131
    }
132
133
    public function getOperator()
134
    {
135
        if ($this->operator === self::OPERATOR_ARRAY) {
136
            return '=>';
137
        } elseif ($this->operator === self::OPERATOR_OBJECT) {
138
            return '->';
139
        } elseif ($this->operator === self::OPERATOR_STATIC) {
140
            return '::';
141
        }
142
143
        return;
144
    }
145
146
    public function getSize()
147
    {
148
        return $this->size;
149
    }
150
151
    public function getValueShort()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
152
    {
153
        if ($rep = $this->value) {
154
            if ($this->type === 'boolean') {
155
                return $rep->contents ? 'true' : 'false';
156
            } elseif ($this->type === 'integer' || $this->type === 'double') {
157
                return $rep->contents;
158
            }
159
        }
160
    }
161
162
    public function getAccessPath()
163
    {
164
        return $this->access_path;
165
    }
166
167
    public static function blank($name = null, $access_path = null)
0 ignored issues
show
Coding Style introduced by
$access_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
168
    {
169
        $o = new self();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
170
        $o->name = $name;
171
        $o->access_path = $name;
172
        if ($access_path) {
0 ignored issues
show
Coding Style introduced by
$access_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
173
            $o->access_path = $access_path;
0 ignored issues
show
Coding Style introduced by
$access_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
174
        }
175
176
        return $o;
177
    }
178
179
    public function transplant(BasicObject $new)
180
    {
181
        $new->name = $this->name;
182
        $new->size = $this->size;
183
        $new->access_path = $this->access_path;
184
        $new->access = $this->access;
185
        $new->static = $this->static;
186
        $new->const = $this->const;
187
        $new->type = $this->type;
188
        $new->depth = $this->depth;
189
        $new->owner_class = $this->owner_class;
190
        $new->operator = $this->operator;
191
        $new->reference = $this->reference;
192
        $new->value = $this->value;
193
        $new->representations += $this->representations;
194
        $new->hints = array_merge($this->hints, $new->hints);
195
196
        return $new;
197
    }
198
199
    public static function isSequential(array $array)
200
    {
201
        return array_keys($array) === range(0, count($array) - 1);
202
    }
203
204
    public static function sortByAccess(BasicObject $a, BasicObject $b)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $a. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
205
    {
206
        static $sorts = array(
207
            self::ACCESS_PUBLIC => 1,
208
            self::ACCESS_PROTECTED => 2,
209
            self::ACCESS_PRIVATE => 3,
210
            self::ACCESS_NONE => 4,
211
        );
212
213
        return $sorts[$a->access] - $sorts[$b->access];
214
    }
215
216
    public static function sortByName(BasicObject $a, BasicObject $b)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $a. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
217
    {
218
        $ret = strnatcasecmp($a->name, $b->name);
219
220
        if ($ret === 0) {
221
            return is_int($a->name) - is_int($b->name);
222
        }
223
224
        return $ret;
225
    }
226
}
227