Conditions | 10 |
Paths | 200 |
Total Lines | 54 |
Code Lines | 28 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
118 | private static function generatePharConfigStmt( |
||
119 | ?string $alias = null, |
||
120 | ?string $index = null, |
||
121 | bool $intercept = false, |
||
122 | bool $checkRequirements = true, |
||
123 | ): string { |
||
124 | $previous = false; |
||
125 | $stub = []; |
||
126 | $aliasStmt = self::getAliasStmt($alias); |
||
127 | |||
128 | if (null !== $aliasStmt) { |
||
129 | $stub[] = $aliasStmt; |
||
130 | |||
131 | $previous = true; |
||
132 | } |
||
133 | |||
134 | if ($intercept) { |
||
135 | $stub[] = 'Phar::interceptFileFuncs();'; |
||
136 | |||
137 | $previous = true; |
||
138 | } |
||
139 | |||
140 | if (false !== $checkRequirements) { |
||
141 | if ($previous) { |
||
142 | $stub[] = ''; |
||
143 | } |
||
144 | |||
145 | $checkRequirementsFile = self::CHECK_FILE_NAME; |
||
146 | |||
147 | $stub[] = null === $alias |
||
148 | ? "require 'phar://' . __FILE__ . '/.box/{$checkRequirementsFile}';" |
||
149 | : "require 'phar://{$alias}/.box/{$checkRequirementsFile}';"; |
||
150 | |||
151 | $previous = true; |
||
152 | } |
||
153 | |||
154 | if (null !== $index) { |
||
155 | if ($previous) { |
||
156 | $stub[] = ''; |
||
157 | } |
||
158 | |||
159 | $indexPath = null === $alias |
||
160 | ? "'phar://' . __FILE__ . '/{$index}';" |
||
161 | : "'phar://{$alias}/{$index}';"; |
||
162 | |||
163 | $stub[] = "\$_SERVER['SCRIPT_FILENAME'] = {$indexPath}"; |
||
164 | $stub[] = "require {$indexPath}"; |
||
165 | } |
||
166 | |||
167 | if ([] === $stub) { |
||
168 | return "// No PHAR config\n"; |
||
169 | } |
||
170 | |||
171 | return implode("\n", $stub)."\n"; |
||
172 | } |
||
174 |