Skip to content

Commit

Permalink
Add remaining strict types
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebauman committed Jun 19, 2023
1 parent fe9c88b commit c16fd2e
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 97 deletions.
2 changes: 1 addition & 1 deletion src/Commands/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Update extends Command
*
* @return int
*/
public function handle()
public function handle(): int
{
foreach (Location::drivers() as $driver) {
if ($driver instanceof Updatable) {
Expand Down
12 changes: 2 additions & 10 deletions src/Drivers/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ abstract class Driver
{
/**
* The fallback driver.
*
* @var Driver|null
*/
protected $fallback;
protected ?Driver $fallback = null;

/**
* Append a fallback driver to the end of the chain.
*
* @param Driver $handler
*/
public function fallback(Driver $handler)
public function fallback(Driver $handler): void
{
if (is_null($this->fallback)) {
$this->fallback = $handler;
Expand Down Expand Up @@ -75,10 +71,6 @@ protected function makePosition(): Position

/**
* Determine if the given fluent data is not empty.
*
* @param Fluent $data
*
* @return bool
*/
protected function isEmpty(Fluent $data): bool
{
Expand Down
4 changes: 1 addition & 3 deletions src/Drivers/HttpDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ abstract class HttpDriver extends Driver
{
/**
* The HTTP resolver callback.
*
* @var Closure|null
*/
protected static $httpResolver;
protected static ?Closure $httpResolver = null;

/**
* Get the URL for the HTTP request.
Expand Down
6 changes: 1 addition & 5 deletions src/Exceptions/DriverDoesNotExistException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ class DriverDoesNotExistException extends LocationException
{
/**
* Create a new exception for the non-existent driver.
*
* @param string $driver
*
* @return static
*/
public static function forDriver($driver)
public static function forDriver(string $driver): static
{
return new static(
"The location driver [$driver] does not exist. Did you publish the configuration file?"
Expand Down
6 changes: 2 additions & 4 deletions src/Facades/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
class Location extends Facade
{
/**
* The IoC key accessor.
*
* @return string
* Get the registered name of the component.
*/
protected static function getFacadeAccessor()
protected static function getFacadeAccessor(): string
{
return LocationManager::class;
}
Expand Down
8 changes: 2 additions & 6 deletions src/LocationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,16 @@ public function drivers(): array

/**
* Get the fallback location drivers to use.
*
* @return array
*/
protected function getDriverFallbacks()
protected function getDriverFallbacks(): array
{
return config('location.fallbacks', []);
}

/**
* Get the default location driver.
*
* @return string
*/
protected function getDefaultDriver()
protected function getDefaultDriver(): string
{
return config('location.driver');
}
Expand Down
10 changes: 3 additions & 7 deletions src/LocationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
class LocationServiceProvider extends ServiceProvider
{
/**
* Run boot operations.
*
* @return void
* Bootstrap the service provider.
*/
public function boot()
public function boot(): void
{
$this->mergeConfigFrom(
$config = __DIR__.'/../config/location.php', 'location'
Expand All @@ -27,10 +25,8 @@ public function boot()

/**
* Register bindings in the service container.
*
* @return void
*/
public function register()
public function register(): void
{
$this->app->singleton(LocationManager::class);
}
Expand Down
86 changes: 26 additions & 60 deletions src/Position.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,135 +3,101 @@
namespace Stevebauman\Location;

use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Arr;

class Position implements Arrayable
{
/**
* The IP address used to retrieve the location.
*
* @var string
*/
public $ip;
public string $ip;

/**
* The driver used for retrieving the location.
*/
public string $driver;

/**
* The country name.
*
* @var string|null
*/
public $countryName;
public ?string $countryName = null;

/**
* The country code.
*
* @var string|null
*/
public $countryCode;
public ?string $countryCode = null;

/**
* The region code.
*
* @var string|null
*/
public $regionCode;
public ?string $regionCode = null;

/**
* The region name.
*
* @var string|null
*/
public $regionName;
public ?string $regionName = null;

/**
* The city name.
*
* @var string|null
*/
public $cityName;
public ?string $cityName = null;

/**
* The zip code.
*
* @var string|null
*/
public $zipCode;
public ?string $zipCode = null;

/**
* The iso code.
*
* @var string|null
* The ISO code.
*/
public $isoCode;
public ?string $isoCode = null;

/**
* The postal code.
*
* @var string|null
*/
public $postalCode;
public ?string $postalCode = null;

/**
* The latitude.
*
* @var string|null
*/
public $latitude;
public ?string $latitude = null;

/**
* The longitude.
*
* @var string|null
*/
public $longitude;
public ?string $longitude = null;

/**
* The metro code.
*
* @var string|null
*/
public $metroCode;
public ?string $metroCode = null;

/**
* The area code.
*
* @var string|null
*/
public $areaCode;
public ?string $areaCode = null;

/**
* The timezone.
*
* @var string|null
*/
public $timezone;

/**
* The driver used for retrieving the location.
*
* @var string|null
*/
public $driver;
public ?string $timezone = null;

/**
* Determine if the position is empty.
*
* @return bool
*/
public function isEmpty()
public function isEmpty(): bool
{
$data = $this->toArray();

unset($data['ip']);
unset($data['driver']);
$data = Arr::except(
$this->toArray(), ['ip', 'driver']
);

return empty(array_filter($data));
}

/**
* Get the instance as an array.
*
* @return array
*/
public function toArray()
public function toArray(): array
{
return get_object_vars($this);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TestCase extends BaseTestCase
/**
* {@inheritdoc}
*/
protected function getPackageProviders($app)
protected function getPackageProviders($app): array
{
return [LocationServiceProvider::class];
}
Expand Down

0 comments on commit c16fd2e

Please sign in to comment.