From c16fd2e3e411a035eded7a6c34fb30d45cb677e3 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Mon, 19 Jun 2023 16:27:09 -0400 Subject: [PATCH] Add remaining strict types --- src/Commands/Update.php | 2 +- src/Drivers/Driver.php | 12 +-- src/Drivers/HttpDriver.php | 4 +- .../DriverDoesNotExistException.php | 6 +- src/Facades/Location.php | 6 +- src/LocationManager.php | 8 +- src/LocationServiceProvider.php | 10 +-- src/Position.php | 86 ++++++------------- tests/TestCase.php | 2 +- 9 files changed, 39 insertions(+), 97 deletions(-) diff --git a/src/Commands/Update.php b/src/Commands/Update.php index 84e97b5..812cd97 100644 --- a/src/Commands/Update.php +++ b/src/Commands/Update.php @@ -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) { diff --git a/src/Drivers/Driver.php b/src/Drivers/Driver.php index ff0988b..9d397bc 100644 --- a/src/Drivers/Driver.php +++ b/src/Drivers/Driver.php @@ -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; @@ -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 { diff --git a/src/Drivers/HttpDriver.php b/src/Drivers/HttpDriver.php index 492590e..dfa6cc0 100644 --- a/src/Drivers/HttpDriver.php +++ b/src/Drivers/HttpDriver.php @@ -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. diff --git a/src/Exceptions/DriverDoesNotExistException.php b/src/Exceptions/DriverDoesNotExistException.php index d0054b8..a6c78ce 100644 --- a/src/Exceptions/DriverDoesNotExistException.php +++ b/src/Exceptions/DriverDoesNotExistException.php @@ -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?" diff --git a/src/Facades/Location.php b/src/Facades/Location.php index 0922b10..6b2faea 100644 --- a/src/Facades/Location.php +++ b/src/Facades/Location.php @@ -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; } diff --git a/src/LocationManager.php b/src/LocationManager.php index db65dbf..43a5f22 100644 --- a/src/LocationManager.php +++ b/src/LocationManager.php @@ -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'); } diff --git a/src/LocationServiceProvider.php b/src/LocationServiceProvider.php index 0a87efa..1aefe1d 100644 --- a/src/LocationServiceProvider.php +++ b/src/LocationServiceProvider.php @@ -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' @@ -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); } diff --git a/src/Position.php b/src/Position.php index 1d98ae2..2b74b32 100644 --- a/src/Position.php +++ b/src/Position.php @@ -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); } diff --git a/tests/TestCase.php b/tests/TestCase.php index ae15c4f..bc3eaf9 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -10,7 +10,7 @@ class TestCase extends BaseTestCase /** * {@inheritdoc} */ - protected function getPackageProviders($app) + protected function getPackageProviders($app): array { return [LocationServiceProvider::class]; }