| Conditions | 16 |
| Paths | 3 |
| Total Lines | 52 |
| Code Lines | 34 |
| 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 |
||
| 83 | private function extractData(string $fileName): array |
||
| 84 | { |
||
| 85 | $stubContent = null; |
||
| 86 | $manifestContent = null; |
||
| 87 | $manifestLength = null; |
||
| 88 | |||
| 89 | $resource = fopen($fileName, 'r'); |
||
| 90 | if (!is_resource($resource)) { |
||
| 91 | throw new ReaderException( |
||
| 92 | sprintf('Resource %s could not be opened', $fileName), |
||
| 93 | 1547902055 |
||
| 94 | ); |
||
| 95 | } |
||
| 96 | |||
| 97 | while (!feof($resource)) { |
||
| 98 | $line = fgets($resource); |
||
| 99 | // stop reading file when manifest can be extracted |
||
| 100 | if ($manifestLength !== null && $manifestContent !== null && strlen($manifestContent) >= $manifestLength) { |
||
| 101 | break; |
||
| 102 | } |
||
| 103 | |||
| 104 | $stubPosition = strpos($line, '<?php'); |
||
| 105 | $manifestPosition = strpos($line, '__HALT_COMPILER()'); |
||
| 106 | |||
| 107 | // line contains both, start of (empty) stub and start of manifest |
||
| 108 | if ($stubContent === null && $stubPosition !== false |
||
| 109 | && $manifestContent === null && $manifestPosition !== false) { |
||
| 110 | $stubContent = substr($line, $stubPosition, $manifestPosition - $stubPosition - 1); |
||
| 111 | $manifestContent = preg_replace('#^.*__HALT_COMPILER\(\)[^>]*\?>(\r|\n)*#', '', $line); |
||
| 112 | $manifestLength = $this->resolveManifestLength($manifestContent); |
||
| 113 | // line contains start of stub |
||
| 114 | } elseif ($stubContent === null && $stubPosition !== false) { |
||
| 115 | $stubContent = substr($line, $stubPosition); |
||
| 116 | // line contains start of manifest |
||
| 117 | } elseif ($manifestContent === null && $manifestPosition !== false) { |
||
| 118 | $manifestContent = preg_replace('#^.*__HALT_COMPILER\(\)[^>]*\?>(\r|\n)*#', '', $line); |
||
| 119 | $manifestLength = $this->resolveManifestLength($manifestContent); |
||
| 120 | // manifest has been started (thus is cannot be stub anymore), add content |
||
| 121 | } elseif ($manifestContent !== null) { |
||
| 122 | $manifestContent .= $line; |
||
| 123 | $manifestLength = $this->resolveManifestLength($manifestContent); |
||
| 124 | // stub has been started (thus cannot be manifest here, yet), add content |
||
| 125 | } elseif ($stubContent !== null) { |
||
| 126 | $stubContent .= $line; |
||
| 127 | } |
||
| 128 | } |
||
| 129 | fclose($resource); |
||
| 130 | |||
| 131 | return [ |
||
| 132 | 'stubContent' => $stubContent, |
||
| 133 | 'manifestContent' => $manifestContent, |
||
| 134 | 'manifestLength' => $manifestLength, |
||
| 135 | ]; |
||
| 224 |