Conditions | 23 |
Paths | 81 |
Total Lines | 83 |
Code Lines | 41 |
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 |
||
144 | public function findPhpExe() |
||
145 | { |
||
146 | $php = getenv('PHP_BINARY'); |
||
147 | |||
148 | if (!empty($php)) { |
||
149 | |||
150 | if (is_executable($php)) { |
||
151 | return $php; |
||
152 | } |
||
153 | |||
154 | throw new RuntimeException('PHP_BINARY is not executable'); |
||
155 | } |
||
156 | |||
157 | $php = getenv('PHP_PATH'); |
||
158 | |||
159 | if (!empty($php)) { |
||
160 | |||
161 | if (is_executable($php)) { |
||
162 | return $php; |
||
163 | } |
||
164 | |||
165 | throw new RuntimeException('PHP_PATH is not executable'); |
||
166 | } |
||
167 | |||
168 | $php = getenv('PHP_PEAR_PHP_BIN'); |
||
169 | |||
170 | if (!empty($php) && is_executable($php)) { |
||
171 | return $php; |
||
172 | } |
||
173 | |||
174 | $php = PHP_BINDIR . (DIRECTORY_SEPARATOR === '\\' ? '\\php.exe' : '/php'); |
||
175 | |||
176 | if (is_executable($php)) { |
||
177 | return $php; |
||
178 | } |
||
179 | |||
180 | if (ini_get('open_basedir')) { |
||
181 | |||
182 | $dirs = array(); |
||
183 | foreach (explode(PATH_SEPARATOR, ini_get('open_basedir')) as $path) { |
||
184 | |||
185 | // Silencing against https://bugs.php.net/69240 |
||
186 | if (@is_dir($path)) { |
||
187 | $dirs[] = $path; |
||
188 | continue; |
||
189 | } |
||
190 | |||
191 | if (basename($path) === 'php' && @is_executable($path)) { |
||
192 | return $path; |
||
193 | } |
||
194 | } |
||
195 | |||
196 | } else { |
||
197 | |||
198 | $dirs = array(PHP_BINDIR); |
||
199 | |||
200 | if (DIRECTORY_SEPARATOR === '\\') { |
||
201 | $dirs[] = 'C:\xampp\php\\'; |
||
202 | } |
||
203 | |||
204 | $dirs = array_merge(explode(PATH_SEPARATOR, getenv('PATH') ?: getenv('Path')), $dirs); |
||
205 | } |
||
206 | |||
207 | $suffixes = array(''); |
||
208 | |||
209 | if (DIRECTORY_SEPARATOR === '\\') { |
||
210 | $path_ext = getenv('PATHEXT'); |
||
211 | if (!empty($path_ext)) { |
||
212 | $suffixes = array_merge($suffixes, explode(PATH_SEPARATOR, $path_ext)); |
||
213 | } |
||
214 | } |
||
215 | |||
216 | foreach ($suffixes as $suffix) { |
||
217 | foreach ($dirs as $dir) { |
||
218 | $file = $dir . DIRECTORY_SEPARATOR . "php$suffix"; |
||
219 | if (@is_file($file) && (DIRECTORY_SEPARATOR === '\\' || is_executable($file))) { |
||
220 | return $file; |
||
221 | } |
||
222 | } |
||
223 | } |
||
224 | |||
225 | throw new RuntimeException('Cannot find PHP executable file'); |
||
226 | } |
||
227 | |||
283 |