Conditions | 9 |
Paths | 48 |
Total Lines | 72 |
Code Lines | 49 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
71 | protected function execute(InputInterface $input, OutputInterface $output) |
||
72 | { |
||
73 | $output->writeln('Building parser lookup table...'); |
||
74 | $map = $this->buildMap($input, $output); |
||
75 | $uses = []; |
||
76 | |||
77 | $symbols = []; |
||
78 | $symbolsClass = $this->findSymbols($input); |
||
79 | if (isset($symbolsClass)) { |
||
80 | $output->writeln("Symbols: {$symbolsClass->getName()}"); |
||
81 | $uses[] = $symbolsClass->getName(); |
||
82 | $symbols = (array) array_flip($symbolsClass->getConstants()); |
||
83 | } |
||
84 | |||
85 | $tokens = []; |
||
86 | $tokensClass = $this->findTokens($input); |
||
87 | if (isset($tokensClass)) { |
||
88 | $output->writeln("Tokens: {$tokensClass->getName()}"); |
||
89 | $uses[] = $tokensClass->getName(); |
||
90 | $tokens = (array) array_flip($tokensClass->getConstants()); |
||
91 | } |
||
92 | |||
93 | $description = $this->findDescription($input); |
||
94 | $descriptionText = isset($description) |
||
95 | ? "{$description}\n * \n * " |
||
96 | : ''; |
||
97 | |||
98 | $nodes = []; |
||
99 | |||
100 | $fileDocText = <<<EOF |
||
101 | /** |
||
102 | * {$descriptionText}Auto-generated file, please don't edit manually. |
||
103 | * Generated by UniLex. |
||
104 | */ |
||
105 | EOF; |
||
106 | |||
107 | $declare = new Declare_([new DeclareDeclare('strict_types', $this->builder->val(1))]); |
||
108 | $declare->setDocComment(new Doc($fileDocText)); |
||
109 | $nodes[] = $declare; |
||
110 | |||
111 | sort($uses, SORT_STRING | SORT_ASC); |
||
112 | foreach ($uses as $index => $use) { |
||
113 | $nodes[] = $this->builder->use($use)->getNode(); |
||
114 | } |
||
115 | |||
116 | $items = []; |
||
117 | foreach ($map as $symbol => $productions) { |
||
118 | $productionItems = []; |
||
119 | foreach ($productions as $token => $production) { |
||
120 | $productionItems[] = new ArrayItem( |
||
121 | $this->builder->val($production), |
||
122 | isset($tokens[$token]) |
||
123 | ? $this->builder->classConstFetch($tokensClass->getShortName(), $tokens[$token]) |
||
124 | : $this->builder->val($token) |
||
125 | ); |
||
126 | } |
||
127 | $items[] = new ArrayItem( |
||
128 | new Array_($productionItems, ['kind' => Array_::KIND_SHORT]), |
||
129 | isset($symbols[$symbol]) |
||
130 | ? $this->builder->classConstFetch($symbolsClass->getShortName(), $symbols[$symbol]) |
||
131 | : $this->builder->val($symbol) |
||
132 | ); |
||
133 | } |
||
134 | |||
135 | $nodes[] = new Return_( |
||
136 | new Array_($items, ['kind' => Array_::KIND_SHORT]) |
||
137 | ); |
||
138 | |||
139 | $generatedCode = $this->printer->prettyPrintFile($nodes); |
||
140 | $this->buildTarget($input, $output, $generatedCode); |
||
141 | |||
142 | return 0; |
||
143 | } |
||
223 |