Skip to content

Commit

Permalink
Merge pull request #66 from acelaya-forks/feature/location-default-pa…
Browse files Browse the repository at this point in the history
…rams

Add default values to Location constructor params
  • Loading branch information
acelaya authored Nov 11, 2024
2 parents 6c791b0 + e864db7 commit fadae5d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this

### Changed
* Update shlinkio coding standard to v2.4
* Add default values to `Location` constructor params, making it easier to handle with named parameters.

### Deprecated
* *Nothing*
Expand Down
24 changes: 15 additions & 9 deletions src/Model/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,27 @@

namespace Shlinkio\Shlink\IpGeolocation\Model;

final class Location
final readonly class Location
{
public function __construct(
public readonly string $countryCode,
public readonly string $countryName,
public readonly string $regionName,
public readonly string $city,
public readonly float $latitude,
public readonly float $longitude,
public readonly string $timeZone,
public string $countryCode = '',
public string $countryName = '',
public string $regionName = '',
public string $city = '',
public float $latitude = 0.0,
public float $longitude = 0.0,
public string $timeZone = '',
) {
}

/** @deprecated Use self:.empty() instead */
public static function emptyInstance(): self
{
return new self('', '', '', '', 0.0, 0.0, '');
return self::empty();
}

public static function empty(): self
{
return new self();
}
}
2 changes: 1 addition & 1 deletion src/Resolver/EmptyIpLocationResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class EmptyIpLocationResolver implements IpLocationResolverInterface
*/
public function resolveIpLocation(string $ipAddress): Model\Location
{
return Model\Location::emptyInstance();
return Model\Location::empty();
}
}
4 changes: 2 additions & 2 deletions test/Resolver/ChainIpLocationResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function returnsResultOfFirstInnerResolver(): void
->expects($this->once())
->method('resolveIpLocation')
->with($this->equalTo($ipAddress))
->willReturn(Location::emptyInstance());
->willReturn(Location::empty());
$this->secondInnerResolver->expects($this->never())->method('resolveIpLocation');

$this->resolver->resolveIpLocation($ipAddress);
Expand All @@ -76,7 +76,7 @@ public function returnsResultOfSecondInnerResolver(): void
->expects($this->once())
->method('resolveIpLocation')
->with($this->equalTo($ipAddress))
->willReturn(Location::emptyInstance());
->willReturn(Location::empty());

$this->resolver->resolveIpLocation($ipAddress);
}
Expand Down
2 changes: 1 addition & 1 deletion test/Resolver/EmptyIpLocationResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function setUp(): void
#[Test, DataProvider('provideEmptyResponses')]
public function alwaysReturnsAnEmptyLocation(string $ipAddress): void
{
self::assertEquals(Location::emptyInstance(), $this->resolver->resolveIpLocation($ipAddress));
self::assertEquals(Location::empty(), $this->resolver->resolveIpLocation($ipAddress));
}

public static function provideEmptyResponses(): array
Expand Down
2 changes: 1 addition & 1 deletion test/Resolver/GeoLite2LocationResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ public function resolvedCityIsProperlyMapped(): void

$result = $this->resolver->resolveIpLocation($ipAddress);

self::assertEquals(Location::emptyInstance(), $result);
self::assertEquals(Location::empty(), $result);
}
}

0 comments on commit fadae5d

Please sign in to comment.