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