1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Remorhaz\JSON\Data\Export; |
5
|
|
|
|
6
|
|
|
use Iterator; |
7
|
|
|
use Remorhaz\JSON\Data\Event\AfterArrayEventInterface; |
8
|
|
|
use Remorhaz\JSON\Data\Event\AfterElementEventInterface; |
9
|
|
|
use Remorhaz\JSON\Data\Event\AfterObjectEventInterface; |
10
|
|
|
use Remorhaz\JSON\Data\Event\AfterPropertyEventInterface; |
11
|
|
|
use Remorhaz\JSON\Data\Event\BeforeArrayEventInterface; |
12
|
|
|
use Remorhaz\JSON\Data\Event\BeforeElementEventInterface; |
13
|
|
|
use Remorhaz\JSON\Data\Event\BeforeObjectEventInterface; |
14
|
|
|
use Remorhaz\JSON\Data\Event\BeforePropertyEventInterface; |
15
|
|
|
use Remorhaz\JSON\Data\Event\ScalarEventInterface; |
16
|
|
|
use Remorhaz\JSON\Data\Value\DecodedJson\NodeValueFactory; |
17
|
|
|
use Remorhaz\JSON\Data\Value\NodeValueInterface; |
18
|
|
|
|
19
|
|
|
final class EventDecoder implements EventDecoderInterface |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
public function exportEvents(Iterator $events): ?NodeValueInterface |
23
|
|
|
{ |
24
|
|
|
$buffer = []; |
25
|
|
|
$structures = []; |
26
|
|
|
$structure = null; |
27
|
|
|
foreach ($events as $event) { |
28
|
|
|
switch (true) { |
29
|
|
|
case $event instanceof ScalarEventInterface: |
30
|
|
|
$buffer[] = $event->getData(); |
31
|
|
|
break; |
32
|
|
|
|
33
|
|
|
case $event instanceof BeforeArrayEventInterface: |
34
|
|
|
case $event instanceof BeforeObjectEventInterface: |
35
|
|
|
$structures[] = $structure; |
36
|
|
|
$structure = []; |
37
|
|
|
break; |
38
|
|
|
|
39
|
|
|
case $event instanceof BeforeElementEventInterface: |
40
|
|
|
case $event instanceof BeforePropertyEventInterface: |
41
|
|
|
break; |
42
|
|
|
|
43
|
|
|
case $event instanceof AfterElementEventInterface: |
44
|
|
|
$structure[$event->getIndex()] = array_pop($buffer); |
45
|
|
|
break; |
46
|
|
|
|
47
|
|
|
case $event instanceof AfterPropertyEventInterface: |
48
|
|
|
$structure[$event->getName()] = array_pop($buffer); |
49
|
|
|
break; |
50
|
|
|
|
51
|
|
|
case $event instanceof AfterArrayEventInterface: |
52
|
|
|
$buffer[] = $structure; |
53
|
|
|
$structure = array_pop($structures); |
54
|
|
|
break; |
55
|
|
|
|
56
|
|
|
case $event instanceof AfterObjectEventInterface: |
57
|
|
|
$buffer[] = (object) $structure; |
58
|
|
|
$structure = array_pop($structures); |
59
|
|
|
break; |
60
|
|
|
|
61
|
|
|
default: |
62
|
|
|
throw new Exception\UnknownEventException($event); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
if (empty($buffer)) { |
66
|
|
|
return null; |
67
|
|
|
} |
68
|
|
|
$data = array_pop($buffer); |
69
|
|
|
if (empty($buffer)) { |
70
|
|
|
return (new NodeValueFactory)->createValue($data); |
71
|
|
|
} |
72
|
|
|
throw new Exception\InvalidDataBufferException($buffer); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths