Test Setup Failed
Push — test ( 546d28...089b88 )
by Jonathan
03:07
created

BasicObject::sortByAccess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 2
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Kint\Object;
4
5
use Kint\Object\Representation\Representation;
6
7
class BasicObject
0 ignored issues
show
Coding Style introduced by
The property $owner_class is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style introduced by
The property $access_path is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
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...
Coding Style Naming introduced by
The parameter $access_path is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

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 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...
200
    {
201
        static $sorts = array(
202
            self::ACCESS_PUBLIC => 1,
203
            self::ACCESS_PROTECTED => 2,
204
            self::ACCESS_PRIVATE => 3,
205
            self::ACCESS_NONE => 4,
206
        );
207
208
        return $sorts[$a->access] - $sorts[$b->access];
209
    }
210
211
    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...
212
    {
213
        $ret = strnatcasecmp($a->name, $b->name);
214
215
        if ($ret === 0) {
216
            return is_int($b->name) - is_int($a->name);
217
        }
218
219
        return $ret;
220
    }
221
}
222