| Conditions | 15 |
| Paths | 4 |
| Total Lines | 54 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 88 | private function extractData(string $fileName): array |
||
| 89 | { |
||
| 90 | $stubContent = null; |
||
| 91 | $manifestContent = null; |
||
| 92 | $manifestLength = null; |
||
| 93 | |||
| 94 | $resource = fopen($fileName, 'r'); |
||
| 95 | if (!is_resource($resource)) { |
||
| 96 | throw new ReaderException( |
||
| 97 | sprintf('Resource %s could not be opened', $fileName), |
||
| 98 | 1547902055 |
||
| 99 | ); |
||
| 100 | } |
||
| 101 | |||
| 102 | while (!feof($resource)) { |
||
| 103 | $line = fgets($resource); |
||
| 104 | // stop processing in case the system fails to read from a stream |
||
| 105 | if ($line === false) { |
||
| 106 | break; |
||
| 107 | } |
||
| 108 | // stop reading file when manifest can be extracted |
||
| 109 | if ($manifestLength !== null && $manifestContent !== null && strlen($manifestContent) >= $manifestLength) { |
||
|
|
|||
| 110 | break; |
||
| 111 | } |
||
| 112 | |||
| 113 | $manifestPosition = strpos($line, '__HALT_COMPILER();'); |
||
| 114 | |||
| 115 | // first line contains start of manifest |
||
| 116 | if ($stubContent === null && $manifestContent === null && $manifestPosition !== false) { |
||
| 117 | $stubContent = substr($line, 0, $manifestPosition - 1); |
||
| 118 | $manifestContent = preg_replace('#^.*__HALT_COMPILER\(\);(?>[ \n]\?>(?>\r\n|\n)?)?#', '', $line); |
||
| 119 | $manifestLength = $this->resolveManifestLength($manifestContent); |
||
| 120 | // line contains start of stub |
||
| 121 | } elseif ($stubContent === null) { |
||
| 122 | $stubContent = $line; |
||
| 123 | // line contains start of manifest |
||
| 124 | } elseif ($manifestContent === null && $manifestPosition !== false) { |
||
| 125 | $manifestContent = preg_replace('#^.*__HALT_COMPILER\(\);(?>[ \n]\?>(?>\r\n|\n)?)?#', '', $line); |
||
| 126 | $manifestLength = $this->resolveManifestLength($manifestContent); |
||
| 127 | // manifest has been started (thus is cannot be stub anymore), add content |
||
| 128 | } elseif ($manifestContent !== null) { |
||
| 129 | $manifestContent .= $line; |
||
| 130 | $manifestLength = $this->resolveManifestLength($manifestContent); |
||
| 131 | // stub has been started (thus cannot be manifest here, yet), add content |
||
| 132 | } elseif ($stubContent !== null) { |
||
| 133 | $stubContent .= $line; |
||
| 134 | } |
||
| 135 | } |
||
| 136 | fclose($resource); |
||
| 137 | |||
| 138 | return [ |
||
| 139 | 'stubContent' => $stubContent, |
||
| 140 | 'manifestContent' => $manifestContent, |
||
| 141 | 'manifestLength' => $manifestLength, |
||
| 142 | ]; |
||
| 260 |