1 | <?php declare(strict_types = 1); |
||
13 | abstract class AbstractGenerator |
||
14 | { |
||
15 | /** @var AbstractGenerator Parent class generator */ |
||
16 | protected $parent; |
||
17 | |||
18 | /** @var array Generated code grouped by generator class name */ |
||
19 | protected $generatedCode = []; |
||
20 | |||
21 | /** @var int Indentation level */ |
||
22 | protected $indentation = 0; |
||
23 | |||
24 | /** |
||
25 | * MethodGenerator constructor. |
||
26 | * |
||
27 | * @param AbstractGenerator $parent Parent generator |
||
28 | */ |
||
29 | public function __construct(AbstractGenerator $parent = null) |
||
33 | |||
34 | /** |
||
35 | * Increase indentation. |
||
36 | * |
||
37 | * @return $this|AbstractGenerator |
||
38 | */ |
||
39 | public function increaseIndentation() : AbstractGenerator |
||
45 | |||
46 | /** |
||
47 | * Decrease indentation. |
||
48 | * |
||
49 | * @return $this|AbstractGenerator |
||
50 | */ |
||
51 | public function decreaseIndentation() : AbstractGenerator |
||
57 | |||
58 | /** |
||
59 | * Close current generator and return parent. |
||
60 | * |
||
61 | * @return AbstractGenerator|ClassGenerator|FunctionGenerator|MethodGenerator|PropertyGenerator|ClassConstantGenerator |
||
62 | */ |
||
63 | public function end() : AbstractGenerator |
||
76 | |||
77 | /** |
||
78 | * Generate code. |
||
79 | * |
||
80 | * @param int $indentation Code level |
||
81 | * |
||
82 | * @return string Generated code |
||
83 | */ |
||
84 | abstract public function code(int $indentation = 0) : string; |
||
85 | |||
86 | /** |
||
87 | * Set Comments block. |
||
88 | * |
||
89 | * @return CommentsGenerator Comments block generator |
||
90 | */ |
||
91 | public function defComment() : CommentsGenerator |
||
95 | |||
96 | /** |
||
97 | * Decrease indentation. |
||
98 | * |
||
99 | * @param int $indentation |
||
100 | * |
||
101 | * @return $this|AbstractGenerator|ClassGenerator |
||
102 | */ |
||
103 | public function setIndentation(int $indentation) : AbstractGenerator |
||
109 | |||
110 | /** |
||
111 | * Get indentation string. |
||
112 | * |
||
113 | * @param int $indentation Code level |
||
114 | * |
||
115 | * @return string Indentation string |
||
116 | */ |
||
117 | protected function indentation(int $indentation = 0) : string |
||
121 | |||
122 | /** |
||
123 | * Generate correct value. |
||
124 | * |
||
125 | * Method handles arrays, numerics, strings and constants. |
||
126 | * |
||
127 | * @param mixed $value Value |
||
128 | * |
||
129 | * @return mixed Value |
||
130 | */ |
||
131 | protected function parseValue($value) |
||
149 | |||
150 | /** |
||
151 | * Get array values definition. |
||
152 | * |
||
153 | * @param array $items Array key-value pairs collection |
||
154 | * |
||
155 | * @return string Array value definition |
||
156 | */ |
||
157 | protected function arrayValue(array $items = array()) |
||
180 | } |
||
181 |
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.