From 78c36715d3e8761e3ad991878353a7904b05a0bd Mon Sep 17 00:00:00 2001 From: Dan Harrin Date: Mon, 4 Oct 2021 10:46:02 +0100 Subject: [PATCH] chore: add PHP types to all classes --- .github/workflows/monorepo-split.yml | 2 +- .github/workflows/tests.yml | 8 +- README.md | 29 ++-- SECURITY.md | 1 + composer.json | 6 +- composer.lock | 2 +- packages/airlines-en/composer.json | 76 +++++----- .../src/AirlinesEnServiceProvider.php | 4 +- packages/airlines/composer.json | 76 +++++----- .../airlines/src/AirlinesServiceProvider.php | 6 +- packages/airlines/src/Models/Airline.php | 7 +- packages/airlines/src/Rules/Airline.php | 16 --- packages/airlines/src/Rules/AirlineRule.php | 17 +++ packages/airports-en/composer.json | 76 +++++----- .../src/AirportsEnServiceProvider.php | 4 +- packages/airports/composer.json | 76 +++++----- .../airports/src/AirportsServiceProvider.php | 6 +- packages/airports/src/Models/Airport.php | 8 +- packages/airports/src/Rules/Airport.php | 16 --- packages/airports/src/Rules/AirportRule.php | 17 +++ packages/continents-de/composer.json | 76 +++++----- .../src/ContinentsDeServiceProvider.php | 4 +- packages/continents-en/composer.json | 76 +++++----- .../src/ContinentsEnServiceProvider.php | 4 +- packages/continents/composer.json | 76 +++++----- .../src/ContinentsServiceProvider.php | 6 +- packages/continents/src/Models/Continent.php | 8 +- packages/continents/src/Rules/Continent.php | 16 --- .../continents/src/Rules/ContinentRule.php | 17 +++ packages/countries-de/composer.json | 76 +++++----- .../src/CountriesDeServiceProvider.php | 4 +- packages/countries-en/composer.json | 76 +++++----- .../src/CountriesEnServiceProvider.php | 4 +- packages/countries-es/composer.json | 76 +++++----- .../src/CountriesEsServiceProvider.php | 4 +- packages/countries-fr/composer.json | 76 +++++----- .../src/CountriesFrServiceProvider.php | 4 +- packages/countries/composer.json | 76 +++++----- .../src/CountriesServiceProvider.php | 6 +- packages/countries/src/Models/Country.php | 14 +- packages/countries/src/Rules/Country.php | 16 --- packages/countries/src/Rules/CountryRule.php | 17 +++ packages/currencies-en/composer.json | 76 +++++----- .../src/CurrenciesEnServiceProvider.php | 4 +- packages/currencies/composer.json | 78 ++++++----- .../src/CurrenciesServiceProvider.php | 6 +- packages/currencies/src/Models/Currency.php | 12 +- packages/currencies/src/Rules/Currency.php | 16 --- .../currencies/src/Rules/CurrencyRule.php | 17 +++ packages/gb-counties-en/composer.json | 76 +++++----- .../src/GbCountiesEnServiceProvider.php | 4 +- packages/gb-counties/composer.json | 76 +++++----- .../src/GbCountiesServiceProvider.php | 6 +- packages/gb-counties/src/Models/GbCounty.php | 5 +- packages/gb-counties/src/Rules/GbCounty.php | 16 --- .../gb-counties/src/Rules/GbCountyRule.php | 17 +++ packages/model/composer.json | 76 +++++----- packages/model/src/Model.php | 132 +++++++++--------- packages/model/src/ModelServiceProvider.php | 6 +- packages/regions-en/composer.json | 76 +++++----- .../src/RegionsEnServiceProvider.php | 4 +- packages/regions/composer.json | 76 +++++----- packages/regions/src/Models/Region.php | 13 +- .../regions/src/RegionsServiceProvider.php | 6 +- packages/regions/src/Rules/Region.php | 16 --- packages/regions/src/Rules/RegionRule.php | 17 +++ packages/repository/composer.json | 78 ++++++----- .../Exceptions/SourceNotFoundException.php | 2 +- .../TranslationNotFoundException.php | 2 +- packages/repository/src/Repository.php | 2 +- packages/repository/src/RepositoryManager.php | 57 ++++---- .../src/RepositoryServiceProvider.php | 2 +- packages/rule/composer.json | 61 ++++---- packages/rule/src/Rule.php | 22 +-- phpunit.xml => phpunit.xml.dist | 0 tests/ModelTest.php | 58 ++++---- tests/Models/Foo.php | 2 +- tests/RuleTest.php | 36 +++-- tests/Rules/Foo.php | 18 --- tests/Rules/FooRule.php | 19 +++ tests/TestCase.php | 58 +++++--- 81 files changed, 1273 insertions(+), 1160 deletions(-) delete mode 100644 packages/airlines/src/Rules/Airline.php create mode 100644 packages/airlines/src/Rules/AirlineRule.php delete mode 100644 packages/airports/src/Rules/Airport.php create mode 100644 packages/airports/src/Rules/AirportRule.php delete mode 100644 packages/continents/src/Rules/Continent.php create mode 100644 packages/continents/src/Rules/ContinentRule.php delete mode 100644 packages/countries/src/Rules/Country.php create mode 100644 packages/countries/src/Rules/CountryRule.php delete mode 100644 packages/currencies/src/Rules/Currency.php create mode 100644 packages/currencies/src/Rules/CurrencyRule.php delete mode 100644 packages/gb-counties/src/Rules/GbCounty.php create mode 100644 packages/gb-counties/src/Rules/GbCountyRule.php delete mode 100644 packages/regions/src/Rules/Region.php create mode 100644 packages/regions/src/Rules/RegionRule.php rename phpunit.xml => phpunit.xml.dist (100%) delete mode 100644 tests/Rules/Foo.php create mode 100644 tests/Rules/FooRule.php diff --git a/.github/workflows/monorepo-split.yml b/.github/workflows/monorepo-split.yml index 21a6300..e99c62a 100644 --- a/.github/workflows/monorepo-split.yml +++ b/.github/workflows/monorepo-split.yml @@ -11,7 +11,7 @@ jobs: - uses: actions/checkout@v2 - uses: shivammathur/setup-php@v2 with: - php-version: 7.4 + php-version: 8.0 coverage: none - uses: "ramsey/composer-install@v1" - id: packages-list diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ea27f39..f7f243e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,16 +10,12 @@ jobs: strategy: fail-fast: false matrix: - php: [8.0, 7.4, 7.3] - laravel: [8.*, 7.*, 6.*] + php: [8.0] + laravel: [8.*] dependency-version: [prefer-lowest, prefer-stable] include: - laravel: 8.* testbench: 6.* - - laravel: 7.* - testbench: 5.* - - laravel: 6.* - testbench: 4.* name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} steps: - uses: actions/checkout@v2 diff --git a/README.md b/README.md index 6334a56..822907c 100644 --- a/README.md +++ b/README.md @@ -271,11 +271,12 @@ The simplest option is to create a new model in your app, and let it extend the namespace App\Models; +use Illuminate\Database\Eloquent\Relations\HasMany; use Squire\Models\Country as SquireCountry; class Country extends SquireCountry { - public function users() + public function users(): HasMany { return $this->hasMany(User::class); } @@ -288,9 +289,10 @@ Another option is the `resolveRelationUsing()` method. This allows you to dynami ```php use App\Models\User; +use Illuminate\Database\Eloquent\Relations\HasMany; use Squire\Models\Country; -Country::resolveRelationUsing('users', function (Country $country) { +Country::resolveRelationUsing('users', function (Country $country): HasMany { return $country->hasMany(User::class); }); ``` @@ -305,7 +307,7 @@ Rules can be found in the `Squire\Rules` namespace. To use one, simply construct use Squire\Rules; $request->validate([ - 'country' => ['required', 'string', new Rules\Country('name')], + 'country' => ['required', 'string', new Rules\CountryRule('name')], ]); ``` @@ -334,7 +336,7 @@ use Squire\Model; class Language extends Model { - public static $schema = [ + public static array $schema = [ 'id' => 'string', 'name' => 'string', ]; @@ -362,9 +364,9 @@ use Squire\Repository; class ModelServiceProvider extends ServiceProvider { - public function boot() + public function boot(): void { - Repository::registerSource(Language::class, 'en', __DIR__.'/../../resources/squire-data/languages-en.csv'); + Repository::registerSource(Language::class, 'en', __DIR__ . '/../../resources/squire-data/languages-en.csv'); } } ``` @@ -395,13 +397,14 @@ Your rule class should contain, at minimum, a `$message` to be served if the val namespace App\Rules; use App\Models; +use Illuminate\Database\Eloquent\Builder; use Squire\Rule; -class Language extends Rule +class LanguageRule extends Rule { - protected $message = 'validation.language'; + protected string $message = 'validation.language'; - protected function getQueryBuilder() + protected function getQueryBuilder(): Builder { return Models\Language::query(); } @@ -419,7 +422,7 @@ use Squire\Rule; class Language extends Rule { - protected $column = 'name'; + protected string $column = 'name'; } ``` @@ -443,11 +446,11 @@ As an example, we will install the `Squire\Models\Country` and `Squire\Models\Co composer require squirephp/countries-en squirephp/continents-en ``` -### Breaking Changes Introduced in 2.x +### Breaking Changes Introduced in 3.x -- The original `Squire\Models\Counties\GbCounty` model has now been moved to `Squire\Models\GbCounty`. +- The minimum PHP version has been bumped to v8.0, and the minimum Laravel version to v8.x. -- The [`$map` property](https://github.com/squirephp/legacy#column-customisation) has been deprecated to improve performance of the package with large datasets. Please set up [Eloquent accessors](https://laravel.com/docs/master/eloquent-mutators#defining-an-accessor) if you require a similar feature. +- Types have been introduced to all classes. If you have created [custom models](#creating-a-model) and [custom validation rules](#creating-a-validation-rule), properties and methods now need to use the correct types. ## Need Help? diff --git a/SECURITY.md b/SECURITY.md index 202f873..7747053 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -4,6 +4,7 @@ | Version | Supported | | ------- | ------------------ | +| 3.x | :white_check_mark: | | 2.x | :white_check_mark: | | 1.x | :white_check_mark: | diff --git a/composer.json b/composer.json index 22ede2a..622ca2e 100644 --- a/composer.json +++ b/composer.json @@ -7,10 +7,10 @@ } ], "require": { - "php": "^7.2|^8.0", - "illuminate/contracts": "^6.0 || ^7.0 || ^8.0", + "php": "^8.0", + "illuminate/contracts": "^8.0", "illuminate/database": "^6.0 || ^7.0 || ^8.40.0", - "illuminate/support": "^6.0 || ^7.0 || ^8.0", + "illuminate/support": "^8.0", "akaunting/laravel-money": "^1.2" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 6358691..2caf968 100644 --- a/composer.lock +++ b/composer.lock @@ -317,7 +317,7 @@ "shasum": "" }, "require": { - "php": "^7.2|^8.0", + "php": "^8.0", "webmozart/assert": "^1.7.0" }, "replace": { diff --git a/packages/airlines-en/composer.json b/packages/airlines-en/composer.json index 317c379..f8b9c84 100644 --- a/packages/airlines-en/composer.json +++ b/packages/airlines-en/composer.json @@ -1,39 +1,41 @@ { - "name": "squirephp/airlines-en", - "description": "A library containing the English translation of Squire's Airline model.", - "keywords": ["squire"], - "license": "MIT", - "homepage": "https://github.com/squirephp", - "support": { - "issues": "https://github.com/squirephp/squire/issues", - "source": "https://github.com/squirephp/squire" - }, - "authors": [ - { - "name": "Dan Harrin", - "email": "dan@danharrin.com" - } - ], - "require": { - "php": "^7.2|^8.0", - "illuminate/support": "^6.0 || ^7.0 || ^8.0", - "squirephp/airlines": "^2.0", - "squirephp/repository": "^2.0" - }, - "autoload": { - "psr-4": { - "Squire\\": "src" - } - }, - "extra": { - "laravel": { - "providers": [ - "Squire\\AirlinesEnServiceProvider" - ] - } - }, - "config": { - "sort-packages": true - }, - "minimum-stability": "dev" + "name": "squirephp/airlines-en", + "description": "A library containing the English translation of Squire's Airline model.", + "keywords": [ + "squire" + ], + "license": "MIT", + "homepage": "https://github.com/squirephp", + "support": { + "issues": "https://github.com/squirephp/squire/issues", + "source": "https://github.com/squirephp/squire" + }, + "authors": [ + { + "name": "Dan Harrin", + "email": "dan@danharrin.com" + } + ], + "require": { + "php": "^8.0", + "illuminate/support": "^8.0", + "squirephp/airlines": "^2.0", + "squirephp/repository": "^2.0" + }, + "autoload": { + "psr-4": { + "Squire\\": "src" + } + }, + "extra": { + "laravel": { + "providers": [ + "Squire\\AirlinesEnServiceProvider" + ] + } + }, + "config": { + "sort-packages": true + }, + "minimum-stability": "dev" } diff --git a/packages/airlines-en/src/AirlinesEnServiceProvider.php b/packages/airlines-en/src/AirlinesEnServiceProvider.php index 33c8ac7..b0869dd 100644 --- a/packages/airlines-en/src/AirlinesEnServiceProvider.php +++ b/packages/airlines-en/src/AirlinesEnServiceProvider.php @@ -7,8 +7,8 @@ class AirlinesEnServiceProvider extends ServiceProvider { - public function boot() + public function boot(): void { - Repository::registerSource(Airline::class, 'en', __DIR__.'/../resources/data.csv'); + Repository::registerSource(Airline::class, 'en', __DIR__ . '/../resources/data.csv'); } } \ No newline at end of file diff --git a/packages/airlines/composer.json b/packages/airlines/composer.json index 2863ecd..69cc381 100644 --- a/packages/airlines/composer.json +++ b/packages/airlines/composer.json @@ -1,39 +1,41 @@ { - "name": "squirephp/airlines", - "description": "A library containing Squire's Airline model.", - "keywords": ["squire"], - "license": "MIT", - "homepage": "https://github.com/squirephp", - "support": { - "issues": "https://github.com/squirephp/squire/issues", - "source": "https://github.com/squirephp/squire" - }, - "authors": [ - { - "name": "Dan Harrin", - "email": "dan@danharrin.com" - } - ], - "require": { - "php": "^7.2|^8.0", - "illuminate/support": "^6.0 || ^7.0 || ^8.0", - "squirephp/model": "^2.0", - "squirephp/rule": "^2.0" - }, - "autoload": { - "psr-4": { - "Squire\\": "src" - } - }, - "extra": { - "laravel": { - "providers": [ - "Squire\\AirlinesServiceProvider" - ] - } - }, - "config": { - "sort-packages": true - }, - "minimum-stability": "dev" + "name": "squirephp/airlines", + "description": "A library containing Squire's Airline model.", + "keywords": [ + "squire" + ], + "license": "MIT", + "homepage": "https://github.com/squirephp", + "support": { + "issues": "https://github.com/squirephp/squire/issues", + "source": "https://github.com/squirephp/squire" + }, + "authors": [ + { + "name": "Dan Harrin", + "email": "dan@danharrin.com" + } + ], + "require": { + "php": "^8.0", + "illuminate/support": "^8.0", + "squirephp/model": "^2.0", + "squirephp/rule": "^2.0" + }, + "autoload": { + "psr-4": { + "Squire\\": "src" + } + }, + "extra": { + "laravel": { + "providers": [ + "Squire\\AirlinesServiceProvider" + ] + } + }, + "config": { + "sort-packages": true + }, + "minimum-stability": "dev" } diff --git a/packages/airlines/src/AirlinesServiceProvider.php b/packages/airlines/src/AirlinesServiceProvider.php index 14b49cb..6e3bd3b 100644 --- a/packages/airlines/src/AirlinesServiceProvider.php +++ b/packages/airlines/src/AirlinesServiceProvider.php @@ -6,12 +6,12 @@ class AirlinesServiceProvider extends ServiceProvider { - public function boot() + public function boot(): void { - $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'squire-airlines'); + $this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'squire-airlines'); $this->publishes([ - __DIR__.'/../resources/lang' => resource_path('lang/vendor/squire-airlines'), + __DIR__ . '/../resources/lang' => resource_path('lang/vendor/squire-airlines'), ]); } } \ No newline at end of file diff --git a/packages/airlines/src/Models/Airline.php b/packages/airlines/src/Models/Airline.php index e2358cc..c34c899 100644 --- a/packages/airlines/src/Models/Airline.php +++ b/packages/airlines/src/Models/Airline.php @@ -2,11 +2,12 @@ namespace Squire\Models; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Squire\Model; class Airline extends Model { - public static $schema = [ + public static array $schema = [ 'id' => 'string', 'alias' => 'string', 'call_sign' => 'string', @@ -16,12 +17,12 @@ class Airline extends Model 'name' => 'string', ]; - public function country() + public function country(): BelongsTo { return $this->belongsTo(Country::class); } - public function continent() + public function continent(): BelongsTo { return $this->hasOneThrough(Continent::class, Country::class); } diff --git a/packages/airlines/src/Rules/Airline.php b/packages/airlines/src/Rules/Airline.php deleted file mode 100644 index 21b4859..0000000 --- a/packages/airlines/src/Rules/Airline.php +++ /dev/null @@ -1,16 +0,0 @@ -loadTranslationsFrom(__DIR__.'/../resources/lang', 'squire-airports'); + $this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'squire-airports'); $this->publishes([ - __DIR__.'/../resources/lang' => resource_path('lang/vendor/squire-airports'), + __DIR__ . '/../resources/lang' => resource_path('lang/vendor/squire-airports'), ]); } } \ No newline at end of file diff --git a/packages/airports/src/Models/Airport.php b/packages/airports/src/Models/Airport.php index 6bb8d98..92775dc 100644 --- a/packages/airports/src/Models/Airport.php +++ b/packages/airports/src/Models/Airport.php @@ -2,11 +2,13 @@ namespace Squire\Models; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\HasOneThrough; use Squire\Model; class Airport extends Model { - public static $schema = [ + public static array $schema = [ 'id' => 'string', 'code_gps' => 'string', 'code_iata' => 'string', @@ -17,12 +19,12 @@ class Airport extends Model 'type' => 'string', ]; - public function country() + public function country(): HasOneThrough { return $this->hasOneThrough(Country::class, Region::class); } - public function region() + public function region(): BelongsTo { return $this->belongsTo(Region::class); } diff --git a/packages/airports/src/Rules/Airport.php b/packages/airports/src/Rules/Airport.php deleted file mode 100644 index 30f7ad9..0000000 --- a/packages/airports/src/Rules/Airport.php +++ /dev/null @@ -1,16 +0,0 @@ -loadTranslationsFrom(__DIR__.'/../resources/lang', 'squire-continents'); + $this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'squire-continents'); $this->publishes([ - __DIR__.'/../resources/lang' => resource_path('lang/vendor/squire-continents'), + __DIR__ . '/../resources/lang' => resource_path('lang/vendor/squire-continents'), ]); } } \ No newline at end of file diff --git a/packages/continents/src/Models/Continent.php b/packages/continents/src/Models/Continent.php index 7571b55..c036454 100644 --- a/packages/continents/src/Models/Continent.php +++ b/packages/continents/src/Models/Continent.php @@ -2,22 +2,24 @@ namespace Squire\Models; +use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Squire\Model; class Continent extends Model { - public static $schema = [ + public static array $schema = [ 'id' => 'string', 'code' => 'string', 'name' => 'string', ]; - public function countries() + public function countries(): HasMany { return $this->hasMany(Country::class); } - public function regions() + public function regions(): HasManyThrough { return $this->hasManyThrough(Region::class, Country::class); } diff --git a/packages/continents/src/Rules/Continent.php b/packages/continents/src/Rules/Continent.php deleted file mode 100644 index 8a43f62..0000000 --- a/packages/continents/src/Rules/Continent.php +++ /dev/null @@ -1,16 +0,0 @@ -loadTranslationsFrom(__DIR__.'/../resources/lang', 'squire-countries'); + $this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'squire-countries'); $this->publishes([ - __DIR__.'/../resources/lang' => resource_path('lang/vendor/squire-countries'), + __DIR__ . '/../resources/lang' => resource_path('lang/vendor/squire-countries'), ]); } } \ No newline at end of file diff --git a/packages/countries/src/Models/Country.php b/packages/countries/src/Models/Country.php index 5988d19..97f9c27 100644 --- a/packages/countries/src/Models/Country.php +++ b/packages/countries/src/Models/Country.php @@ -2,11 +2,13 @@ namespace Squire\Models; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\HasMany; use Squire\Model; class Country extends Model { - public static $schema = [ + public static array $schema = [ 'id' => 'string', 'calling_code' => 'string', 'capital_city' => 'string', @@ -18,27 +20,27 @@ class Country extends Model 'name' => 'string', ]; - public function airlines() + public function airlines(): HasMany { return $this->hasMany(Airline::class); } - public function airports() + public function airports(): HasMany { return $this->hasMany(Airport::class); } - public function continent() + public function continent(): BelongsTo { return $this->belongsTo(Continent::class); } - public function currency() + public function currency(): BelongsTo { return $this->belongsTo(Currency::class); } - public function regions() + public function regions(): HasMany { return $this->hasMany(Region::class); } diff --git a/packages/countries/src/Rules/Country.php b/packages/countries/src/Rules/Country.php deleted file mode 100644 index f8b8b8c..0000000 --- a/packages/countries/src/Rules/Country.php +++ /dev/null @@ -1,16 +0,0 @@ -loadTranslationsFrom(__DIR__.'/../resources/lang', 'squire-currencies'); + $this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'squire-currencies'); $this->publishes([ - __DIR__.'/../resources/lang' => resource_path('lang/vendor/squire-currencies'), + __DIR__ . '/../resources/lang' => resource_path('lang/vendor/squire-currencies'), ]); } } \ No newline at end of file diff --git a/packages/currencies/src/Models/Currency.php b/packages/currencies/src/Models/Currency.php index ac81146..69832e2 100644 --- a/packages/currencies/src/Models/Currency.php +++ b/packages/currencies/src/Models/Currency.php @@ -2,11 +2,13 @@ namespace Squire\Models; +use Akaunting\Money; +use Illuminate\Database\Eloquent\Relations\HasMany; use Squire\Model; class Currency extends Model { - public static $schema = [ + public static array $schema = [ 'id' => 'string', 'code_alphabetic' => 'string', 'code_numeric' => 'integer', @@ -18,16 +20,16 @@ class Currency extends Model 'symbol_native' => 'string', ]; - public function countries() + public function countries(): HasMany { return $this->hasMany(Country::class); } - public function format($number, $shouldConvert = false) + public function format(int $number, bool $shouldConvert = false): string { - return (new \Akaunting\Money\Money( + return (new Money\Money( $number, - (new \Akaunting\Money\Currency(strtoupper($this->id))), + (new Money\Currency(strtoupper($this->id))), $shouldConvert ))->format(); } diff --git a/packages/currencies/src/Rules/Currency.php b/packages/currencies/src/Rules/Currency.php deleted file mode 100644 index b8b40d0..0000000 --- a/packages/currencies/src/Rules/Currency.php +++ /dev/null @@ -1,16 +0,0 @@ -loadTranslationsFrom(__DIR__.'/../resources/lang', 'squire-gb-counties'); + $this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'squire-gb-counties'); $this->publishes([ - __DIR__.'/../resources/lang' => resource_path('lang/vendor/squire-gb-counties'), + __DIR__ . '/../resources/lang' => resource_path('lang/vendor/squire-gb-counties'), ]); } } \ No newline at end of file diff --git a/packages/gb-counties/src/Models/GbCounty.php b/packages/gb-counties/src/Models/GbCounty.php index 947ef98..b436fef 100644 --- a/packages/gb-counties/src/Models/GbCounty.php +++ b/packages/gb-counties/src/Models/GbCounty.php @@ -2,18 +2,19 @@ namespace Squire\Models; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Squire\Model; class GbCounty extends Model { - public static $schema = [ + public static array $schema = [ 'id' => 'string', 'code' => 'string', 'name' => 'string', 'region_id' => 'string', ]; - public function region() + public function region(): BelongsTo { return $this->belongsTo(Region::class); } diff --git a/packages/gb-counties/src/Rules/GbCounty.php b/packages/gb-counties/src/Rules/GbCounty.php deleted file mode 100644 index 64ef486..0000000 --- a/packages/gb-counties/src/Rules/GbCounty.php +++ /dev/null @@ -1,16 +0,0 @@ -filter(function ($locale) { - return Repository::sourceIsRegistered(static::class, $locale); - })->each(function ($locale) { - $cachePath = static::getCachePath($locale); - - file_put_contents($cachePath, ''); - - static::setSqliteConnection($cachePath); - - static::migrate($locale); - - $modelUpdatedAt = static::getModelUpdatedAt(); - $sourceUpdatedAt = static::getSourceUpdatedAt($locale); + $cachedAt = static::getCachedAt($locale); + $modelUpdatedAt = static::getModelUpdatedAt(); + $sourceUpdatedAt = static::getSourceUpdatedAt($locale); - touch($cachePath, $modelUpdatedAt >= $sourceUpdatedAt ? $modelUpdatedAt : $sourceUpdatedAt); - }); - - return false; + return $modelUpdatedAt <= $cachedAt && $sourceUpdatedAt <= $cachedAt; } - protected static function getCachedAt($locale = null) + protected static function getCachedAt($locale = null): int { $cachePath = static::getCachePath($locale); return file_exists($cachePath) ? filemtime($cachePath) : 0; } - protected static function getCacheDirectory() + protected static function getCachePath(?string $locale = null): string + { + return static::getCacheDirectory() . '/' . static::getCacheFileName($locale); + } + + protected static function getCacheDirectory(): string { return realpath(config('squire.cache-path', storage_path('framework/cache'))); } - protected static function getCacheFileName($locale = null) + protected static function getCacheFileName(?string $locale = null): string { $kebabCaseLocale = strtolower(str_replace('_', '-', $locale ?? Repository::getLocale(static::class))); - $kebabCaseModelClassName = Str::kebab(str_replace( '\\', '', static::class)); + $kebabCaseModelClassName = Str::kebab(str_replace('\\', '', static::class)); - return config('squire.cache-prefix', 'squire').'-'.$kebabCaseModelClassName.'-'.$kebabCaseLocale.'.sqlite'; + return config('squire.cache-prefix', 'squire') . '-' . $kebabCaseModelClassName . '-' . $kebabCaseLocale . '.sqlite'; } - protected static function getCachePath($locale = null) + protected static function getModelUpdatedAt(): int { - return static::getCacheDirectory().'/'.static::getCacheFileName($locale); - } - - protected static function getModelUpdatedAt() - { - return filemtime((new \ReflectionClass(static::class))->getFileName()); + return filemtime((new ReflectionClass(static::class))->getFileName()); } - protected static function getSourceUpdatedAt($locale = null) + protected static function getSourceUpdatedAt(?string $locale = null): int { return filemtime(Repository::getSource(static::class, $locale)); } - protected static function hasValidCache($locale = null) + protected static function setSqliteConnection(string $database): void { - $cachedAt = static::getCachedAt($locale); - $modelUpdatedAt = static::getModelUpdatedAt(); - $sourceUpdatedAt = static::getSourceUpdatedAt($locale); - - return $modelUpdatedAt <= $cachedAt && $sourceUpdatedAt <= $cachedAt; + static::$sqliteConnections[static::class] = app(ConnectionFactory::class)->make([ + 'driver' => 'sqlite', + 'database' => $database, + ]); } - protected static function isCacheable() + protected static function isCacheable(): bool { $cacheDirectory = static::getCacheDirectory(); return file_exists($cacheDirectory) && is_writable($cacheDirectory); } - public static function migrate($locale = null) + public static function cache(array $locales = []) + { + if (! count($locales)) { + $locales = array_keys(Repository::getSources(static::class)); + } + + collect($locales) + ->filter(fn (string $locale): bool => Repository::sourceIsRegistered(static::class, $locale)) + ->each(function (string $locale): void { + $cachePath = static::getCachePath($locale); + + file_put_contents($cachePath, ''); + + static::setSqliteConnection($cachePath); + + static::migrate($locale); + + $modelUpdatedAt = static::getModelUpdatedAt(); + $sourceUpdatedAt = static::getSourceUpdatedAt($locale); + + touch($cachePath, $modelUpdatedAt >= $sourceUpdatedAt ? $modelUpdatedAt : $sourceUpdatedAt); + }); + } + + public static function migrate(?string $locale = null): void { $tableName = (new static)->getTable(); - static::resolveConnection()->getSchemaBuilder()->create($tableName, function ($table) { + static::resolveConnection()->getSchemaBuilder()->create($tableName, function (Blueprint $table): void { foreach (static::$schema as $name => $type) { $table->{$type}($name)->nullable(); } @@ -132,31 +136,25 @@ public static function migrate($locale = null) $schema = collect(str_getcsv($data->first())); - $data->transform(function ($line) use ($schema) { - return $schema->combine(str_getcsv($line)); - }); + $data->transform(fn (string $line) => $schema->combine(str_getcsv($line))); $data->shift(); foreach (array_chunk($data->toArray(), 100) ?? [] as $dataToInsert) { - if (! empty($dataToInsert)) static::insert($dataToInsert); + if (empty($dataToInsert)) { + continue; + } + + static::insert($dataToInsert); } } - public static function resolveConnection($connection = null) + public static function resolveConnection($connection = null): SQLiteConnection { return static::$sqliteConnections[static::class]; } - protected static function setSqliteConnection($database) - { - static::$sqliteConnections[static::class] = app(ConnectionFactory::class)->make([ - 'driver' => 'sqlite', - 'database' => $database, - ]); - } - - public function usesTimestamps() + public function usesTimestamps(): bool { return false; } diff --git a/packages/model/src/ModelServiceProvider.php b/packages/model/src/ModelServiceProvider.php index 1057c05..fb4ceb8 100644 --- a/packages/model/src/ModelServiceProvider.php +++ b/packages/model/src/ModelServiceProvider.php @@ -6,14 +6,14 @@ class ModelServiceProvider extends ServiceProvider { - public function boot() + public function boot(): void { $this->publishes([ - __DIR__.'/../config/squire.php' => config_path('squire.php'), + __DIR__ . '/../config/squire.php' => config_path('squire.php'), ]); $this->mergeConfigFrom( - __DIR__.'/../config/squire.php', 'squire' + __DIR__ . '/../config/squire.php', 'squire' ); } } \ No newline at end of file diff --git a/packages/regions-en/composer.json b/packages/regions-en/composer.json index b5bb515..7d7c057 100644 --- a/packages/regions-en/composer.json +++ b/packages/regions-en/composer.json @@ -1,39 +1,41 @@ { - "name": "squirephp/regions-en", - "description": "A library containing the English translation of Squire's Region model.", - "keywords": ["squire"], - "license": "MIT", - "homepage": "https://github.com/squirephp", - "support": { - "issues": "https://github.com/squirephp/squire/issues", - "source": "https://github.com/squirephp/squire" - }, - "authors": [ - { - "name": "Dan Harrin", - "email": "dan@danharrin.com" - } - ], - "require": { - "php": "^7.2|^8.0", - "illuminate/support": "^6.0 || ^7.0 || ^8.0", - "squirephp/regions": "^2.0", - "squirephp/repository": "^2.0" - }, - "autoload": { - "psr-4": { - "Squire\\": "src" - } - }, - "extra": { - "laravel": { - "providers": [ - "Squire\\RegionsEnServiceProvider" - ] - } - }, - "config": { - "sort-packages": true - }, - "minimum-stability": "dev" + "name": "squirephp/regions-en", + "description": "A library containing the English translation of Squire's Region model.", + "keywords": [ + "squire" + ], + "license": "MIT", + "homepage": "https://github.com/squirephp", + "support": { + "issues": "https://github.com/squirephp/squire/issues", + "source": "https://github.com/squirephp/squire" + }, + "authors": [ + { + "name": "Dan Harrin", + "email": "dan@danharrin.com" + } + ], + "require": { + "php": "^8.0", + "illuminate/support": "^8.0", + "squirephp/regions": "^2.0", + "squirephp/repository": "^2.0" + }, + "autoload": { + "psr-4": { + "Squire\\": "src" + } + }, + "extra": { + "laravel": { + "providers": [ + "Squire\\RegionsEnServiceProvider" + ] + } + }, + "config": { + "sort-packages": true + }, + "minimum-stability": "dev" } diff --git a/packages/regions-en/src/RegionsEnServiceProvider.php b/packages/regions-en/src/RegionsEnServiceProvider.php index 41f4f1d..83803f9 100644 --- a/packages/regions-en/src/RegionsEnServiceProvider.php +++ b/packages/regions-en/src/RegionsEnServiceProvider.php @@ -7,8 +7,8 @@ class RegionsEnServiceProvider extends ServiceProvider { - public function boot() + public function boot(): void { - Repository::registerSource(Region::class, 'en', __DIR__.'/../resources/data.csv'); + Repository::registerSource(Region::class, 'en', __DIR__ . '/../resources/data.csv'); } } \ No newline at end of file diff --git a/packages/regions/composer.json b/packages/regions/composer.json index 1a577c7..dbb2737 100644 --- a/packages/regions/composer.json +++ b/packages/regions/composer.json @@ -1,39 +1,41 @@ { - "name": "squirephp/regions", - "description": "A library containing Squire's Region model.", - "keywords": ["squire"], - "license": "MIT", - "homepage": "https://github.com/squirephp", - "support": { - "issues": "https://github.com/squirephp/squire/issues", - "source": "https://github.com/squirephp/squire" - }, - "authors": [ - { - "name": "Dan Harrin", - "email": "dan@danharrin.com" - } - ], - "require": { - "php": "^7.2|^8.0", - "illuminate/support": "^6.0 || ^7.0 || ^8.0", - "squirephp/model": "^2.0", - "squirephp/rule": "^2.0" - }, - "autoload": { - "psr-4": { - "Squire\\": "src" - } - }, - "extra": { - "laravel": { - "providers": [ - "Squire\\RegionsServiceProvider" - ] - } - }, - "config": { - "sort-packages": true - }, - "minimum-stability": "dev" + "name": "squirephp/regions", + "description": "A library containing Squire's Region model.", + "keywords": [ + "squire" + ], + "license": "MIT", + "homepage": "https://github.com/squirephp", + "support": { + "issues": "https://github.com/squirephp/squire/issues", + "source": "https://github.com/squirephp/squire" + }, + "authors": [ + { + "name": "Dan Harrin", + "email": "dan@danharrin.com" + } + ], + "require": { + "php": "^8.0", + "illuminate/support": "^8.0", + "squirephp/model": "^2.0", + "squirephp/rule": "^2.0" + }, + "autoload": { + "psr-4": { + "Squire\\": "src" + } + }, + "extra": { + "laravel": { + "providers": [ + "Squire\\RegionsServiceProvider" + ] + } + }, + "config": { + "sort-packages": true + }, + "minimum-stability": "dev" } diff --git a/packages/regions/src/Models/Region.php b/packages/regions/src/Models/Region.php index 70710f3..bb437bc 100644 --- a/packages/regions/src/Models/Region.php +++ b/packages/regions/src/Models/Region.php @@ -2,33 +2,36 @@ namespace Squire\Models; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\HasOneThrough; use Squire\Model; class Region extends Model { - public static $schema = [ + public static array $schema = [ 'id' => 'string', 'code' => 'string', 'country_id' => 'string', 'name' => 'string', ]; - public function airports() + public function airports(): HasMany { return $this->hasMany(Airport::class); } - public function continent() + public function continent(): HasOneThrough { return $this->hasOneThrough(Continent::class, Country::class); } - public function country() + public function country(): BelongsTo { return $this->belongsTo(Country::class); } - public function gbCounties() + public function gbCounties(): HasMany { return $this->hasMany(GbCounty::class); } diff --git a/packages/regions/src/RegionsServiceProvider.php b/packages/regions/src/RegionsServiceProvider.php index 51da710..de7dfed 100644 --- a/packages/regions/src/RegionsServiceProvider.php +++ b/packages/regions/src/RegionsServiceProvider.php @@ -6,12 +6,12 @@ class RegionsServiceProvider extends ServiceProvider { - public function boot() + public function boot(): void { - $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'squire-regions'); + $this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'squire-regions'); $this->publishes([ - __DIR__.'/../resources/lang' => resource_path('lang/vendor/squire-regions'), + __DIR__ . '/../resources/lang' => resource_path('lang/vendor/squire-regions'), ]); } } \ No newline at end of file diff --git a/packages/regions/src/Rules/Region.php b/packages/regions/src/Rules/Region.php deleted file mode 100644 index 3832c48..0000000 --- a/packages/regions/src/Rules/Region.php +++ /dev/null @@ -1,16 +0,0 @@ -getSource($name, $locale); return $this->fetchDataFromSource($source); } - public function fetchDataFromSource($source) + public function getSource(string $name, ?string $locale = null): string { - return file($source); + if ($locale && ! $this->sourceIsRegistered($name, $locale)) { + throw new TranslationNotFoundException($name, $locale); + } + + if (! $locale) { + $locale = $this->getLocale($name); + } + + return $this->getSources($name)[$locale]; } - public function getLocale($name) + public function sourceIsRegistered(string $name, ?string $locale = null): bool { - $appLocale = App::getLocale(); - if ($this->sourceIsRegistered($name, $appLocale)) return $appLocale; - - $appFallbackLocale = config('app.fallback_locale'); - if ($this->sourceIsRegistered($name, $appFallbackLocale)) return $appFallbackLocale; + if (! $locale) { + return array_key_exists($name, $this->sources); + } - return array_key_first($this->getSources($name)); + return array_key_exists($name, $this->sources) && array_key_exists($locale, $this->sources[$name]); } - public function getSource($name, $locale = null) + public function getLocale(string $name): string { - if ($locale && ! $this->sourceIsRegistered($name, $locale)) - throw new TranslationNotFoundException($name, $locale); + if ($this->sourceIsRegistered($name, $appLocale = App::getLocale())) { + return $appLocale; + } - if (! $locale) $locale = $this->getLocale($name); + if ($this->sourceIsRegistered($name, $appFallbackLocale = config('app.fallback_locale'))) { + return $appFallbackLocale; + } - return $this->getSources($name)[$locale]; + return array_key_first($this->getSources($name)); } - public function getSources($name = null) + public function getSources(?string $name = null): array | string { if (! $name) return $this->sources; @@ -53,17 +62,17 @@ public function getSources($name = null) return $this->sources[$name]; } - public function registerSource($name, $locale, $path) + public function fetchDataFromSource($source): array { - if (! $this->sourceIsRegistered($name)) $this->sources[$name] = []; - - $this->sources[$name][$locale] = realpath($path); + return file($source); } - public function sourceIsRegistered($name, $locale = null) + public function registerSource(string $name, string $locale, string $path): void { - if (! $locale) return array_key_exists($name, $this->sources); + if (! $this->sourceIsRegistered($name)) { + $this->sources[$name] = []; + } - return array_key_exists($name, $this->sources) && array_key_exists($locale, $this->sources[$name]); + $this->sources[$name][$locale] = realpath($path); } } \ No newline at end of file diff --git a/packages/repository/src/RepositoryServiceProvider.php b/packages/repository/src/RepositoryServiceProvider.php index 545727b..c269f9d 100644 --- a/packages/repository/src/RepositoryServiceProvider.php +++ b/packages/repository/src/RepositoryServiceProvider.php @@ -6,7 +6,7 @@ class RepositoryServiceProvider extends ServiceProvider { - public $singletons = [ + public array $singletons = [ RepositoryManager::class => RepositoryManager::class, ]; } \ No newline at end of file diff --git a/packages/rule/composer.json b/packages/rule/composer.json index 924bb33..badb37c 100644 --- a/packages/rule/composer.json +++ b/packages/rule/composer.json @@ -1,31 +1,34 @@ { - "name": "squirephp/rule", - "description": "A library containing the base Squire rule class.", - "keywords": ["squire"], - "license": "MIT", - "homepage": "https://github.com/squirephp", - "support": { - "issues": "https://github.com/squirephp/squire/issues", - "source": "https://github.com/squirephp/squire" - }, - "authors": [ - { - "name": "Dan Harrin", - "email": "dan@danharrin.com" - } - ], - "require": { - "php": "^7.2|^8.0", - "illuminate/contracts": "^6.0 || ^7.0 || ^8.0", - "illuminate/support": "^6.0 || ^7.0 || ^8.0" - }, - "autoload": { - "psr-4": { - "Squire\\": "src" - } - }, - "config": { - "sort-packages": true - }, - "minimum-stability": "dev" + "name": "squirephp/rule", + "description": "A library containing the base Squire rule class.", + "keywords": [ + "squire" + ], + "license": "MIT", + "homepage": "https://github.com/squirephp", + "support": { + "issues": "https://github.com/squirephp/squire/issues", + "source": "https://github.com/squirephp/squire" + }, + "authors": [ + { + "name": "Dan Harrin", + "email": "dan@danharrin.com" + } + ], + "require": { + "php": "^8.0", + "illuminate/contracts": "^8.0", + "illuminate/database": "^8.0", + "illuminate/support": "^8.0" + }, + "autoload": { + "psr-4": { + "Squire\\": "src" + } + }, + "config": { + "sort-packages": true + }, + "minimum-stability": "dev" } diff --git a/packages/rule/src/Rule.php b/packages/rule/src/Rule.php index 70ce75e..f249b35 100644 --- a/packages/rule/src/Rule.php +++ b/packages/rule/src/Rule.php @@ -3,28 +3,30 @@ namespace Squire; use Illuminate\Contracts\Validation; -use Illuminate\Support\Facades\Validator; +use Illuminate\Database\Eloquent\Builder; -class Rule implements Validation\Rule +abstract class Rule implements Validation\Rule { - protected $column = 'id'; + protected string $column = 'id'; - protected $message; + protected string $message; - public function __construct($column = null) + public function __construct(?string $column = null) { - if ($column) $this->column = $column; + if ($column) { + $this->column = $column; + } } - protected function getQueryBuilder() {} - - public function message() + public function message(): string { return __($this->message); } - public function passes($attribute, $value) + public function passes($attribute, $value): bool { return $this->getQueryBuilder()->where($this->column, $value)->exists(); } + + abstract protected function getQueryBuilder(): Builder; } \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml.dist similarity index 100% rename from phpunit.xml rename to phpunit.xml.dist diff --git a/tests/ModelTest.php b/tests/ModelTest.php index 457a49d..e2d6f60 100644 --- a/tests/ModelTest.php +++ b/tests/ModelTest.php @@ -3,34 +3,53 @@ namespace Squire\Tests; use Illuminate\Support\Facades\App; +use Squire\Models\Airline; +use Squire\Models\Airport; +use Squire\Models\Continent; +use Squire\Models\Country; use Squire\Models\Currency; +use Squire\Models\GbCounty; +use Squire\Models\Region; use Squire\Repository; use Squire\Tests\Models; class ModelTest extends TestCase { /** @test */ - public function can_query_models() + public function can_query_models(): void { - Repository::registerSource(Models\Foo::class, App::getLocale(), __DIR__.'/data/foo-en.csv'); + Repository::registerSource(Models\Foo::class, App::getLocale(), __DIR__ . '/data/foo-en.csv'); $this->assertEquals(2, Models\Foo::count()); $this->assertEquals('bar', Models\Foo::first()->foo); - $this->testModel(\Squire\Models\Airline::class); - $this->testModel(\Squire\Models\Airport::class); - $this->testModel(\Squire\Models\Continent::class); - $this->testModel(\Squire\Models\Country::class); - $this->testModel(\Squire\Models\Currency::class); - $this->testModel(\Squire\Models\GbCounty::class); - $this->testModel(\Squire\Models\Region::class); + $this->testModel(Airline::class); + $this->testModel(Airport::class); + $this->testModel(Continent::class); + $this->testModel(Country::class); + $this->testModel(Currency::class); + $this->testModel(GbCounty::class); + $this->testModel(Region::class); + } + + protected function testModel(string $model): void + { + $locales = array_keys(Repository::getSources($model)); + + foreach ($locales as $locale) { + App::setLocale($locale); + + $model::clearBootedModels(); + + $this->assertIsObject($model::all()); + } } /** @test */ - public function can_translate_models() + public function can_translate_models(): void { - Repository::registerSource(Models\Foo::class, 'en', __DIR__.'/data/foo-en.csv'); - Repository::registerSource(Models\Foo::class, 'es', __DIR__.'/data/foo-es.csv'); + Repository::registerSource(Models\Foo::class, 'en', __DIR__ . '/data/foo-en.csv'); + Repository::registerSource(Models\Foo::class, 'es', __DIR__ . '/data/foo-es.csv'); App::setLocale('en'); $this->assertEquals('en', Models\Foo::first()->lang); @@ -42,22 +61,9 @@ public function can_translate_models() } /** @test */ - public function can_format_usd() + public function can_format_usd(): void { $this->assertSame('$5.00', Currency::find('usd')->format(500)); $this->assertSame('$500.00', Currency::find('usd')->format(500, true)); } - - protected function testModel($model) - { - $locales = array_keys(Repository::getSources($model)); - - foreach ($locales as $locale) { - App::setLocale($locale); - - $model::clearBootedModels(); - - $this->assertIsObject($model::all()); - } - } } \ No newline at end of file diff --git a/tests/Models/Foo.php b/tests/Models/Foo.php index ced168a..7945e3b 100644 --- a/tests/Models/Foo.php +++ b/tests/Models/Foo.php @@ -6,7 +6,7 @@ class Foo extends Model { - public static $schema = [ + public static array $schema = [ 'foo' => 'string', 'lang' => 'string', ]; diff --git a/tests/RuleTest.php b/tests/RuleTest.php index 9dcc6b8..4d6c9c2 100644 --- a/tests/RuleTest.php +++ b/tests/RuleTest.php @@ -4,29 +4,43 @@ use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Validator; +use Squire\Models\Airline; +use Squire\Models\Airport; +use Squire\Models\Continent; +use Squire\Models\Country; +use Squire\Models\Currency; +use Squire\Models\GbCounty; +use Squire\Models\Region; use Squire\Repository; +use Squire\Rules\AirlineRule; +use Squire\Rules\AirportRule; +use Squire\Rules\ContinentRule; +use Squire\Rules\CountryRule; +use Squire\Rules\CurrencyRule; +use Squire\Rules\GbCountyRule; +use Squire\Rules\RegionRule; use Squire\Tests\Models; use Squire\Tests\Rules; class RuleTest extends TestCase { /** @test */ - public function can_be_validated() + public function can_be_validated(): void { - Repository::registerSource(Models\Foo::class, App::getLocale(), __DIR__.'/data/foo-en.csv'); + Repository::registerSource(Models\Foo::class, App::getLocale(), __DIR__ . '/data/foo-en.csv'); - $this->testRule(Rules\Foo::class, Models\Foo::class); + $this->testRule(Rules\FooRule::class, Models\Foo::class); - $this->testRule(\Squire\Rules\Airline::class, \Squire\Models\Airline::class); - $this->testRule(\Squire\Rules\Airport::class, \Squire\Models\Airport::class); - $this->testRule(\Squire\Rules\Continent::class, \Squire\Models\Continent::class); - $this->testRule(\Squire\Rules\Country::class, \Squire\Models\Country::class); - $this->testRule(\Squire\Rules\Currency::class, \Squire\Models\Currency::class); - $this->testRule(\Squire\Rules\GbCounty::class, \Squire\Models\GbCounty::class); - $this->testRule(\Squire\Rules\Region::class, \Squire\Models\Region::class); + $this->testRule(AirlineRule::class, Airline::class); + $this->testRule(AirportRule::class, Airport::class); + $this->testRule(ContinentRule::class, Continent::class); + $this->testRule(CountryRule::class, Country::class); + $this->testRule(CurrencyRule::class, Currency::class); + $this->testRule(GbCountyRule::class, GbCounty::class); + $this->testRule(RegionRule::class, Region::class); } - protected function testRule($rule, $model) + protected function testRule(string $rule, string $model): void { $primaryKey = array_keys($model::$schema)[0]; $secondaryKey = array_keys($model::$schema)[1]; diff --git a/tests/Rules/Foo.php b/tests/Rules/Foo.php deleted file mode 100644 index 75ca678..0000000 --- a/tests/Rules/Foo.php +++ /dev/null @@ -1,18 +0,0 @@ -