From 58448bc9b81b3f8b365ace7282feea72fe9cd879 Mon Sep 17 00:00:00 2001 From: Marc Morera Date: Sun, 20 Sep 2020 12:17:50 +0200 Subject: [PATCH] Coordinate can have strings as values - Added .gitattributes with export-ignore values - Fixed code --- .gitattributes | 8 ++++++++ Exception/TooManyRequestsException.php | 4 ++-- Http/HttpResponsesToException.php | 4 ++-- Model/Coordinate.php | 4 ++-- Tests/Model/CoordinateTest.php | 19 +++++++++++++++++++ 5 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..744fe58 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,8 @@ +/.gitattributes export-ignore +/.gitignore export-ignore +/Tests export-ignore +/phpunit.xml export-ignore +/.php_cs export-ignore +/.formatter.yml export-ignore +/.circleci export-ignore +/.editorconfig export-ignore \ No newline at end of file diff --git a/Exception/TooManyRequestsException.php b/Exception/TooManyRequestsException.php index 0d651f9..6035ef7 100644 --- a/Exception/TooManyRequestsException.php +++ b/Exception/TooManyRequestsException.php @@ -16,7 +16,7 @@ namespace Apisearch\Exception; /** - * Class TooManyRequestsException + * Class TooManyRequestsException. */ class TooManyRequestsException extends TransportableException { @@ -39,4 +39,4 @@ public static function tooManyRequestsReached(): self { return new self('You reached the rate limit. Please, check your permissions'); } -} \ No newline at end of file +} diff --git a/Http/HttpResponsesToException.php b/Http/HttpResponsesToException.php index a2b103d..fe57a20 100644 --- a/Http/HttpResponsesToException.php +++ b/Http/HttpResponsesToException.php @@ -58,10 +58,10 @@ protected static function throwTransportableExceptionIfNeeded( throw new ResourceExistsException($response['body']['message']); case ForbiddenException::getTransportableHTTPError(): throw new ForbiddenException($response['body']['message']); - case TooManyRequestsException::getTransportableHTTPError(); + case TooManyRequestsException::getTransportableHTTPError(): throw new TooManyRequestsException($response['body']['message']); case ConnectionException::getTransportableHTTPError(): - throw new ConnectionException('Apisearch returned an internal error code [500] - ' . $response['body']['message']); + throw new ConnectionException('Apisearch returned an internal error code [500] - '.$response['body']['message']); } } } diff --git a/Model/Coordinate.php b/Model/Coordinate.php index 948fad5..49643f3 100644 --- a/Model/Coordinate.php +++ b/Model/Coordinate.php @@ -100,8 +100,8 @@ public static function createFromArray(array $array): self } return new self( - $array['lat'], - $array['lon'] + \floatval($array['lat']), + \floatval($array['lon']) ); } } diff --git a/Tests/Model/CoordinateTest.php b/Tests/Model/CoordinateTest.php index a7f60e2..2710e2d 100644 --- a/Tests/Model/CoordinateTest.php +++ b/Tests/Model/CoordinateTest.php @@ -120,4 +120,23 @@ public function testToArray() $coordinate->toArray() ); } + + /** + * Test string values. + */ + public function testAsString() + { + $coordinateAsArray = [ + 'lat' => '1.20', + 'lon' => '2.10', + ]; + $coordinate = Coordinate::createFromArray($coordinateAsArray); + $this->assertEquals( + [ + 'lat' => 1.20, + 'lon' => 2.10, + ], + $coordinate->toArray() + ); + } }