Conditions | 6 |
Paths | 18 |
Total Lines | 56 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
95 | private function initMntOrTac(): void |
||
96 | { |
||
97 | $fixedHeaderRegexp = '^(-?[\d.]+) (-?[\d.]+) (-?[\d.]+) (-?[\d.]+) ([\d.]+) ([\d.]+) ([1-4]) ([01]) (\d) ([01]) '; |
||
98 | $header = $this->gridFile->fgets(); |
||
99 | |||
100 | preg_match('/' . $fixedHeaderRegexp . '/', $header, $fixedHeaderParts); |
||
101 | |||
102 | $this->startX = min((float) $fixedHeaderParts[1], (float) $fixedHeaderParts[2]); |
||
103 | $this->endX = max((float) $fixedHeaderParts[1], (float) $fixedHeaderParts[2]); |
||
104 | $this->startY = min((float) $fixedHeaderParts[3], (float) $fixedHeaderParts[4]); |
||
105 | $this->endY = max((float) $fixedHeaderParts[3], (float) $fixedHeaderParts[4]); |
||
106 | $this->columnGridInterval = (float) $fixedHeaderParts[5]; |
||
107 | $this->rowGridInterval = (float) $fixedHeaderParts[6]; |
||
108 | $this->numberOfColumns = (int) (string) (($this->endX - $this->startX) / $this->columnGridInterval) + 1; |
||
109 | $this->numberOfRows = (int) (string) (($this->endY - $this->startY) / $this->rowGridInterval) + 1; |
||
110 | $this->storageOrder = (int) $fixedHeaderParts[7]; |
||
111 | $coordinatesIncludedInData = (bool) $fixedHeaderParts[8]; |
||
112 | $this->valuesPerCoordinate = (int) $fixedHeaderParts[9]; |
||
113 | $precisionIncluded = (bool) $fixedHeaderParts[10]; |
||
114 | |||
115 | preg_match('/' . $fixedHeaderRegexp . str_repeat('(-?[\d.]+) ', $this->valuesPerCoordinate) . '(.*)$/', $header, $fullHeaderParts); |
||
116 | |||
117 | $baseAdjustments = array_slice($fullHeaderParts, count($fullHeaderParts) - $this->valuesPerCoordinate - 1, $this->valuesPerCoordinate); |
||
118 | foreach ($baseAdjustments as $baseAdjustment) { |
||
119 | assert((float) $baseAdjustment === 0.0); |
||
120 | } |
||
121 | |||
122 | // these files are not always 1 record per line (sometimes blank lines, sometimes multiple records per row) |
||
123 | // so direct file access is not possible. Read into memory instead :/ |
||
124 | |||
125 | $this->data = new SplFixedArray($this->numberOfColumns * $this->numberOfRows); |
||
126 | |||
127 | $rawData = $this->gridFile->fread($this->gridFile->getSize() - strlen($header)); |
||
128 | $values = explode(' ', trim(preg_replace('/\s+/', ' ', $rawData))); |
||
129 | |||
130 | $cursor = 0; |
||
131 | for ($i = 0, $numValues = $this->numberOfColumns * $this->numberOfRows; $i < $numValues; ++$i) { |
||
132 | if ($coordinatesIncludedInData) { |
||
133 | $cursor += 2; |
||
134 | } |
||
135 | |||
136 | $rowData = []; |
||
137 | for ($j = 0; $j < $this->valuesPerCoordinate; ++$j) { |
||
138 | $rowData[] = (float) $values[$cursor]; |
||
139 | ++$cursor; |
||
140 | } |
||
141 | |||
142 | $this->data[$i] = $rowData; |
||
143 | |||
144 | if ($precisionIncluded) { |
||
145 | ++$cursor; |
||
146 | } |
||
147 | } |
||
148 | |||
149 | $this->gridFile->fgets(); |
||
150 | assert($this->gridFile->eof()); |
||
151 | } |
||
153 |