1 | <?php |
||
14 | class NewsTicker extends AbstractParser { |
||
15 | |||
16 | /** |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $interferences = array(); |
||
20 | |||
21 | /** |
||
22 | * @param $response |
||
23 | */ |
||
24 | public function __construct($response) { |
||
25 | parent::__construct($response); |
||
26 | $this->parse(); |
||
27 | |||
28 | } |
||
29 | |||
30 | protected function parse() { |
||
31 | $jsonString = str_replace('//OK', '', $this->getHtmlResponse()); |
||
32 | $array = json_decode($jsonString); |
||
|
|||
33 | |||
34 | $payload = null; |
||
35 | //Find the interesting part |
||
36 | foreach ($array as $item) { |
||
37 | if (is_array($item)) { |
||
38 | $payload = $item; |
||
39 | break; |
||
40 | } |
||
41 | } |
||
42 | if (null === $payload) { |
||
43 | throw new \Exception('unable to parse payload from ' . $jsonString); |
||
44 | } |
||
45 | |||
46 | //Remove the Javastuff |
||
47 | foreach ($payload as $key => $item) { |
||
48 | if (preg_match('/de.swm.mvglive.gwt.client.newsticker.NewstickerItem/', $item)) { |
||
49 | unset($payload[$key]); |
||
50 | } |
||
51 | if (preg_match('/java.util.ArrayList/', $item)) { |
||
52 | unset($payload[$key]); |
||
53 | } |
||
54 | } |
||
55 | |||
56 | if (0 != (count($payload) % 2)) { |
||
57 | throw new \Exception('Item count is odd! ' . $jsonString); |
||
58 | |||
59 | } |
||
60 | $object = new \stdClass(); |
||
61 | foreach ($payload as $key => $item) { |
||
62 | if (0 == ($key % 2)) { |
||
63 | $object = new \stdClass(); |
||
64 | $object->lines = $item; |
||
65 | |||
66 | //get Lines with problems |
||
67 | $stringToAnalyze = trim(str_replace('Linie(n)', '', $item)); |
||
68 | $linesString = explode(':', $stringToAnalyze)[0]; |
||
69 | $object->affectedLines = explode(',', $linesString); |
||
70 | array_walk($object->affectedLines, function (&$item) { |
||
71 | $item = trim($item); |
||
72 | }); |
||
73 | |||
74 | } else { |
||
75 | $object->messages = $item; |
||
76 | $this->interferences[] = $object; |
||
77 | } |
||
78 | |||
79 | } |
||
80 | |||
81 | } |
||
82 | |||
83 | public function getInterferences() { |
||
86 | } |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.