| Conditions | 8 |
| Paths | 22 |
| Total Lines | 26 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 16 |
| CRAP Score | 8.0877 |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | 1 | public static function import($class, $geoJson, $propertyMap = null, $geoProperty = null, $featureCallback = null) |
|
| 10 | { |
||
| 11 | 1 | $geoProperty = $geoProperty ?: GIS::of($class); |
|
| 12 | 1 | $features = (is_array($geoJson) ? $geoJson : json_decode($geoJson, true))['features']; |
|
| 13 | 1 | foreach ($features as $feature) { |
|
| 14 | 1 | if (is_callable($featureCallback)) { |
|
| 15 | $feature = $featureCallback($feature); |
||
| 16 | } |
||
| 17 | |||
| 18 | 1 | if ($feature['type'] != 'Feature') { |
|
| 19 | continue; |
||
| 20 | } |
||
| 21 | |||
| 22 | 1 | if ($propertyMap === null) { |
|
| 23 | 1 | $propertyMap = array_intersect(array_keys($class::config()->get('db')), array_keys($feature['properties'])); |
|
| 24 | 1 | $propertyMap = array_combine($propertyMap, $propertyMap); |
|
| 25 | } |
||
| 26 | |||
| 27 | 1 | $obj = $class::create(); |
|
| 28 | 1 | $array = $feature['geometry']; |
|
| 29 | 1 | $array['srid'] = 4326; |
|
| 30 | 1 | $obj->$geoProperty = (string)GIS::create($array); |
|
| 31 | 1 | foreach ($propertyMap as $doProperty => $jsonProperty) { |
|
| 32 | 1 | $obj->$doProperty = $feature['properties'][$jsonProperty]; |
|
| 33 | } |
||
| 34 | 1 | $obj->write(); |
|
| 35 | } |
||
| 38 |