Passed
Push — master ( 89a9e2...8bb4e8 )
by Observer
01:15
created
engine/extensions/VLF/bin/parser.php 1 patch
Braces   +106 added lines, -87 removed lines patch added patch discarded remove patch
@@ -25,18 +25,20 @@  discard block
 block discarded – undo
25 25
      */
26 26
     public function __construct (string $content, array $settings = [])
27 27
     {
28
-        if (file_exists ($content))
29
-            $content = file_get_contents ($content);
28
+        if (file_exists ($content)) {
29
+                    $content = file_get_contents ($content);
30
+        }
30 31
 
31 32
         // Зачем? Так надо!
32 33
         $content = "# VLF begin\n\n$content\n\n# VLF end";
33 34
 
34 35
         foreach ($settings as $name => $setting)
35 36
         {
36
-            if (isset ($this->$name))
37
-                $this->$name = $setting;
38
-
39
-            else throw new \Exception ('Trying to setting up undefined property "'. $name .'"');
37
+            if (isset ($this->$name)) {
38
+                            $this->$name = $setting;
39
+            } else {
40
+                throw new \Exception ('Trying to setting up undefined property "'. $name .'"');
41
+            }
40 42
         }
41 43
 
42 44
         if ($this->use_caching && file_exists ($file = VLF_EXT_DIR .'/cache/'. sha1 ($content) .'.cache'))
@@ -49,9 +51,9 @@  discard block
 block discarded – undo
49 51
                 $this->links = $info[1][1];
50 52
 
51 53
                 return;
54
+            } else {
55
+                unlink ($file);
52 56
             }
53
-
54
-            else unlink ($file);
55 57
         }
56 58
 
57 59
         $info = $this->generateSyntaxTree ($content);
@@ -61,8 +63,9 @@  discard block
 block discarded – undo
61 63
 
62 64
         if ($this->use_caching)
63 65
         {
64
-            if (!is_dir (dirname (__DIR__) .'/cache'))
65
-                mkdir (dirname (__DIR__) .'/cache');
66
+            if (!is_dir (dirname (__DIR__) .'/cache')) {
67
+                            mkdir (dirname (__DIR__) .'/cache');
68
+            }
66 69
 
67 70
             file_put_contents (VLF_EXT_DIR .'/cache/'. sha1 ($content) .'.cache', gzdeflate (serialize ([sha1 (file_get_contents (__FILE__)), $info])));
68 71
         }
@@ -85,19 +88,22 @@  discard block
 block discarded – undo
85 88
         $tree           = [];
86 89
         $links          = [];
87 90
 
88
-        if ($this->debug_mode)
89
-            pre ($lines);
91
+        if ($this->debug_mode) {
92
+                    pre ($lines);
93
+        }
90 94
 
91 95
         foreach ($lines as $id => $line)
92 96
         {
93
-            if ($skip_at > $id)
94
-                continue;
97
+            if ($skip_at > $id) {
98
+                            continue;
99
+            }
95 100
 
96 101
             $height = $this->getLineHeight ($line);
97 102
             $words  = $this->linesFilter (explode (' ', $line));
98 103
 
99
-            if ($this->debug_mode)
100
-                pre ($words);
104
+            if ($this->debug_mode) {
105
+                            pre ($words);
106
+            }
101 107
 
102 108
             /**
103 109
              * Высокоинтеллектуальный фикс
@@ -118,16 +124,18 @@  discard block
 block discarded – undo
118 124
             {
119 125
                 $updated = false;
120 126
 
121
-                if ($this->debug_mode)
122
-                    pre ($current_object);
127
+                if ($this->debug_mode) {
128
+                                    pre ($current_object);
129
+                }
123 130
 
124 131
                 while (isset ($tree[$current_object]['info']['subparent_link']) && $tree[$link = $tree[$current_object]['info']['subparent_link']->link]['hard'] < $tree[$current_object]['hard'])
125 132
                 {
126 133
                     $current_object = $link;
127 134
                     $updated        = true;
128 135
 
129
-                    if ($this->debug_mode)
130
-                        pre ($current_object);
136
+                    if ($this->debug_mode) {
137
+                                            pre ($current_object);
138
+                    }
131 139
                 }
132 140
 
133 141
                 if (
@@ -136,13 +144,15 @@  discard block
 block discarded – undo
136 144
                     isset ($tree[$current_object]['info']['arguments'][0]) &&
137 145
                     $tree[$current_object]['info']['arguments'][0] instanceof VLFLink &&
138 146
                     $tree[$tree[$current_object]['info']['arguments'][0]->link]['hard'] < $tree[$current_object]['hard']
139
-                ) $current_object = $tree[$current_object]['info']['arguments'][0]->link;
140
-
141
-                elseif (!$updated)
142
-                    break;
147
+                ) {
148
+                    $current_object = $tree[$current_object]['info']['arguments'][0]->link;
149
+                } elseif (!$updated) {
150
+                                    break;
151
+                }
143 152
 
144
-                if ($this->debug_mode)
145
-                    pre ($current_object);
153
+                if ($this->debug_mode) {
154
+                                    pre ($current_object);
155
+                }
146 156
             }
147 157
 
148 158
             /**
@@ -150,8 +160,9 @@  discard block
 block discarded – undo
150 160
              */
151 161
             if (class_exists ($words[0]) || class_exists ('\VoidEngine\\'. $words[0]))
152 162
             {
153
-                if (!isset ($words[1]))
154
-                    throw new \Exception ('Object name mustn\'t be empty at line "'. $line .'"');
163
+                if (!isset ($words[1])) {
164
+                                    throw new \Exception ('Object name mustn\'t be empty at line "'. $line .'"');
165
+                }
155 166
 
156 167
                 /**
157 168
                  * Button NewButton
@@ -179,9 +190,7 @@  discard block
 block discarded – undo
179 190
                     $current_object = $id;
180 191
 
181 192
                     continue;
182
-                }
183
-
184
-                else
193
+                } else
185 194
                 {
186 195
                     $tree[$id] = [
187 196
                         'type'  => VLF_OBJECT_DEFINITION,
@@ -203,10 +212,9 @@  discard block
 block discarded – undo
203 212
                         
204 213
                         $end = strrpos ($line, ')');
205 214
 
206
-                        if ($end === false)
207
-                            throw new \Exception ('Line "'. $line .'" have arguments list initialization, but not have list ending');
208
-
209
-                        elseif ($begin < $end)
215
+                        if ($end === false) {
216
+                                                    throw new \Exception ('Line "'. $line .'" have arguments list initialization, but not have list ending');
217
+                        } elseif ($begin < $end)
210 218
                         {
211 219
                             $arguments = [];
212 220
                             // $parsed    = explode (',', substr ($line, $begin, $end - $begin));
@@ -216,18 +224,20 @@  discard block
 block discarded – undo
216 224
                             {
217 225
                                 $argument = trim ($argument);
218 226
 
219
-                                if (strlen ($argument) > 0)
220
-                                    $arguments[] = isset ($links[$argument]) ?
227
+                                if (strlen ($argument) > 0) {
228
+                                                                    $arguments[] = isset ($links[$argument]) ?
221 229
                                         new VLFLink ($argument, $links[$argument]) :
222 230
                                         $argument;
223
-
224
-                                else throw new \Exception ('Argument '. ($argument_id + 1) .' mustn\'t have zero length at line "'. $line .'"');
231
+                                } else {
232
+                                    throw new \Exception ('Argument '. ($argument_id + 1) .' mustn\'t have zero length at line "'. $line .'"');
233
+                                }
225 234
                             }
226 235
 
227 236
                             $tree[$id]['info']['arguments'] = $arguments;
228 237
 
229
-                            if (!$this->ignore_postobject_info && trim (substr ($line, $end)) > 0)
230
-                                throw new \Exception ('You mustn\'t write any chars after arguments definition');
238
+                            if (!$this->ignore_postobject_info && trim (substr ($line, $end)) > 0) {
239
+                                                            throw new \Exception ('You mustn\'t write any chars after arguments definition');
240
+                            }
231 241
                         }
232 242
 
233 243
                         $tree[$id]['info']['subparent_link'] = new VLFLink ($tree[$current_object]['info']['object_name'], $current_object);
@@ -291,13 +301,14 @@  discard block
 block discarded – undo
291 301
 
292 302
                         $comment .= $parsed[0];
293 303
                         $skip_at  = $parsed[1];
304
+                    } else {
305
+                        throw new \Exception ('Unknown char founded after syntax-control symbol at line "'. $line .'"');
294 306
                     }
295
-
296
-                    else throw new \Exception ('Unknown char founded after syntax-control symbol at line "'. $line .'"');
297 307
                 }
298 308
                 
299
-                if ($this->debug_mode)
300
-                    pre ("Comment:\n\n$comment");
309
+                if ($this->debug_mode) {
310
+                                    pre ("Comment:\n\n$comment");
311
+                }
301 312
             }
302 313
 
303 314
             /**
@@ -319,9 +330,9 @@  discard block
 block discarded – undo
319 330
 
320 331
                         $code   .= $parsed[0];
321 332
                         $skip_at = $parsed[1];
333
+                    } else {
334
+                        throw new \Exception ('Unknown char founded after syntax-control symbol at line "'. $line .'"');
322 335
                     }
323
-
324
-                    else throw new \Exception ('Unknown char founded after syntax-control symbol at line "'. $line .'"');
325 336
                 }
326 337
                 
327 338
                 $tree[$id] = [
@@ -376,8 +387,9 @@  discard block
 block discarded – undo
376 387
 
377 388
                 if ($postChar == ':' || $postChar == '^')
378 389
                 {
379
-                    if (!isset ($words[1]))
380
-                        throw new \Exception ('Property value mustn\'t be empty at line "'. $line .'"');
390
+                    if (!isset ($words[1])) {
391
+                                            throw new \Exception ('Property value mustn\'t be empty at line "'. $line .'"');
392
+                    }
381 393
 
382 394
                     $propertyName     = substr ($words[0], 0, -1);
383 395
                     $propertyValue    = implode (' ', array_slice ($words, 1));
@@ -412,8 +424,9 @@  discard block
 block discarded – undo
412 424
                         'syntax_nodes' => []
413 425
                     ];
414 426
 
415
-                    if (isset ($links[$info['info']['property_value']]))
416
-                        $info['info']['property_value'] = new VLFLink ($info['info']['property_value'], $links[$info['info']['property_value']]);
427
+                    if (isset ($links[$info['info']['property_value']])) {
428
+                                            $info['info']['property_value'] = new VLFLink ($info['info']['property_value'], $links[$info['info']['property_value']]);
429
+                    }
417 430
 
418 431
                     $tree[$current_object]['syntax_nodes'][] = $info;
419 432
                 }
@@ -431,10 +444,9 @@  discard block
 block discarded – undo
431 444
                         
432 445
                         $end = strrpos ($line, ')');
433 446
 
434
-                        if ($end === false)
435
-                            throw new \Exception ('Line "'. $line .'" have arguments list initialization, but not have list ending');
436
-
437
-                        elseif ($begin < $end)
447
+                        if ($end === false) {
448
+                                                    throw new \Exception ('Line "'. $line .'" have arguments list initialization, but not have list ending');
449
+                        } elseif ($begin < $end)
438 450
                         {
439 451
                             // $parsed = explode (',', substr ($line, $begin, $end - $begin));
440 452
                             $parsed = $this->parseArguments (substr ($line, $begin, $end - $begin));
@@ -443,24 +455,27 @@  discard block
 block discarded – undo
443 455
                             {
444 456
                                 $argument = trim ($argument);
445 457
 
446
-                                if (strlen ($argument) > 0)
447
-                                    $arguments[] = isset ($links[$argument]) ?
458
+                                if (strlen ($argument) > 0) {
459
+                                                                    $arguments[] = isset ($links[$argument]) ?
448 460
                                         new VLFLink ($argument, $links[$argument]) :
449 461
                                         $argument;
450
-
451
-                                else throw new \Exception ('Argument '. ($argument_id + 1) .' mustn\'t have zero length at line "'. $line .'"');
462
+                                } else {
463
+                                    throw new \Exception ('Argument '. ($argument_id + 1) .' mustn\'t have zero length at line "'. $line .'"');
464
+                                }
452 465
                             }
453 466
 
454
-                            if (!$this->ignore_postobject_info && trim (substr ($line, $end)) > 0)
455
-                                throw new \Exception ('You mustn\'t write any chars after arguments definition');
467
+                            if (!$this->ignore_postobject_info && trim (substr ($line, $end)) > 0) {
468
+                                                            throw new \Exception ('You mustn\'t write any chars after arguments definition');
469
+                            }
456 470
                         }
457 471
                     }
458 472
 
459 473
                     /**
460 474
                      * ->show
461 475
                      */
462
-                    elseif (!$this->ignore_unexpected_method_args)
463
-                        throw new \Exception ('Unexpected method arguments list at line "'. $line .'"');
476
+                    elseif (!$this->ignore_unexpected_method_args) {
477
+                                            throw new \Exception ('Unexpected method arguments list at line "'. $line .'"');
478
+                    }
464 479
 
465 480
                     $tree[$current_object]['syntax_nodes'][] = [
466 481
                         'type'  => VLF_METHOD_CALL,
@@ -513,7 +528,9 @@  discard block
 block discarded – undo
513 528
             /**
514 529
              * Что-то загадочное, таинственное, неизвестное человечеству
515 530
              */
516
-            else throw new \Exception ('Unknown structures founded at line "'. $line .'"');
531
+            else {
532
+                throw new \Exception ('Unknown structures founded at line "'. $line .'"');
533
+            }
517 534
         }
518 535
 
519 536
         return [$tree, $links];
@@ -535,8 +552,9 @@  discard block
 block discarded – undo
535 552
 
536 553
         foreach ($lines as $line_id => $line)
537 554
         {
538
-            if ($line_id <= $begin_id)
539
-                continue;
555
+            if ($line_id <= $begin_id) {
556
+                            continue;
557
+            }
540 558
 
541 559
             if (!(bool)(trim ($line)))
542 560
             {
@@ -547,13 +565,15 @@  discard block
 block discarded – undo
547 565
 
548 566
             $height = $this->getLineHeight ($line);
549 567
 
550
-            if ($this->debug_mode)
551
-                pre ("$height, $down_height, $line");
552
-
553
-            if ($height > $down_height)
554
-                $parsed .= "$line\n";
568
+            if ($this->debug_mode) {
569
+                            pre ("$height, $down_height, $line");
570
+            }
555 571
 
556
-            else break;
572
+            if ($height > $down_height) {
573
+                            $parsed .= "$line\n";
574
+            } else {
575
+                break;
576
+            }
557 577
         }
558 578
 
559 579
         return [$parsed, $line_id];
@@ -577,8 +597,9 @@  discard block
 block discarded – undo
577 597
     {
578 598
         $i = 0;
579 599
 
580
-        while (isset ($line[$i]) && $line[$i] == "\t")
581
-            ++$i;
600
+        while (isset ($line[$i]) && $line[$i] == "\t") {
601
+                    ++$i;
602
+        }
582 603
         
583 604
         return strlen ($line = str_repeat ('    ', $i) . substr ($line, $i)) - strlen ($line = trim ($line));
584 605
     }
@@ -595,8 +616,9 @@  discard block
 block discarded – undo
595 616
     {
596 617
         return array_filter ($segments, function ($text)
597 618
         {
598
-            if ($this->strong_line_parser && preg_match ('/[^a-z0-9]/i', $text))
599
-                throw new \Exception  ('Line "'. $text .'" mustn\'t have any not-alphabet or not-numeric characters');
619
+            if ($this->strong_line_parser && preg_match ('/[^a-z0-9]/i', $text)) {
620
+                            throw new \Exception  ('Line "'. $text .'" mustn\'t have any not-alphabet or not-numeric characters');
621
+            }
600 622
             
601 623
             return strlen (trim ($text)) > 0;
602 624
         });
@@ -617,18 +639,15 @@  discard block
 block discarded – undo
617 639
         {
618 640
             $t .= $arguments[$i];
619 641
 
620
-            if ($arguments[$i] == '\\')
621
-                $canSplit = $i + 1;
622
-
623
-            elseif ($canSplit < $i)
642
+            if ($arguments[$i] == '\\') {
643
+                            $canSplit = $i + 1;
644
+            } elseif ($canSplit < $i)
624 645
             {
625
-                if ($arguments[$i] == '\'' && !$split2)
626
-                    $split1 = !$split1;
627
-
628
-                elseif ($arguments[$i] == '"' && !$split1)
629
-                    $split2 = !$split2;
630
-
631
-                elseif (!$split1 && !$split2 && $arguments[$i] == ',')
646
+                if ($arguments[$i] == '\'' && !$split2) {
647
+                                    $split1 = !$split1;
648
+                } elseif ($arguments[$i] == '"' && !$split1) {
649
+                                    $split2 = !$split2;
650
+                } elseif (!$split1 && !$split2 && $arguments[$i] == ',')
632 651
                 {
633 652
                     $args[] = substr ($t, 0, -1);
634 653
                     $t = '';
Please login to merge, or discard this patch.