From 6de72a1e3240e37db977cadf9bb5d8fd6a1377df Mon Sep 17 00:00:00 2001 From: Craig Smith Date: Tue, 19 Jul 2022 16:43:31 +1200 Subject: [PATCH] feat: upgrade installation package --- .phpunit.result.cache | 1 + composer.json | 24 ++++++++---- config/{config.php => addressable.php} | 0 ...le.php => create_addresses_table.php.stub} | 4 +- phpstan-baseline.neon | 0 phpstan.neon.dist | 15 ++++++-- phpunit.xml.dist | 16 +------- src/AddressesServiceProvider.php | 37 +++++++------------ src/Models/Address.php | 35 +++++++++--------- tests/Feature/ServiceProviderTest.php | 4 +- 10 files changed, 67 insertions(+), 69 deletions(-) create mode 100644 .phpunit.result.cache rename config/{config.php => addressable.php} (100%) rename database/migrations/{2020_01_01_000001_create_addresses_table.php => create_addresses_table.php.stub} (96%) create mode 100644 phpstan-baseline.neon diff --git a/.phpunit.result.cache b/.phpunit.result.cache new file mode 100644 index 0000000..5200d64 --- /dev/null +++ b/.phpunit.result.cache @@ -0,0 +1 @@ +{"version":1,"defects":{"CustomD\\Addressable\\Tests\\Feature\\ServiceProviderTest::it_has_provides_method":4,"CustomD\\Addressable\\Tests\\Feature\\ServiceProviderTest::it_is_a_service_provider":4},"times":{"CustomD\\Addressable\\Tests\\Feature\\ServiceProviderTest::it_has_provides_method":0.233,"CustomD\\Addressable\\Tests\\Feature\\ServiceProviderTest::it_is_a_service_provider":0.016}} \ No newline at end of file diff --git a/composer.json b/composer.json index 8558119..2b2afb4 100755 --- a/composer.json +++ b/composer.json @@ -37,15 +37,21 @@ ], "require": { "php": "^8.0.0", - "illuminate/console": "^9.0.0 || ^10.0.0", - "illuminate/database": "^9.0.0 || ^10.0.0", - "illuminate/support": "^9.0.0 || ^10.0.0", + "illuminate/console": "^9.0.0", + "illuminate/database": "^9.0.0", + "illuminate/support": "^9.0.0", "jackpopp/geodistance": "^1.2.0", - "rinvex/countries": "^8.0.0" + "rinvex/countries": "^8.0.0", + "spatie/laravel-package-tools": "^1.9.2" }, "require-dev": { - "codedungeon/phpunit-result-printer": "^0.31.0", - "illuminate/container": "^9.0.0 || ^10.0.0", + "illuminate/container": "^9.0.0", + "nunomaduro/collision": "^6.0", + "nunomaduro/larastan": "^2.0.1", + "orchestra/testbench": "^7.0", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan-deprecation-rules": "^1.0", + "phpstan/phpstan-phpunit": "^1.0", "phpunit/phpunit": "^9.5.0" }, "autoload": { @@ -59,12 +65,16 @@ } }, "scripts": { + "analyse": "vendor/bin/phpstan analyse", "test": "vendor/bin/phpunit" }, "config": { "sort-packages": true, "preferred-install": "dist", - "optimize-autoloader": true + "optimize-autoloader": true, + "allow-plugins": { + "phpstan/extension-installer": true + } }, "extra": { "laravel": { diff --git a/config/config.php b/config/addressable.php similarity index 100% rename from config/config.php rename to config/addressable.php diff --git a/database/migrations/2020_01_01_000001_create_addresses_table.php b/database/migrations/create_addresses_table.php.stub similarity index 96% rename from database/migrations/2020_01_01_000001_create_addresses_table.php rename to database/migrations/create_addresses_table.php.stub index 39d22aa..320ba68 100755 --- a/database/migrations/2020_01_01_000001_create_addresses_table.php +++ b/database/migrations/create_addresses_table.php.stub @@ -6,7 +6,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; -class CreateAddressesTable extends Migration +return new class extends Migration { public function up() { @@ -35,4 +35,4 @@ public function down() { Schema::dropIfExists(config('addressable.tables.addresses')); } -} +}; diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..e69de29 diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 72e57f4..b4508a2 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,6 +1,13 @@ includes: -- ./vendor/nunomaduro/larastan/extension.neon + - phpstan-baseline.neon + parameters: - level: 5 - paths: - - src + level: 5 + paths: + - src + - config + - database + tmpDir: build/phpstan + checkOctaneCompatibility: true + checkModelProperties: true + checkMissingIterableValueType: false diff --git a/phpunit.xml.dist b/phpunit.xml.dist index cc17283..beefb5d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,18 +1,6 @@ - + + ./tests/Unit diff --git a/src/AddressesServiceProvider.php b/src/AddressesServiceProvider.php index a5d2010..4dc9a9f 100644 --- a/src/AddressesServiceProvider.php +++ b/src/AddressesServiceProvider.php @@ -5,36 +5,27 @@ namespace CustomD\Addressable; use CustomD\Addressable\Models\Address; -use Illuminate\Support\ServiceProvider; +use Spatie\LaravelPackageTools\Package; +use Spatie\LaravelPackageTools\PackageServiceProvider; -class AddressesServiceProvider extends ServiceProvider +class AddressesServiceProvider extends PackageServiceProvider { - /** - * {@inheritdoc} - */ - public function register() + public function configurePackage(Package $package): void { - // Merge config - $this->mergeConfigFrom(realpath(__DIR__.'/../../config/config.php'), 'addressable'); - $this->app->singleton('addressable.addresss', config('addressable.models.address')); - - if(config('addressable.models.address') !== Address::class) { - $this->app->alias('addressable.models.address', Address::class); - } + $package + ->name('addressable') + ->hasConfigFile() + ->hasMigration('create_addresses_table.php'); } - /** - * {@inheritdoc} - */ - public function boot() + public function packageRegistered() { - $this->publishes([ - __DIR__.'/../config/config.php' => config_path('addressable.php') - ], 'config'); - $this->publishes([ - __DIR__.'/../database/migrations/' => database_path('migrations') - ], 'migrations'); + $this->app->singleton('addressable.addresss', config('addressable.models.address')); + + if (config('addressable.models.address') !== Address::class) { + $this->app->alias('addressable.models.address', Address::class); + } } } diff --git a/src/Models/Address.php b/src/Models/Address.php index bc31ff2..c52e473 100755 --- a/src/Models/Address.php +++ b/src/Models/Address.php @@ -70,9 +70,6 @@ class Address extends Model use SoftDeletes; use GeoDistanceTrait; - protected $latColumn = 'latitude'; - - protected $lngColumn = 'longitude'; /** * {@inheritdoc} @@ -98,21 +95,21 @@ class Address extends Model * {@inheritdoc} */ protected $casts = [ - 'addressable_id' => 'integer', + 'addressable_id' => 'integer', 'addressable_type' => 'string', - 'label' => 'string', - 'given_name' => 'string', - 'family_name' => 'string', - 'organization' => 'string', - 'country_code' => 'string', - 'street' => 'string', - 'state' => 'string', - 'city' => 'string', - 'postal_code' => 'string', - 'latitude' => 'float', - 'longitude' => 'float', - 'is_primary' => 'boolean', - 'deleted_at' => 'datetime', + 'label' => 'string', + 'given_name' => 'string', + 'family_name' => 'string', + 'organization' => 'string', + 'country_code' => 'string', + 'street' => 'string', + 'state' => 'string', + 'city' => 'string', + 'postal_code' => 'string', + 'latitude' => 'float', + 'longitude' => 'float', + 'is_primary' => 'boolean', + 'deleted_at' => 'datetime', ]; /** @@ -139,6 +136,10 @@ public function __construct(array $attributes = []) { $this->setTable(config('addressable.tables.addresses')); + $this->latColumn = 'latitude'; + + $this->lngColumn = 'longitude'; + parent::__construct($attributes); } diff --git a/tests/Feature/ServiceProviderTest.php b/tests/Feature/ServiceProviderTest.php index 5742bce..1a8a7e2 100644 --- a/tests/Feature/ServiceProviderTest.php +++ b/tests/Feature/ServiceProviderTest.php @@ -5,10 +5,10 @@ namespace CustomD\Addressable\Tests\Feature; use ReflectionClass; -use PHPUnit\Framework\TestCase; +use Orchestra\Testbench\TestCase; use Illuminate\Container\Container; use Illuminate\Support\ServiceProvider; -use CustomD\Addressable\Providers\AddressesServiceProvider; +use CustomD\Addressable\AddressesServiceProvider; class ServiceProviderTest extends TestCase {