| Conditions | 21 |
| Paths | 2160 |
| Total Lines | 92 |
| Code Lines | 57 |
| 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 |
||
| 106 | protected function writeGeometry(Geometry $geometry): string |
||
| 107 | { |
||
| 108 | $this->writeOptions['hasZ'] = $geometry->hasZ(); |
||
| 109 | $this->writeOptions['hasM'] = $geometry->isMeasured(); |
||
| 110 | |||
| 111 | // Type and precision |
||
| 112 | $type = self::$typeMap[$geometry->geometryType()] + |
||
| 113 | (BinaryWriter::zigZagEncode($this->writeOptions['decimalDigitsXY']) << 4); |
||
| 114 | $twkbHead = $this->writer->writeUInt8($type); |
||
| 115 | |||
| 116 | // Is there extended precision information? |
||
| 117 | $metadataHeader = $this->writeOptions['includeBoundingBoxes'] << 0; |
||
| 118 | // Is there extended precision information? |
||
| 119 | $metadataHeader += $this->writeOptions['includeSize'] << 1; |
||
| 120 | // Is there an ID list? |
||
| 121 | // TODO: implement this (needs metadata support in geoPHP) |
||
| 122 | //$metadataHeader += $this->writeOptions['hasIdList'] << 2; |
||
| 123 | // Is there extended precision information? |
||
| 124 | $metadataHeader += ($geometry->hasZ() || $geometry->isMeasured()) << 3; |
||
| 125 | // Is this an empty geometry? |
||
| 126 | $metadataHeader += $geometry->isEmpty() << 4; |
||
| 127 | |||
| 128 | $twkbHead .= $this->writer->writeUInt8($metadataHeader); |
||
| 129 | |||
| 130 | $twkbGeom = ''; |
||
| 131 | if (!$geometry->isEmpty()) { |
||
| 132 | $this->lastPoint = new Point(0, 0, 0, 0); |
||
| 133 | |||
| 134 | switch ($geometry->geometryType()) { |
||
| 135 | case Geometry::POINT: |
||
| 136 | /** @var Point $geometry */ |
||
| 137 | $twkbGeom .= $this->writePoint($geometry); |
||
| 138 | break; |
||
| 139 | case Geometry::LINESTRING: |
||
| 140 | /** @var LineString $geometry */ |
||
| 141 | $twkbGeom .= $this->writeLineString($geometry); |
||
| 142 | break; |
||
| 143 | case Geometry::POLYGON: |
||
| 144 | /** @var Polygon $geometry */ |
||
| 145 | $twkbGeom .= $this->writePolygon($geometry); |
||
| 146 | break; |
||
| 147 | case Geometry::MULTI_POINT: |
||
| 148 | case Geometry::MULTI_LINESTRING: |
||
| 149 | case Geometry::MULTI_POLYGON: |
||
| 150 | case Geometry::GEOMETRY_COLLECTION: |
||
| 151 | /** @var Collection $geometry */ |
||
| 152 | $twkbGeom .= $this->writeMulti($geometry); |
||
| 153 | break; |
||
| 154 | } |
||
| 155 | } |
||
| 156 | |||
| 157 | if ($this->writeOptions['includeBoundingBoxes']) { |
||
| 158 | $bBox = $geometry->getBoundingBox(); |
||
| 159 | |||
| 160 | if (!empty($bBox)) { |
||
| 161 | // X |
||
| 162 | $twkbBox = $this->writer->writeSVarInt($bBox['minx'] * $this->writeOptions['xyFactor']); |
||
| 163 | $twkbBox .= $this->writer->writeSVarInt(($bBox['maxx'] - $bBox['minx']) * $this->writeOptions['xyFactor']); |
||
| 164 | // Y |
||
| 165 | $twkbBox .= $this->writer->writeSVarInt($bBox['miny'] * $this->writeOptions['xyFactor']); |
||
| 166 | $twkbBox .= $this->writer->writeSVarInt(($bBox['maxy'] - $bBox['miny']) * $this->writeOptions['xyFactor']); |
||
| 167 | if ($geometry->hasZ()) { |
||
| 168 | $bBox['minz'] = $geometry->minimumZ(); |
||
| 169 | $bBox['maxz'] = $geometry->maximumZ(); |
||
| 170 | $twkbBox .= $this->writer->writeSVarInt(round($bBox['minz'] * $this->writeOptions['zFactor'])); |
||
| 171 | $twkbBox .= $this->writer->writeSVarInt(round(($bBox['maxz'] - $bBox['minz']) * $this->writeOptions['zFactor'])); |
||
| 172 | } |
||
| 173 | if ($geometry->isMeasured()) { |
||
| 174 | $bBox['minm'] = $geometry->minimumM(); |
||
| 175 | $bBox['maxm'] = $geometry->maximumM(); |
||
| 176 | $twkbBox .= $this->writer->writeSVarInt($bBox['minm'] * $this->writeOptions['mFactor']); |
||
| 177 | $twkbBox .= $this->writer->writeSVarInt(($bBox['maxm'] - $bBox['minm']) * $this->writeOptions['mFactor']); |
||
| 178 | } |
||
| 179 | $twkbGeom = $twkbBox . $twkbGeom; |
||
| 180 | } |
||
| 181 | } |
||
| 182 | |||
| 183 | if ($geometry->hasZ() || $geometry->isMeasured()) { |
||
| 184 | $extendedPrecision = 0; |
||
| 185 | if ($geometry->hasZ()) { |
||
| 186 | $extendedPrecision |= ($geometry->hasZ() ? 0x1 : 0) | ($this->writeOptions['decimalDigitsZ'] << 2); |
||
| 187 | } |
||
| 188 | if ($geometry->isMeasured()) { |
||
| 189 | $extendedPrecision |= ($geometry->isMeasured() ? 0x2 : 0) | ($this->writeOptions['decimalDigitsM'] << 5); |
||
| 190 | } |
||
| 191 | $twkbHead .= $this->writer->writeUInt8($extendedPrecision); |
||
| 192 | } |
||
| 193 | if ($this->writeOptions['includeSize']) { |
||
| 194 | $twkbHead .= $this->writer->writeUVarInt(strlen($twkbGeom)); |
||
| 195 | } |
||
| 196 | |||
| 197 | return $twkbHead . $twkbGeom; |
||
| 198 | } |
||
| 281 |