Skip to content

Commit 370af74

Browse files
authored
Merge pull request #124 from apisearch-io/feature/coordinate-can-have-strings
Coordinate can have strings as values
2 parents 610987f + 58448bc commit 370af74

File tree

5 files changed

+33
-6
lines changed

5 files changed

+33
-6
lines changed

.gitattributes

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/.gitattributes export-ignore
2+
/.gitignore export-ignore
3+
/Tests export-ignore
4+
/phpunit.xml export-ignore
5+
/.php_cs export-ignore
6+
/.formatter.yml export-ignore
7+
/.circleci export-ignore
8+
/.editorconfig export-ignore

Exception/TooManyRequestsException.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
namespace Apisearch\Exception;
1717

1818
/**
19-
* Class TooManyRequestsException
19+
* Class TooManyRequestsException.
2020
*/
2121
class TooManyRequestsException extends TransportableException
2222
{
@@ -39,4 +39,4 @@ public static function tooManyRequestsReached(): self
3939
{
4040
return new self('You reached the rate limit. Please, check your permissions');
4141
}
42-
}
42+
}

Http/HttpResponsesToException.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ protected static function throwTransportableExceptionIfNeeded(
5858
throw new ResourceExistsException($response['body']['message']);
5959
case ForbiddenException::getTransportableHTTPError():
6060
throw new ForbiddenException($response['body']['message']);
61-
case TooManyRequestsException::getTransportableHTTPError();
61+
case TooManyRequestsException::getTransportableHTTPError():
6262
throw new TooManyRequestsException($response['body']['message']);
6363
case ConnectionException::getTransportableHTTPError():
64-
throw new ConnectionException('Apisearch returned an internal error code [500] - ' . $response['body']['message']);
64+
throw new ConnectionException('Apisearch returned an internal error code [500] - '.$response['body']['message']);
6565
}
6666
}
6767
}

Model/Coordinate.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ public static function createFromArray(array $array): self
100100
}
101101

102102
return new self(
103-
$array['lat'],
104-
$array['lon']
103+
\floatval($array['lat']),
104+
\floatval($array['lon'])
105105
);
106106
}
107107
}

Tests/Model/CoordinateTest.php

+19
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,23 @@ public function testToArray()
120120
$coordinate->toArray()
121121
);
122122
}
123+
124+
/**
125+
* Test string values.
126+
*/
127+
public function testAsString()
128+
{
129+
$coordinateAsArray = [
130+
'lat' => '1.20',
131+
'lon' => '2.10',
132+
];
133+
$coordinate = Coordinate::createFromArray($coordinateAsArray);
134+
$this->assertEquals(
135+
[
136+
'lat' => 1.20,
137+
'lon' => 2.10,
138+
],
139+
$coordinate->toArray()
140+
);
141+
}
123142
}

0 commit comments

Comments
 (0)