From 5166eee88cb7afa00ea37fadff1365d91683643f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 24 Apr 2024 20:29:37 +0200 Subject: [PATCH] Clean code --- dev/tools/phan/config_extended.php | 4 ++- htdocs/core/class/dolgeophp.class.php | 37 ++++++++++++++++++--------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/dev/tools/phan/config_extended.php b/dev/tools/phan/config_extended.php index 259eab8e160..4d828556aea 100644 --- a/dev/tools/phan/config_extended.php +++ b/dev/tools/phan/config_extended.php @@ -85,6 +85,8 @@ $config['suppress_issue_types'] = [ 'PhanPluginDuplicateConditionalNullCoalescing', // Not essential - 990+ occurrences 'PhanPluginRedundantAssignmentInGlobalScope', // Not essential, a lot of false warning 'PhanPluginDuplicateCatchStatementBody', // Requires PHP7.1 - 50+ occurrences - ]; + + 'PhanPluginUnknownObjectMethodCall', // False positive for some class +]; return $config; diff --git a/htdocs/core/class/dolgeophp.class.php b/htdocs/core/class/dolgeophp.class.php index 9c54eb4f7cc..a123dab53d5 100644 --- a/htdocs/core/class/dolgeophp.class.php +++ b/htdocs/core/class/dolgeophp.class.php @@ -54,11 +54,15 @@ class DolGeoPHP public function parseGeoString($value) { $geom = geoPHP::load($value, 'wkt'); - $geojson = $geom->out('json'); - $centroid = $geom->getCentroid(); - $centroidjson = $centroid->out('json'); + if ($geom) { + $geojson = $geom->out('json'); + $centroid = $geom->getCentroid(); + $centroidjson = $centroid->out('json'); - return array('geojson' => $geojson, 'centroid' => $centroid, 'centroidjson' => $centroidjson); + return array('geojson' => $geojson, 'centroid' => $centroid, 'centroidjson' => $centroidjson); + } else { + return array(); + } } /** @@ -69,9 +73,12 @@ class DolGeoPHP */ public function getXYString($value) { - $geom = geoPHP::load($value, 'wkt'); - $value = $geom->x().' '.$geom->y(); + $value = ''; + $geom = geoPHP::load($value, 'wkt'); + if ($geom) { + $value = $geom->x().' '.$geom->y(); + } return $value; } @@ -79,13 +86,16 @@ class DolGeoPHP * Return a string with x and y * * @param mixed $value Value - * @return string X space Y + * @return string Class : num points */ public function getPointString($value) { - $geom = geoPHP::load($value, 'wkt'); - $value = get_class($geom) . ' : '. $geom->numPoints() . ' Points'; + $value = ''; + $geom = geoPHP::load($value, 'wkt'); + if ($geom) { + $value = get_class($geom) . ' : '. $geom->numPoints() . ' Points'; + } return $value; } @@ -93,13 +103,16 @@ class DolGeoPHP * Return wkt * * @param string $geojson A json string - * @return string X space Y + * @return mixed Value key */ public function getWkt($geojson) { - $geom = geoPHP::load($geojson, 'json'); - $value_key = $geom->out('wkt'); + $value_key = ''; + $geom = geoPHP::load($geojson, 'json'); + if ($geom) { + $value_key = $geom->out('wkt'); + } return $value_key; } }