Skip to content

Commit b5db7cd

Browse files
authored
Replace empty() by more strict checks (#1125)
* Replace empty() by stricter checks * Apply StyleCI fixes * Compare with empty string instead of checking length * Compare with empty array instead of checking count * Compare with empty string instead of checking length
1 parent c4a1190 commit b5db7cd

File tree

8 files changed

+14
-14
lines changed

8 files changed

+14
-14
lines changed

Dumper/AbstractArrayDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected function getArray(Location $location): array
3636
$properties['bounds']
3737
);
3838

39-
if (0 === count($properties)) {
39+
if ([] === $properties) {
4040
$properties = null;
4141
}
4242

Model/Address.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,12 @@ public static function createFromArray(array $data)
235235

236236
$adminLevels = [];
237237
foreach ($data['adminLevels'] as $adminLevel) {
238-
if (empty($adminLevel['level'])) {
238+
if (null === $adminLevel['level'] || 0 === $adminLevel['level']) {
239239
continue;
240240
}
241241

242242
$name = $adminLevel['name'] ?? $adminLevel['code'] ?? null;
243-
if (empty($name)) {
243+
if (null === $name || '' === $name) {
244244
continue;
245245
}
246246

Model/AddressBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function build(string $class = Address::class): Address
109109
}
110110

111111
$country = null;
112-
if (!empty($this->country) || !empty($this->countryCode)) {
112+
if ((null !== $this->country && '' !== $this->country) || (null !== $this->countryCode && '' !== $this->countryCode)) {
113113
$country = new Country($this->country, $this->countryCode);
114114
}
115115

Model/AddressCollection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function count()
5353
*/
5454
public function first(): Location
5555
{
56-
if (empty($this->locations)) {
56+
if ([] === $this->locations) {
5757
throw new CollectionIsEmpty();
5858
}
5959

@@ -65,7 +65,7 @@ public function first(): Location
6565
*/
6666
public function isEmpty(): bool
6767
{
68-
return empty($this->locations);
68+
return [] === $this->locations;
6969
}
7070

7171
/**

Model/AdminLevelCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function count()
7373
*/
7474
public function first(): AdminLevel
7575
{
76-
if (empty($this->adminLevels)) {
76+
if ([] === $this->adminLevels) {
7777
throw new CollectionIsEmpty();
7878
}
7979

ProviderAggregator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ private static function getProvider($query, array $providers, Provider $currentP
180180
return $currentProvider;
181181
}
182182

183-
if (0 === count($providers)) {
183+
if ([] === $providers) {
184184
throw ProviderNotRegistered::noProviderRegistered();
185185
}
186186

Query/GeocodeQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ final class GeocodeQuery implements Query
5353
*/
5454
private function __construct(string $text)
5555
{
56-
if (empty($text)) {
56+
if ('' === $text) {
5757
throw new InvalidArgument('Geocode query cannot be empty');
5858
}
5959

StatefulGeocoder.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
final class StatefulGeocoder implements Geocoder
2424
{
2525
/**
26-
* @var string
26+
* @var string|null
2727
*/
2828
private $locale;
2929

@@ -61,7 +61,7 @@ public function geocode(string $value): Collection
6161
$query = GeocodeQuery::create($value)
6262
->withLimit($this->limit);
6363

64-
if (!empty($this->locale)) {
64+
if (null !== $this->locale && '' !== $this->locale) {
6565
$query = $query->withLocale($this->locale);
6666
}
6767

@@ -80,7 +80,7 @@ public function reverse(float $latitude, float $longitude): Collection
8080
$query = ReverseQuery::fromCoordinates($latitude, $longitude)
8181
->withLimit($this->limit);
8282

83-
if (!empty($this->locale)) {
83+
if (null !== $this->locale && '' !== $this->locale) {
8484
$query = $query->withLocale($this->locale);
8585
}
8686

@@ -93,7 +93,7 @@ public function reverse(float $latitude, float $longitude): Collection
9393
public function geocodeQuery(GeocodeQuery $query): Collection
9494
{
9595
$locale = $query->getLocale();
96-
if (empty($locale) && null !== $this->locale) {
96+
if ((null === $locale || '' === $locale) && null !== $this->locale) {
9797
$query = $query->withLocale($this->locale);
9898
}
9999

@@ -111,7 +111,7 @@ public function geocodeQuery(GeocodeQuery $query): Collection
111111
public function reverseQuery(ReverseQuery $query): Collection
112112
{
113113
$locale = $query->getLocale();
114-
if (empty($locale) && null !== $this->locale) {
114+
if ((null === $locale || '' === $locale) && null !== $this->locale) {
115115
$query = $query->withLocale($this->locale);
116116
}
117117

0 commit comments

Comments
 (0)