Conditions | 19 |
Paths | 4352 |
Total Lines | 88 |
Code Lines | 67 |
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 |
||
80 | protected function getGeometry(): Geometry |
||
81 | { |
||
82 | $options = []; |
||
83 | $type = $this->reader->readUInt8(); |
||
84 | $metadataHeader = $this->reader->readUInt8(); |
||
85 | |||
86 | $geometryType = $type & 0x0F; |
||
87 | $options['precision'] = BinaryReader::zigZagDecode($type >> 4); |
||
88 | $options['precisionFactor'] = pow(10, $options['precision']); |
||
89 | |||
90 | $options['hasBoundingBox'] = ($metadataHeader >> 0 & 1) == 1; |
||
91 | $options['hasSizeAttribute'] = ($metadataHeader >> 1 & 1) == 1; |
||
92 | $options['hasIdList'] = ($metadataHeader >> 2 & 1) == 1; |
||
93 | $options['hasExtendedPrecision'] = ($metadataHeader >> 3 & 1) == 1; |
||
94 | $options['isEmpty'] = ($metadataHeader >> 4 & 1) == 1; |
||
95 | $unused1 = ($metadataHeader >> 5 & 1) == 1; |
||
96 | $unused2 = ($metadataHeader >> 6 & 1) == 1; |
||
97 | $unused3 = ($metadataHeader >> 7 & 1) == 1; |
||
98 | |||
99 | if ($options['hasExtendedPrecision']) { |
||
100 | $extendedPrecision = $this->reader->readUInt8(); |
||
101 | |||
102 | $options['hasZ'] = ($extendedPrecision & 0x01) === 0x01; |
||
103 | $options['hasM'] = ($extendedPrecision & 0x02) === 0x02; |
||
104 | |||
105 | $options['zPrecision'] = ($extendedPrecision & 0x1C) >> 2; |
||
106 | $options['zPrecisionFactor'] = pow(10, $options['zPrecision']); |
||
107 | |||
108 | $options['mPrecision'] = ($extendedPrecision & 0xE0) >> 5; |
||
109 | $options['mPrecisionFactor'] = pow(10, $options['mPrecision']); |
||
110 | } else { |
||
111 | $options['hasZ'] = false; |
||
112 | $options['hasM'] = false; |
||
113 | $options['zPrecisionFactor'] = 0; |
||
114 | $options['mPrecisionFactor'] = 0; |
||
115 | } |
||
116 | if ($options['hasSizeAttribute']) { |
||
117 | $options['remainderSize'] = $this->reader->readUVarInt(); |
||
118 | } |
||
119 | if ($options['hasBoundingBox']) { |
||
120 | $dimension = 2 + ($options['hasZ'] ? 1 : 0) + ($options['hasM'] ? 1 : 0); |
||
121 | $precisions = [ |
||
122 | $options['precisionFactor'], |
||
123 | $options['precisionFactor'], |
||
124 | $options['hasZ'] ? $options['zPrecisionFactor'] : 0, |
||
125 | $options['hasM'] ? $options['mPrecisionFactor'] : 0 |
||
126 | ]; |
||
127 | |||
128 | $bBoxMin = $bBoxMax = []; |
||
129 | for ($i = 0; $i < $dimension; $i++) { |
||
130 | $bBoxMin[$i] = $this->reader->readUVarInt() / $precisions[$i]; |
||
131 | $bBoxMax[$i] = $this->reader->readUVarInt() / $precisions[$i] + $bBoxMin[$i]; |
||
132 | } |
||
133 | /** @noinspection PhpUndefinedVariableInspection (minimum 2 dimension) */ |
||
134 | $options['boundingBox'] = ['minXYZM' => $bBoxMin, 'maxXYZM' => $bBoxMax]; |
||
135 | } |
||
136 | |||
137 | if ($unused1) { |
||
138 | $this->reader->readUVarInt(); |
||
139 | } |
||
140 | if ($unused2) { |
||
141 | $this->reader->readUVarInt(); |
||
142 | } |
||
143 | if ($unused3) { |
||
144 | $this->reader->readUVarInt(); |
||
145 | } |
||
146 | |||
147 | $this->lastPoint = new Point(0, 0, 0, 0); |
||
148 | |||
149 | switch ($geometryType) { |
||
150 | case 1: |
||
151 | return $this->getPoint($options); |
||
152 | case 2: |
||
153 | return $this->getLineString($options); |
||
154 | case 3: |
||
155 | return $this->getPolygon($options); |
||
156 | case 4: |
||
157 | return $this->getMulti('Point', $options); |
||
158 | case 5: |
||
159 | return $this->getMulti('LineString', $options); |
||
160 | case 6: |
||
161 | return $this->getMulti('Polygon', $options); |
||
162 | case 7: |
||
163 | return $this->getMulti('Geometry', $options); |
||
164 | default: |
||
165 | throw new \Exception( |
||
166 | 'Geometry type ' . $geometryType . |
||
167 | ' (' . (self::$typeMap[$geometryType] ?? 'unknown') . ') not supported' |
||
168 | ); |
||
286 |