Kint_Object::getSize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
class Kint_Object
0 ignored issues
show
Coding Style introduced by
Kint_Object 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 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...
4
{
5
    const ACCESS_NONE = null;
6
    const ACCESS_PUBLIC = 'public';
7
    const ACCESS_PROTECTED = 'protected';
8
    const ACCESS_PRIVATE = 'private';
9
10
    const OPERATOR_NONE = null;
11
    const OPERATOR_ARRAY = '=>';
12
    const OPERATOR_OBJECT = '->';
13
    const OPERATOR_STATIC = '::';
14
15
    public $name;
16
    public $type;
17
    public $static = false;
18
    public $const = false;
19
    public $access = self::ACCESS_NONE;
20
    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...
21
    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...
22
    public $operator = self::OPERATOR_NONE;
23
    public $reference = false;
24
    public $size = null;
25
    public $depth = 0;
26
    public $representations = array();
27
    public $value = null;
28
    public $hints = array();
29
30
    public function __construct()
31
    {
32
    }
33
34
    public function addRepresentation(Kint_Object_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...
35
    {
36
        if (isset($this->representations[$rep->name])) {
37
            return false;
38
        }
39
40
        if ($this->value === null) {
41
            $this->value = $rep;
42
        }
43
44
        if ($pos === null) {
45
            $this->representations[$rep->name] = $rep;
46
        } else {
47
            $this->representations = array_merge(
48
                array_slice($this->representations, 0, $pos),
49
                array($rep->name => $rep),
50
                array_slice($this->representations, $pos)
51
            );
52
        }
53
54
        return true;
55
    }
56
57
    public function replaceRepresentation(Kint_Object_Representation $rep, $pos = null)
58
    {
59
        if ($pos === null) {
60
            $this->representations[$rep->name] = $rep;
61
        } else {
62
            $this->removeRepresentation($rep->name);
63
            $this->addRepresentation($rep, $pos);
64
        }
65
    }
66
67
    public function removeRepresentation($name)
68
    {
69
        unset($this->representations[$name]);
70
    }
71
72
    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...
73
    {
74
        if (isset($this->representations[$name])) {
75
            return $this->representations[$name];
76
        }
77
    }
78
79
    public function getRepresentations()
80
    {
81
        return $this->representations;
82
    }
83
84
    public function clearRepresentations()
85
    {
86
        $this->representations = array();
87
    }
88
89
    public function getType()
90
    {
91
        return $this->type;
92
    }
93
94
    public function getModifiers()
95
    {
96
        $out = $this->getAccess();
97
98
        if ($this->const) {
99
            $out .= ' const';
100
        }
101
102
        if ($this->static) {
103
            $out .= ' static';
104
        }
105
106
        if (strlen($out)) {
107
            return ltrim($out);
108
        }
109
    }
110
111
    public function getAccess()
112
    {
113
        switch ($this->access) {
114
            case self::ACCESS_PRIVATE:
115
                return 'private';
116
            case self::ACCESS_PROTECTED:
117
                return 'protected';
118
            case self::ACCESS_PUBLIC:
119
                return 'public';
120
        }
121
    }
122
123
    public function getName()
124
    {
125
        return $this->name;
126
    }
127
128
    public function getOperator()
129
    {
130
        if ($this->operator === self::OPERATOR_ARRAY) {
131
            return '=>';
132
        } elseif ($this->operator === self::OPERATOR_OBJECT) {
133
            return '->';
134
        } elseif ($this->operator === self::OPERATOR_STATIC) {
135
            return '::';
136
        }
137
138
        return;
139
    }
140
141
    public function getSize()
142
    {
143
        return $this->size;
144
    }
145
146
    public function getValueShort()
147
    {
148
        if ($rep = $this->value) {
149
            if ($this->type === 'boolean') {
150
                return $rep->contents ? 'true' : 'false';
151
            } elseif ($this->type === 'integer' || $this->type === 'double') {
152
                return $rep->contents;
153
            }
154
        }
155
    }
156
157
    public function getAccessPath()
158
    {
159
        return $this->access_path;
160
    }
161
162
    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...
163
    {
164
        $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...
165
        $o->name = $name;
166
        $o->access_path = $name;
167
        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...
168
            $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...
169
        }
170
171
        return $o;
172
    }
173
174
    public function transplant(Kint_Object $new)
175
    {
176
        $new->name = $this->name;
177
        $new->size = $this->size;
178
        $new->access_path = $this->access_path;
179
        $new->access = $this->access;
180
        $new->static = $this->static;
181
        $new->const = $this->const;
182
        $new->type = $this->type;
183
        $new->depth = $this->depth;
184
        $new->owner_class = $this->owner_class;
185
        $new->operator = $this->operator;
186
        $new->reference = $this->reference;
187
        $new->value = $this->value;
188
        $new->representations += $this->representations;
189
        $new->hints = array_merge($this->hints, $new->hints);
190
191
        return $new;
192
    }
193
194
    public static function isSequential(array $array)
195
    {
196
        return array_keys($array) === range(0, count($array) - 1);
197
    }
198
199
    public static function sortByAccess(Kint_Object $a, Kint_Object $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(Kint_Object $a, Kint_Object $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($a->name) - is_int($b->name);
217
        }
218
219
        return $ret;
220
    }
221
}
222