Skip to content

Commit

Permalink
Merge pull request #6 from karam-mustafa/v2.0.1
Browse files Browse the repository at this point in the history
fix resolve unit no if options inserted.
  • Loading branch information
karam-mustafa authored Dec 17, 2021
2 parents d72303e + d736216 commit 547f095
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v2.0.1
--------
* fix if there are no options inserted.

v2.0.0
--------
* Refactor class names.
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/DataStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ trait DataStorage
*
* @var array
*/
private $options;
private $options = [];

/**
* get the available units.
Expand Down
50 changes: 29 additions & 21 deletions src/Traits/Distances.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function getSin()
}

/**
* @param float|int $sin
* @param float|int $sin
*
* @return Distances
*
Expand Down Expand Up @@ -91,7 +91,7 @@ public function setLongitude($val)
}

/**
* @param float|int $cos
* @param float|int $cos
*
* @return Distances
*
Expand All @@ -117,10 +117,10 @@ public function __construct()
/**
* Finding the distance of points using several given coordinate points.
*
* @throws Exception
*
* @return array
*
* @throws Exception
*
* @author karam mustafa
* @author karam mustafa
*/
Expand Down Expand Up @@ -154,9 +154,9 @@ public function getDistance()
/**
* get the sin or cos values multiply.
*
* @param int $firstLat
* @param int $secondLat
* @param string $angle
* @param int $firstLat
* @param int $secondLat
* @param string $angle
*
* @return float
*
Expand Down Expand Up @@ -184,10 +184,10 @@ private function getValueForAngleBetween()
/**
* calculation distance process.
*
* @throws Exception
*
* @return array
*
* @throws Exception
*
* @author karam mustafa
*/
private function calcDistance()
Expand Down Expand Up @@ -221,23 +221,31 @@ private function correctDistanceValue($distance)
/**
* check if user chose any units.
*
* @param float $distance
*
* @throws Exception
* @param float $distance
*
* @return array
*
* @throws Exception
*
* @author karam mustafa
*/
private function resolveDistanceWithUnits($distance)
{
// loop in each unit and solve the distance.
foreach ($this->getOptions()['units'] as $unit) {
// check if the unit isset.
$this->checkIfUnitExists($unit)
// set the result in storage.
->setInStorage($unit, $distance * $this->getUnits()[$unit]);
if (isset($this->getOptions()['units']) &&
sizeof($this->getOptions('units')) > 0
) {
// loop in each unit and solve the distance.
foreach ($this->getOptions()['units'] as $unit) {
// check if the unit isset.
$this->checkIfUnitExists($unit)
// set the result in storage.
->setInStorage($unit, $distance * $this->getUnits()[$unit]);
}
} else {
// if there are not units, then get the default units property.
$this->setInStorage('mile', $distance * $this->getUnits()['mile']);
}

// remove un required results and get the results from storage.
return $this
->removeFromStorage('position', 'distance_key')
Expand All @@ -260,12 +268,12 @@ private function resolveUnits()
/**
* check if current units its available in units property or config file.
*
* @param string $unit
*
* @throws \Exception
* @param string $unit
*
* @return Distances
*
* @throws \Exception
*
* @author karam mustafa
*/
private function checkIfUnitExists($unit)
Expand Down

0 comments on commit 547f095

Please sign in to comment.