1 | <?php |
||
12 | class RemoveComments extends AbstractPass |
||
13 | { |
||
14 | /** |
||
15 | * @var string[] List of annotations to preserve |
||
16 | */ |
||
17 | public $preserveAnnotations = [ |
||
18 | 'license' |
||
19 | ]; |
||
20 | |||
21 | /** |
||
22 | * @var bool Whether to remove DocBlock comments |
||
23 | */ |
||
24 | public $removeDocBlocks = true; |
||
25 | |||
26 | /** |
||
27 | * @var bool Whether to remove "C style" comments |
||
28 | */ |
||
29 | public $removeMultiLineComments = true; |
||
30 | |||
31 | /** |
||
32 | * @var bool Whether to remove "one-line" comments |
||
33 | */ |
||
34 | public $removeSingleLineComments = true; |
||
35 | |||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | */ |
||
39 | 13 | protected function optimizeStream() |
|
51 | |||
52 | /** |
||
53 | * Generate a regexp that matches preserved annotations |
||
54 | * |
||
55 | * @return string |
||
56 | */ |
||
57 | 12 | protected function getRegexp() |
|
66 | |||
67 | /** |
||
68 | * Remove all docblocks tokens from given stream |
||
69 | * |
||
70 | * @return void |
||
71 | */ |
||
72 | 12 | protected function removeDocBlocks() |
|
87 | |||
88 | /** |
||
89 | * Remove current comment token from given stream |
||
90 | * |
||
91 | * @return void |
||
92 | */ |
||
93 | 8 | protected function removeComment() |
|
120 | |||
121 | /** |
||
122 | * Remove single-line and/or multi-line comments from given stream |
||
123 | * |
||
124 | * @return void |
||
125 | */ |
||
126 | 13 | protected function removeComments() |
|
144 | } |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()
method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail()
, this method _has_ side-effects. In the following case, we could not remove the method call: