Conditions | 14 |
Paths | 3 |
Total Lines | 50 |
Code Lines | 32 |
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 | $manifestPosition = strpos($line, '__HALT_COMPILER();'); |
||
105 | |||
106 | // first line contains start of manifest |
||
107 | if ($stubContent === null && $manifestContent === null && $manifestPosition !== false) { |
||
108 | $stubContent = substr($line, 0, $manifestPosition - 1); |
||
109 | $manifestContent = preg_replace('#^.*__HALT_COMPILER\(\);(?>[ \n]\?>(?>\r\n|\n)?)?#', '', $line); |
||
110 | $manifestLength = $this->resolveManifestLength($manifestContent); |
||
111 | // line contains start of stub |
||
112 | } elseif ($stubContent === null) { |
||
113 | $stubContent = $line; |
||
114 | // line contains start of manifest |
||
115 | } elseif ($manifestContent === null && $manifestPosition !== false) { |
||
116 | $manifestContent = preg_replace('#^.*__HALT_COMPILER\(\);(?>[ \n]\?>(?>\r\n|\n)?)?#', '', $line); |
||
117 | $manifestLength = $this->resolveManifestLength($manifestContent); |
||
118 | // manifest has been started (thus is cannot be stub anymore), add content |
||
119 | } elseif ($manifestContent !== null) { |
||
120 | $manifestContent .= $line; |
||
121 | $manifestLength = $this->resolveManifestLength($manifestContent); |
||
122 | // stub has been started (thus cannot be manifest here, yet), add content |
||
123 | } elseif ($stubContent !== null) { |
||
124 | $stubContent .= $line; |
||
125 | } |
||
126 | } |
||
127 | fclose($resource); |
||
128 | |||
129 | return [ |
||
130 | 'stubContent' => $stubContent, |
||
131 | 'manifestContent' => $manifestContent, |
||
132 | 'manifestLength' => $manifestLength, |
||
133 | ]; |
||
242 |