Skip to content
This repository has been archived by the owner on Nov 4, 2019. It is now read-only.

Commit

Permalink
fix cs
Browse files Browse the repository at this point in the history
  • Loading branch information
willdurand committed Feb 2, 2014
1 parent 60750a8 commit 09e2039
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
68 changes: 34 additions & 34 deletions src/templates/queryWithDistance.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@

/**
* Adds distance from a given origin column to query.
*
* @param double $latitude The latitude of the origin point.
* @param double $longitude The longitude of the origin point.
* @param double $unit The unit measure.
*
* @return <?php echo $queryClassName ?> The current query, for fluid interface
*/
public function withDistance($latitude, $longitude, $unit = <?php echo $defaultUnit ?>)
{
if (<?php echo $peerClassName ?>::MILES_UNIT === $unit) {
$earthRadius = 3959;
} elseif (<?php echo $peerClassName ?>::NAUTICAL_MILES_UNIT === $unit) {
$earthRadius = 3440;
} else {
$earthRadius = 6371;
}

$sql = 'ABS(%s * ACOS(%s * COS(RADIANS(%s)) * COS(RADIANS(%s) - %s) + %s * SIN(RADIANS(%s))))';
$preparedSql = sprintf($sql,
$earthRadius,
cos(deg2rad($latitude)),
$this->getAliasedColName(<?php echo $latitudeColumnConstant ?>),
$this->getAliasedColName(<?php echo $longitudeColumnConstant ?>),
deg2rad($longitude),
sin(deg2rad($latitude)),
$this->getAliasedColName(<?php echo $latitudeColumnConstant ?>)
);

return $this
->withColumn($preparedSql, 'Distance');
}

/**
* Adds distance from a given origin column to query.
*
* @param double $latitude The latitude of the origin point.
* @param double $longitude The longitude of the origin point.
* @param double $unit The unit measure.
*
* @return <?php echo $queryClassName ?> The current query, for fluid interface
*/
public function withDistance($latitude, $longitude, $unit = <?php echo $defaultUnit ?>)
{
if (<?php echo $peerClassName ?>::MILES_UNIT === $unit) {
$earthRadius = 3959;
} elseif (<?php echo $peerClassName ?>::NAUTICAL_MILES_UNIT === $unit) {
$earthRadius = 3440;
} else {
$earthRadius = 6371;
}

$sql = 'ABS(%s * ACOS(%s * COS(RADIANS(%s)) * COS(RADIANS(%s) - %s) + %s * SIN(RADIANS(%s))))';
$preparedSql = sprintf($sql,
$earthRadius,
cos(deg2rad($latitude)),
$this->getAliasedColName(<?php echo $latitudeColumnConstant ?>),
$this->getAliasedColName(<?php echo $longitudeColumnConstant ?>),
deg2rad($longitude),
sin(deg2rad($latitude)),
$this->getAliasedColName(<?php echo $latitudeColumnConstant ?>)
);

return $this
->withColumn($preparedSql, 'Distance');
}
2 changes: 1 addition & 1 deletion tests/GeocodableBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public function testWithDistanceAddsColumn()
->filterByName('Lyon Area')
->findOne()
;
$this->assertTrue((float)$object->getDistance() > 0);
$this->assertTrue((float) $object->getDistance() > 0);
}

public function testFilterByDistanceFromReturnsNoObjects()
Expand Down

0 comments on commit 09e2039

Please sign in to comment.