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