Kint_ParserTest::testGetCleanArray()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 33
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 20
nc 1
nop 0
dl 0
loc 33
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
class Kint_ParserTest extends PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style introduced by
Kint_ParserTest 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...
4
{
5
    public function testTriggerComplete()
6
    {
7
        $this->assertEquals(
8
            Kint_Parser::TRIGGER_SUCCESS |
9
            Kint_Parser::TRIGGER_DEPTH_LIMIT |
10
            Kint_Parser::TRIGGER_RECURSION,
11
            Kint_Parser::TRIGGER_COMPLETE
12
        );
13
    }
14
15
    public function testParseInteger()
16
    {
17
        $p = new Kint_Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. 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...
18
        $b = Kint_Object::blank('$v');
0 ignored issues
show
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...
19
        $v = 1234;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. 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...
20
21
        $o = $p->parse($v, clone $b);
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...
22
23
        $this->assertEquals('$v', $o->access_path);
24
        $this->assertEquals('$v', $o->name);
25
        $this->assertEquals('integer', $o->type);
26
        $this->assertEquals('Kint_Object', get_class($o));
27
        $this->assertEquals('Kint_Object_Representation', get_class($o->value));
28
        $this->assertEquals(1234, $o->value->contents);
29
        $this->assertEquals(1234, $v);
30
        $this->assertEquals(0, $o->depth);
31
    }
32
33
    public function testParseBoolean()
34
    {
35
        $p = new Kint_Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. 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...
36
        $b = Kint_Object::blank('$v');
0 ignored issues
show
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...
37
        $v = true;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. 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...
38
39
        $o = $p->parse($v, clone $b);
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...
40
41
        $this->assertEquals('boolean', $o->type);
42
        $this->assertEquals(true, $o->value->contents);
43
44
        $v = false;
45
46
        $o = $p->parse($v, clone $b);
47
48
        $this->assertEquals(false, $o->value->contents);
49
    }
50
51
    public function testParseDouble()
52
    {
53
        $p = new Kint_Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. 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...
54
        $b = Kint_Object::blank('$v');
0 ignored issues
show
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...
55
        $v = 1234.5678;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. 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...
56
57
        $o = $p->parse($v, clone $b);
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...
58
59
        $this->assertEquals('double', $o->type);
60
        $this->assertEquals(1234.5678, $o->value->contents);
61
    }
62
63
    public function testParseNull()
64
    {
65
        $p = new Kint_Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. 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...
66
        $b = Kint_Object::blank('$v');
0 ignored issues
show
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...
67
        $v = null;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. 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...
68
69
        $o = $p->parse($v, clone $b);
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...
70
71
        $this->assertEquals('null', $o->type);
72
        $this->assertEquals(null, $o->value->contents);
73
    }
74
75
    public function testParseString()
76
    {
77
        $p = new Kint_Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. 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...
78
        $b = Kint_Object::blank('$v');
0 ignored issues
show
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...
79
        $v = 'The quick brown fox jumps over the lazy dog';
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. 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...
80
81
        $o = $p->parse($v, clone $b);
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...
82
83
        $this->assertEquals('string', $o->type);
84
        $this->assertEquals('Kint_Object_Blob', get_class($o));
85
        $this->assertEquals($v, $o->value->contents);
86
        $this->assertEquals(true, $o->value->implicit_label);
87
        $this->assertEquals('ASCII', $o->encoding);
0 ignored issues
show
Bug introduced by
The property encoding does not seem to exist in Kint_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
88
        $this->assertEquals(strlen($v), $o->size);
89
        $this->assertContains('string', $o->hints);
90
91
        // Apologies to Spanish programmers, Google made this sentence.
92
        $v = 'El zorro marrón rápido salta sobre el perro perezoso';
93
94
        $o = $p->parse($v, clone $b);
95
96
        $this->assertEquals($v, $o->value->contents);
97
        $this->assertEquals('UTF-8', $o->encoding);
98
        $this->assertEquals(mb_strlen($v, 'UTF-8'), $o->size);
99
        $this->assertNotEquals(strlen($v), $o->size);
100
    }
101
102
    public function testParseResource()
103
    {
104
        $p = new Kint_Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. 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...
105
        $b = Kint_Object::blank('$v');
0 ignored issues
show
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...
106
        $v = imagecreate(1, 1);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. 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...
107
108
        $o = $p->parse($v, clone $b);
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...
109
110
        $this->assertEquals('resource', $o->type);
111
        $this->assertEquals('Kint_Object_Resource', get_class($o));
112
        $this->assertEquals(null, $o->value);
113
        $this->assertEquals('gd', $o->resource_type);
0 ignored issues
show
Bug introduced by
The property resource_type does not seem to exist in Kint_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
114
    }
115
116
    public function testParseArray()
117
    {
118
        $p = new Kint_Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. 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...
119
        $b = Kint_Object::blank('$v');
0 ignored issues
show
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...
120
        $v = array(
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. 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...
121
            1234,
122
            'key' => 'value',
123
            1234 => 5678,
124
        );
125
126
        $o = $p->parse($v, clone $b);
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...
127
128
        $this->assertEquals('array', $o->type);
129
130
        $val = array_values($o->value->contents);
131
132
        $this->assertEquals(0, $val[0]->name);
133
        $this->assertEquals(1234, $val[0]->value->contents);
134
        $this->assertEquals('$v[0]', $val[0]->access_path);
135
        $this->assertEquals(Kint_Object::OPERATOR_ARRAY, $val[0]->operator);
136
        $this->assertEquals('key', $val[1]->name);
137
        $this->assertEquals('value', $val[1]->value->contents);
138
        $this->assertEquals('$v[\'key\']', $val[1]->access_path);
139
        $this->assertEquals(Kint_Object::OPERATOR_ARRAY, $val[1]->operator);
140
        $this->assertEquals(1234, $val[2]->name);
141
        $this->assertEquals(5678, $val[2]->value->contents);
142
        $this->assertEquals('$v[1234]', $val[2]->access_path);
143
        $this->assertEquals(Kint_Object::OPERATOR_ARRAY, $val[2]->operator);
144
    }
145
146
    public function testParseObject()
147
    {
148
        $p = new Kint_Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. 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...
149
        $b = Kint_Object::blank('$v');
0 ignored issues
show
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...
150
        $v = new ChildTestClass();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. 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...
151
152
        $o = $p->parse($v, clone $b);
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...
153
154
        $this->assertEquals('object', $o->type);
155
        $this->assertInstanceOf('Kint_Object_Instance', $o);
156
        $this->assertEquals('ChildTestClass', $o->classname);
0 ignored issues
show
Bug introduced by
The property classname does not seem to exist in Kint_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
157
        $this->assertEquals(spl_object_hash($v), $o->hash);
0 ignored issues
show
Bug introduced by
The property hash does not seem to exist in Kint_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
158
        $this->assertContains('object', $o->hints);
159
160
        $val = array_values($o->value->contents);
161
162
        $this->assertEquals('pub', $val[0]->name);
163
        $this->assertEquals('array', $val[0]->type);
164
        $this->assertEquals(Kint_Object::OPERATOR_OBJECT, $val[0]->operator);
165
        $this->assertEquals('$v->pub', $val[0]->access_path);
166
        $this->assertEquals('pro', $val[1]->name);
167
        $this->assertEquals('array', $val[1]->type);
168
        $this->assertEquals(Kint_Object::OPERATOR_OBJECT, $val[1]->operator);
169
        $this->assertNull($val[1]->access_path);
170
        $this->assertEquals('pri', $val[2]->name);
171
        $this->assertEquals('array', $val[2]->type);
172
        $this->assertEquals(Kint_Object::OPERATOR_OBJECT, $val[2]->operator);
173
        $this->assertNull($val[2]->access_path);
174
    }
175
176
    public function testParseUnknown()
177
    {
178
        $p = new Kint_Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. 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...
179
        $b = Kint_Object::blank('$v');
0 ignored issues
show
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...
180
        $v = imagecreate(1, 1);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. 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...
181
        imagedestroy($v);
182
183
        $o = $p->parse($v, clone $b);
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...
184
185
        $this->assertEquals('unknown', $o->type);
186
        $this->assertNull($o->value);
187
    }
188
189
    public function testParseReferences()
190
    {
191
        $p = new Kint_Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. 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...
192
        $b = Kint_Object::blank('$v');
0 ignored issues
show
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...
193
        $r = 1234;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $r. 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...
194
        $v = array(&$r, 1234);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. 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...
195
196
        $o = $p->parse($v, clone $b);
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...
197
198
        $this->assertEquals(true, $o->value->contents[0]->reference);
199
        $this->assertEquals(false, $o->value->contents[1]->reference);
200
201
        $v = new stdClass();
202
        $v->v1 = &$r;
203
        $v->v2 = 1234;
204
205
        $o = $p->parse($v, clone $b);
206
207
        $this->assertEquals(true, $o->value->contents[0]->reference);
208
        $this->assertEquals(false, $o->value->contents[1]->reference);
209
    }
210
211
    public function testParseRecursion()
212
    {
213
        $p = new Kint_Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. 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...
214
        $b = Kint_Object::blank('$v');
0 ignored issues
show
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...
215
        $v = array();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. 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...
216
        $v[] = &$v;
217
218
        $recursed = false;
219
220
        $pl = new ProxyPlugin(
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $pl. 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...
221
            array('array', 'object'),
222
            Kint_Parser::TRIGGER_RECURSION,
223
            function () use (&$recursed) {
224
                $recursed = true;
225
            }
226
        );
227
        $p->addPlugin($pl);
228
229
        $o = $p->parse($v, clone $b);
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...
230
231
        $this->assertContains('recursion', $o->value->contents[0]->hints);
232
        $this->assertEquals(true, $recursed);
233
234
        $v = new stdClass();
235
        $v->v = $v;
236
237
        $recursed = false;
238
239
        $o = $p->parse($v, clone $b);
240
241
        $this->assertContains('recursion', $o->value->contents[0]->hints);
242
        $this->assertEquals(true, $recursed);
243
    }
244
245
    public function testParseDepthLimit()
246
    {
247
        $p = new Kint_Parser(1);
0 ignored issues
show
Documentation introduced by
1 is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Comprehensibility introduced by
Avoid variables with short names like $p. 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...
248
        $b = Kint_Object::blank('$v');
0 ignored issues
show
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...
249
        $v = array(array(1234));
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. 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...
250
251
        $limit = false;
252
253
        $pl = new ProxyPlugin(
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $pl. 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...
254
            array('array', 'object'),
255
            Kint_Parser::TRIGGER_DEPTH_LIMIT,
256
            function () use (&$limit) {
257
                $limit = true;
258
            }
259
        );
260
        $p->addPlugin($pl);
261
262
        $o = $p->parse($v, clone $b);
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...
263
264
        $this->assertContains('depth_limit', $o->value->contents[0]->hints);
265
        $this->assertEquals(true, $limit);
266
267
        $limit = false;
268
269
        $v = new stdClass();
270
        $v->v = array(1234);
271
272
        $o = $p->parse($v, clone $b);
273
274
        $this->assertContains('depth_limit', $o->value->contents[0]->hints);
275
        $this->assertEquals(true, $limit);
276
    }
277
278
    public function testParseCastKeys()
279
    {
280
        $p = new Kint_Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. 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...
281
        $b = Kint_Object::blank('$v');
0 ignored issues
show
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...
282
283
        // Object from array
284
        $v1 = (object) array('value');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v1. 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...
285
        $o1 = $p->parse($v1, clone $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o1. 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...
286
287
        // Normal object
288
        $v2 = new stdClass();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v2. 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...
289
        $v2->{0} = 'value';
290
        $o2 = $p->parse($v2, clone $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o2. 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...
291
292
        // Array from object
293
        $v3 = new stdClass();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v3. 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...
294
        $v3->{0} = 'value';
295
        $v3 = (array) $v3;
296
        $o3 = $p->parse($v3, clone $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o3. 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...
297
298
        // Normal array
299
        $v4 = array('value');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v4. 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...
300
        $o4 = $p->parse($v4, clone $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o4. 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...
301
302
        // Object with both
303
        $v5 = (object) array('value');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v5. 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...
304
        $v5->{0} = 'value2';
305
        $o5 = $p->parse($v5, clone $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o5. 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...
306
307
        // Array with both
308
        $v6 = new stdClass();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v6. 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...
309
        $v6->{0} = 'value';
310
        $v6 = (array) $v6;
311
        $v6['0'] = 'value2';
312
        $o6 = $p->parse($v6, clone $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o6. 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...
313
314
        if (version_compare(PHP_VERSION, '7.2') >= 0) {
315
            // Object from array
316
            $this->assertEquals(1, $o1->size);
317
            $this->assertEquals('value', $o1->value->contents[0]->value->contents);
318
            $this->assertEquals('$v->{\'0\'}', $o1->value->contents[0]->access_path);
319
            $this->assertTrue(isset($v1->{'0'}));
320
            $this->assertSame('0', $o1->value->contents[0]->name);
321
322
            // Normal object
323
            $this->assertEquals(1, $o2->size);
324
            $this->assertEquals('value', $o2->value->contents[0]->value->contents);
325
            $this->assertEquals('$v->{\'0\'}', $o2->value->contents[0]->access_path);
326
            $this->assertTrue(isset($v2->{'0'}));
327
            $this->assertSame('0', $o2->value->contents[0]->name);
328
329
            // Array from object
330
            $this->assertEquals(1, $o3->size);
331
            $this->assertEquals('value', $o3->value->contents[0]->value->contents);
332
            $this->assertEquals('$v[0]', $o3->value->contents[0]->access_path);
333
            $this->assertTrue(isset($v3['0']));
334
            $this->assertSame(0, $o3->value->contents[0]->name);
335
336
            // Normal array
337
            $this->assertEquals(1, $o4->size);
338
            $this->assertEquals('value', $o4->value->contents[0]->value->contents);
339
            $this->assertEquals('$v[0]', $o4->value->contents[0]->access_path);
340
            $this->assertTrue(isset($v4['0']));
341
            $this->assertSame(0, $o4->value->contents[0]->name);
342
343
            // Object with both
344
            $this->assertEquals(1, $o5->size);
345
            $this->assertEquals('value2', $o5->value->contents[0]->value->contents);
346
            $this->assertEquals('$v->{\'0\'}', $o5->value->contents[0]->access_path);
347
            $this->assertSame('0', $o5->value->contents[0]->name);
348
349
            // Array with both
350
            $this->assertEquals(1, $o6->size);
351
            $this->assertEquals('value2', $o6->value->contents[0]->value->contents);
352
            $this->assertEquals('$v[0]', $o6->value->contents[0]->access_path);
353
            $this->assertSame(0, $o6->value->contents[0]->name);
354
355
            // Object with both and weak equality (As of PHP 7.2)
356
            $v7 = (object) array('value');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v7. 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...
357
            $v7->{'0'} = 'value2';
358
            $v7->{''} = 'value3';
359
            $o7 = $p->parse($v7, clone $b);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o7. 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...
360
361
            // Object with both and weak equality
362
            $this->assertEquals(2, $o7->size);
363 View Code Duplication
            foreach ($o7->value->contents as $o) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
364
                $this->assertContains($o->value->contents, array('value2', 'value3'));
365
366
                if ($o->value->contents === 'value2') {
367
                    $this->assertEquals('$v->{\'0\'}', $o->access_path);
368
                    $this->assertSame('0', $o->name);
369
                } elseif ($o->value->contents === 'value3') {
370
                    $this->assertEquals('$v->{\'\'}', $o->access_path);
371
                    $this->assertSame('', $o->name);
372
                }
373
            }
374
        } else {
375
            // Object from array
376
            $this->assertEquals(1, $o1->size);
377
            $this->assertEquals('value', $o1->value->contents[0]->value->contents);
378
            $this->assertEquals('array_values((array) $v)[0]', $o1->value->contents[0]->access_path);
379
            $this->assertFalse(isset($v1->{'0'}));
380
            $this->assertSame(0, $o1->value->contents[0]->name);
381
382
            // Normal object
383
            $this->assertEquals(1, $o2->size);
384
            $this->assertEquals('value', $o2->value->contents[0]->value->contents);
385
            $this->assertEquals('$v->{\'0\'}', $o2->value->contents[0]->access_path);
386
            $this->assertTrue(isset($v2->{'0'}));
387
            $this->assertSame('0', $o2->value->contents[0]->name);
388
389
            // Array from object
390
            $this->assertEquals(1, $o3->size);
391
            $this->assertEquals('value', $o3->value->contents[0]->value->contents);
392
            $this->assertEquals('array_values($v)[0]', $o3->value->contents[0]->access_path);
393
            $this->assertFalse(isset($v3['0']));
394
            $this->assertSame('0', $o3->value->contents[0]->name);
395
396
            // Normal array
397
            $this->assertEquals(1, $o4->size);
398
            $this->assertEquals('value', $o4->value->contents[0]->value->contents);
399
            $this->assertEquals('$v[0]', $o4->value->contents[0]->access_path);
400
            $this->assertTrue(isset($v4['0']));
401
            $this->assertSame(0, $o4->value->contents[0]->name);
402
403
            // Object with both
404
            $this->assertEquals(2, $o5->size);
405 View Code Duplication
            foreach ($o5->value->contents as $o) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
406
                $this->assertContains($o->value->contents, array('value', 'value2'));
407
408
                if ($o->value->contents === 'value') {
409
                    $this->assertEquals('array_values((array) $v)[0]', $o->access_path);
410
                    $this->assertSame(0, $o->name);
411
                } elseif ($o->value->contents === 'value2') {
412
                    $this->assertEquals('$v->{\'0\'}', $o->access_path);
413
                    $this->assertSame('0', $o->name);
414
                }
415
            }
416
417
            // Array with both
418
            $this->assertEquals(2, $o6->size);
419 View Code Duplication
            foreach ($o6->value->contents as $o) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
420
                $this->assertContains($o->value->contents, array('value', 'value2'));
421
422
                if ($o->value->contents === 'value') {
423
                    $this->assertEquals('array_values($v)[0]', $o->access_path);
424
                    $this->assertSame('0', $o->name);
425
                } elseif ($o->value->contents === 'value2') {
426
                    $this->assertEquals('$v[0]', $o->access_path);
427
                    $this->assertSame(0, $o->name);
428
                }
429
            }
430
        }
431
    }
432
433
    public function testParseAccessPathAvailability()
434
    {
435
        $b = Kint_Object::blank('$v');
0 ignored issues
show
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...
436
        $v = new ChildTestClass();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. 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...
437
438
        $p = new Kint_Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. 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...
439
        $o = $p->parse($v, clone $b);
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...
440
        $properties = array();
441
        foreach ($o->value->contents as $prop) {
442
            $properties[$prop->name] = $prop;
443
        }
444
        $this->assertEquals('$v->pub', $properties['pub']->access_path);
445
        $this->assertNull($properties['pro']->access_path);
446
        $this->assertNull($properties['pri']->access_path);
447
448
        $p = new Kint_Parser(false, 'ChildTestClass');
449
        $o = $p->parse($v, clone $b);
450
        $properties = array();
451
        foreach ($o->value->contents as $prop) {
452
            $properties[$prop->name] = $prop;
453
        }
454
        $this->assertEquals('$v->pub', $properties['pub']->access_path);
455
        $this->assertEquals('$v->pro', $properties['pro']->access_path);
456
        $this->assertNull($properties['pri']->access_path);
457
458
        $p = new Kint_Parser(false, 'TestClass');
459
        $o = $p->parse($v, clone $b);
460
        $properties = array();
461
        foreach ($o->value->contents as $prop) {
462
            $properties[$prop->name] = $prop;
463
        }
464
        $this->assertEquals('$v->pub', $properties['pub']->access_path);
465
        $this->assertEquals('$v->pro', $properties['pro']->access_path);
466
        $this->assertEquals('$v->pri', $properties['pri']->access_path);
467
    }
468
469
    public function testPlugins()
470
    {
471
        $p = new Kint_Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. 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...
472
        $b = Kint_Object::blank('$v');
0 ignored issues
show
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...
473
        $v = 1234;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. 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...
474
475
        $o = $p->parse($v, clone $b);
476
477
        $this->assertObjectNotHasAttribute('testPluginCorrectlyActivated', $o);
478
479
        $pl = new ProxyPlugin(
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $pl. 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...
480
            array('integer'),
481
            Kint_Parser::TRIGGER_SUCCESS,
482
            function (&$var, &$o) {
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...
483
                $o->testPluginCorrectlyActivated = true;
484
            }
485
        );
486
        $p->addPlugin($pl);
487
488
        $o = $p->parse($v, clone $b);
489
490
        $this->assertObjectHasAttribute('testPluginCorrectlyActivated', $o);
491
492
        $p->clearPlugins();
493
494
        $o = $p->parse($v, clone $b);
495
496
        $this->assertObjectNotHasAttribute('testPluginCorrectlyActivated', $o);
497
    }
498
499
    public function testTriggers()
500
    {
501
        $p = new Kint_Parser(1);
0 ignored issues
show
Documentation introduced by
1 is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Comprehensibility introduced by
Avoid variables with short names like $p. 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...
502
        $b = Kint_Object::blank('$v');
0 ignored issues
show
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...
503
        $v = array(1234, array(1234));
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. 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...
504
        $v[] = &$v;
505
506
        $triggers = array();
507
508
        $pl = new ProxyPlugin(
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $pl. 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...
509
            array('integer', 'array'),
510
            Kint_Parser::TRIGGER_BEGIN | Kint_Parser::TRIGGER_COMPLETE,
511
            function (&$var, &$o, $trig) use (&$triggers) {
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...
512
                $triggers[] = $trig;
513
            }
514
        );
515
        $p->addPlugin($pl);
516
517
        $o = $p->parse($v, clone $b);
0 ignored issues
show
Unused Code introduced by
$o is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
518
519
        $this->assertEquals(array(
520
                Kint_Parser::TRIGGER_BEGIN,
521
                Kint_Parser::TRIGGER_BEGIN,
522
                Kint_Parser::TRIGGER_SUCCESS,
523
                Kint_Parser::TRIGGER_BEGIN,
524
                Kint_Parser::TRIGGER_DEPTH_LIMIT,
525
                Kint_Parser::TRIGGER_BEGIN,
526
                Kint_Parser::TRIGGER_RECURSION,
527
                Kint_Parser::TRIGGER_SUCCESS,
528
            ),
529
            $triggers
530
        );
531
    }
532
533
    public function testHaltParse()
534
    {
535
        $p = new Kint_Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. 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...
536
        $b = Kint_Object::blank('$v');
0 ignored issues
show
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...
537
        $t = clone $b;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $t. 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...
538
        $t->type = 'integer';
539
        $v = 1234;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. 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...
540
541
        $pl = new ProxyPlugin(
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $pl. 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...
542
            array('integer'),
543
            Kint_Parser::TRIGGER_BEGIN,
544
            function (&$var, &$o, $trig, $parser) {
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...
545
                $parser->haltParse();
546
            }
547
        );
548
        $p->addPlugin($pl);
549
550
        $o = $p->parse($v, clone $b);
551
552
        $this->assertEquals($t, $o);
553
554
        $p->clearPlugins();
555
556
        $pl = new ProxyPlugin(
557
            array('integer'),
558
            Kint_Parser::TRIGGER_SUCCESS,
559
            function (&$var, &$o, $trig, $parser) {
560
                $parser->haltParse();
561
            }
562
        );
563
        $p->addPlugin($pl);
564
565
        $pl = new ProxyPlugin(
566
            array('integer'),
567
            Kint_Parser::TRIGGER_SUCCESS,
568
            function (&$var, &$o) {
569
                $o->testPluginCorrectlyActivated = true;
570
            }
571
        );
572
        $p->addPlugin($pl);
573
574
        $o = $p->parse($v, clone $b);
575
576
        $this->assertObjectNotHasAttribute('testPluginCorrectlyActivated', $o);
577
    }
578
579
    /**
580
     * @expectedException \PHPUnit_Framework_Error_Warning
581
     */
582
    public function testPluginExceptionBecomesWarning()
583
    {
584
        $p = new Kint_Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. 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...
585
        $b = Kint_Object::blank('$v');
0 ignored issues
show
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...
586
        $t = clone $b;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $t. 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...
587
        $t->type = 'integer';
588
        $v = 1234;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. 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...
589
590
        $message = __FUNCTION__;
591
592
        $pl = new ProxyPlugin(
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $pl. 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...
593
            array('integer'),
594
            Kint_Parser::TRIGGER_BEGIN,
595
            function (&$var, &$o, $trig, $parser) use ($message) {
0 ignored issues
show
Unused Code introduced by
The parameter $var is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $o is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $trig is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $parser is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
596
                throw new Exception($message);
597
            }
598
        );
599
        $p->addPlugin($pl);
600
601
        $o = $p->parse($v, clone $b);
0 ignored issues
show
Unused Code introduced by
$o is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
602
    }
603
604
    public function childHasPathProvider()
605
    {
606
        $data = array();
607
608
        $expected = array(
609
            'public parser' => array(
610
                new Kint_Parser(),
611
                array(
612
                    'props' => array('$v', false, true, false, false),
613
                    'statics' => array('$v', true, true, false, false),
614
                    'props without path' => array(null, false, false, false, false),
615
                    'statics without path' => array(null, true, true, false, false),
616
                ),
617
            ),
618
            'protected parser' => array(
619
                new Kint_Parser(false, 'ChildTestClass'),
620
                array(
621
                    'props' => array('$v', false, true, true, false),
622
                    'statics' => array('$v', true, true, true, false),
623
                    'props without path' => array(null, false, false, false, false),
624
                    'statics without path' => array(null, true, true, true, false),
625
                ),
626
            ),
627
            'private parser' => array(
628
                new Kint_Parser(false, 'TestClass'),
629
                array(
630
                    'props' => array('$v', false, true, true, true),
631
                    'statics' => array('$v', true, true, true, true),
632
                    'props without path' => array(null, false, false, false, false),
633
                    'statics without path' => array(null, true, true, true, true),
634
                ),
635
            ),
636
        );
637
638
        foreach ($expected as $parser_name => $params) {
0 ignored issues
show
Coding Style introduced by
$parser_name 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...
639
            list($parser, $opts) = $params;
640
641
            foreach ($opts as $name => $set) {
642
                list($path, $static, $pub, $pro, $pri) = $set;
643
644
                $visibilities = array(
645
                    Kint_Object::ACCESS_PUBLIC => $pub,
646
                    Kint_Object::ACCESS_PROTECTED => $pro,
647
                    Kint_Object::ACCESS_PRIVATE => $pri,
648
                );
649
650
                foreach ($visibilities as $visibility => $expect) {
651
                    $parent = Kint_Object::blank();
652
                    $parent = $parent->transplant(new Kint_Object_Instance());
653
                    $parent->classname = 'ChildTestClass';
0 ignored issues
show
Bug introduced by
The property classname does not seem to exist in Kint_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
654
                    $parent->type = 'object';
655
656
                    $r = new Kint_Object_Representation('Contents');
657
                    $parent->addRepresentation($r);
658
659
                    $prop = Kint_Object::blank();
660
                    $r->contents = array($prop);
661
                    $prop->owner_class = 'TestClass';
662
663
                    $parent->access_path = $path;
664
                    $prop->static = $static;
665
                    $prop->access = $visibility;
666
667
                    $data[$parser_name.', '.$visibility.' '.$name] = array($parser, $parent, $prop, $expect);
0 ignored issues
show
Coding Style introduced by
$parser_name 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...
668
                }
669
            }
670
        }
671
672
        return $data;
673
    }
674
675
    /**
676
     * @dataProvider childHasPathProvider
677
     */
678
    public function testChildHasPath($parser, $parent, $child, $expected)
679
    {
680
        $this->assertEquals($expected, $parser->childHasPath($parent, $child));
681
    }
682
683
    public function testGetCleanArray()
684
    {
685
        $p = new Kint_Parser();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. 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...
686
        $b = Kint_Object::blank('$v');
0 ignored issues
show
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...
687
        $v = array(1234);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $v. 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...
688
689
        $arrays = array();
690
691
        $pl = new ProxyPlugin(
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $pl. 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...
692
            array('array'),
693
            Kint_Parser::TRIGGER_SUCCESS,
694
            function (&$var, &$o, $trig, $parser) use (&$arrays) {
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...
695
                $clean = $parser->getCleanArray($var);
696
697
                // This here is exactly why you should never alter input
698
                // variables in plugins and always use getCleanArray
699
                $var[] = 4321;
700
                $clean[] = 8765;
701
702
                $arrays = array(
703
                    'var' => $var,
704
                    'clean' => $clean,
705
                );
706
            }
707
        );
708
        $p->addPlugin($pl);
709
710
        $o = $p->parse($v, clone $b);
0 ignored issues
show
Unused Code introduced by
$o is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
711
712
        $this->assertEquals(array(1234, 4321), $v);
713
        $this->assertEquals(array(1234, 8765), $arrays['clean']);
714
        $this->assertEquals(count($v) + 1, count($arrays['var']));
715
    }
716
}
717