Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PHPStan errors #23

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [8.2]
php: [8.2, 8.3]
laravel: [10.*, 11.*]
stability: [prefer-stable]
include:
Expand Down
1 change: 1 addition & 0 deletions .phpunit.cache/test-results
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":"pest_2.36.0","defects":[],"times":{"P\\Tests\\Feature\\UserTest::__pest_evaluable_user_can_have_address":0.097,"P\\Tests\\Unit\\DatabaseSeederTest::__pest_evaluable_seeder_command_is_working":0.092,"P\\Tests\\Unit\\DatabaseSeederTest::__pest_evaluable_seeder_commands_are_working":0.08}}
53 changes: 36 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,24 @@
}
],
"require": {
"php": "^8.1|^8.2",
"illuminate/contracts": "^10.0|^11.0",
"illuminate/support": "^10.0|^11.0",
"laravel/pint": "^1.17",
"spatie/laravel-package-tools": "^1.9.2"
"php": "^8.2|^8.3",
"illuminate/contracts": "^10.0||^11.0",
"illuminate/support": "^10.0||^11.0",
"spatie/laravel-package-tools": "^1.16"
},
"require-dev": {
"nunomaduro/collision": "^6.0|^7.0",
"larastan/larastan": "^2.0.1",
"larastan/larastan": "^2.9",
"laravel/pint": "^1.17",
"nunomaduro/collision": "^8.1.1|^7.10",
"orangehill/iseed": "^3.0",
"orchestra/testbench": "^8.0|^9.0",
"pestphp/pest": "^1.21",
"pestphp/pest-plugin-laravel": "^1.1",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"orchestra/testbench": "^8.22||^9.0",
"pestphp/pest": "^2.34",
"pestphp/pest-plugin-arch": "^2.7",
"pestphp/pest-plugin-drift": "^2.6",
"pestphp/pest-plugin-laravel": "^2.3",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan-deprecation-rules": "^1.1",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.5",
"spatie/laravel-ray": "^1.26"
},
"autoload": {
Expand All @@ -48,14 +49,32 @@
},
"autoload-dev": {
"psr-4": {
"Soap\\ThaiAddresses\\Tests\\": "tests/src",
"Soap\\ThaiAddresses\\Tests\\Database\\": "tests/database"
"Soap\\ThaiAddresses\\Tests\\": "tests",
"Workbench\\App\\": "workbench/app/",
"Workbench\\Database\\Factories\\": "workbench/database/factories/",
"Workbench\\Database\\Seeders\\": "workbench/database/seeders/"
}
},
"scripts": {
"analyse": "vendor/bin/phpstan analyse",
"test": "vendor/bin/pest",
"test-coverage": "vendor/bin/pest --coverage"
"test-coverage": "vendor/bin/pest --coverage",
"post-autoload-dump": [
"@clear",
"@prepare"
],
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
"prepare": "@php vendor/bin/testbench package:discover --ansi",
"build": "@php vendor/bin/testbench workbench:build --ansi",
"serve": [
"Composer\\Config::disableProcessTimeout",
"@build",
"@php vendor/bin/testbench serve --ansi"
],
"lint": [
"@php vendor/bin/pint --ansi",
"@php vendor/bin/phpstan analyse --verbose --ansi"
]
},
"config": {
"sort-packages": true,
Expand All @@ -70,7 +89,7 @@
"Soap\\ThaiAddresses\\ThaiAddressesServiceProvider"
],
"aliases": {
"ThaiProvinces": "Soap\\ThaiAddresses\\Facades\\ThaiAddresses"
"ThaiAddresses": "Soap\\ThaiAddresses\\Facades\\ThaiAddresses"
}
}
},
Expand Down
7 changes: 4 additions & 3 deletions database/migrations/create_addresses_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
{
public function up()
{
Schema::create(ThaiAddresses::getAddressTableName(), function (Blueprint $table) {
// Columns
$table = ThaiAddresses::getAddressTableName();
Schema::create($table, function (Blueprint $table) {
$table->id('id');
$table->morphs('addressable');

Expand All @@ -36,6 +36,7 @@ public function up()

public function down()
{
Schema::dropIfExists(ThaiAddresses::getAddressTableName());
$table = ThaiAddresses::getAddressTableName();
Schema::dropIfExists($table);
}
};
6 changes: 4 additions & 2 deletions database/migrations/create_thai_districts_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
{
public function up()
{
Schema::create(ThaiAddresses::getDistrictTableName(), function (Blueprint $table) {
$table = ThaiAddresses::getDistrictTableName();
Schema::create($table, function (Blueprint $table) {
$table->id();

// add fields
Expand All @@ -24,6 +25,7 @@ public function up()

public function down()
{
Schema::dropIfExists(ThaiAddresses::getDistrictTableName());
$table = ThaiAddresses::getDistrictTableName();
Schema::dropIfExists($table);
}
};
8 changes: 4 additions & 4 deletions database/migrations/create_thai_geographies_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
{
public function up()
{
Schema::create(ThaiAddresses::getGeographyTableName(), function (Blueprint $table) {
$table = ThaiAddresses::getGeographyTableName();
Schema::create($table, function (Blueprint $table) {
$table->id();

// add fields

$table->string('name_en');
$table->string('name_th');
$table->timestamps();
Expand All @@ -22,6 +21,7 @@ public function up()

public function down()
{
Schema::dropIfExists(ThaiAddresses::getGeographyTableName());
$table = ThaiAddresses::getGeographyTableName();
Schema::dropIfExists($table);
}
};
6 changes: 4 additions & 2 deletions database/migrations/create_thai_provinces_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
{
public function up()
{
Schema::create(ThaiAddresses::getProvinceTableName(), function (Blueprint $table) {
$table = ThaiAddresses::getProvinceTableName();
Schema::create($table, function (Blueprint $table) {

$table->id();
// add fields
Expand All @@ -23,6 +24,7 @@ public function up()

public function down()
{
Schema::dropIfExists(ThaiAddresses::getProvinceTableName());
$table = ThaiAddresses::getProvinceTableName();
Schema::dropIfExists($table);
}
};
8 changes: 4 additions & 4 deletions database/migrations/create_thai_subdistricts_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
{
public function up()
{
Schema::create(ThaiAddresses::getSubdistrictTableName(), function (Blueprint $table) {
$table = ThaiAddresses::getSubdistrictTableName();
Schema::create($table, function (Blueprint $table) {
$table->id();

// add fields
$table->string('zip_code');
$table->string('name_th');
$table->string('name_en');
Expand All @@ -24,6 +23,7 @@ public function up()

public function down()
{
Schema::dropIfExists(ThaiAddresses::getSubdistrictTableName());
$table = ThaiAddresses::getSubdistrictTableName();
Schema::dropIfExists($table);
}
};
6 changes: 5 additions & 1 deletion database/seeders/DistrictSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ class DistrictSeeder extends Seeder
public function run()
{
District::query()->delete();
$json = File::get(base_path('vendor/soap/thai-addresses/database/seeders/data/districts.json'));
if (File::exists(base_path('vendor/soap/thai-addresses/database/seeders/data/districts.json'))) {
$json = File::get(base_path('vendor/soap/thai-addresses/database/seeders/data/districts.json'));
} else {
$json = File::get(realpath('database/seeders/data/districts.json'));
}
$districts = json_decode($json);

foreach ($districts as $item) {
Expand Down
6 changes: 5 additions & 1 deletion database/seeders/GeographySeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ class GeographySeeder extends Seeder
public function run()
{
Geography::query()->delete();
$json = File::get(base_path('vendor/soap/thai-addresses/database/seeders/data/geographies.json'));
if (File::exists(base_path('/vendor/soap/thai-addresses/database/seeders/data/geographies.json'))) {
$json = File::get(base_path('/vendor/soap/thai-addresses/database/seeders/data/geographies.json'));
} else {
$json = File::get(__DIR__.'/data/geographies.json');
}
$geographies = json_decode($json);

foreach ($geographies as $item) {
Expand Down
7 changes: 6 additions & 1 deletion database/seeders/ProvinceSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ class ProvinceSeeder extends Seeder
public function run()
{
Province::query()->delete();
$json = File::get(base_path('vendor/soap/thai-addresses/database/seeders/data/provinces.json'));
if (File::exists(base_path('/vendor/soap/thai-addresses/database/seeders/data/provinces.json'))) {
$json = File::get(base_path('/vendor/soap/thai-addresses/database/seeders/data/provinces.json'));
} else {
$json = File::get(__DIR__.'/data/provinces.json');
}

$provinces = json_decode($json);

foreach ($provinces as $item) {
Expand Down
7 changes: 6 additions & 1 deletion database/seeders/SubdistrictSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ class SubdistrictSeeder extends Seeder
public function run()
{
Subdistrict::query()->delete();
$json = File::get(base_path('vendor/soap/thai-addresses/database/seeders/data/subdistricts.json'));
if (File::exists(base_path('/vendor/soap/thai-addresses/database/seeders/data/subdistricts.json'))) {
$json = File::get(base_path('/vendor/soap/thai-addresses/database/seeders/data/subdistricts.json'));
} else {
$json = File::get(__DIR__.'/data/subdistricts.json');
}

$subdistricts = json_decode($json);

foreach ($subdistricts as $item) {
Expand Down
3 changes: 1 addition & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ includes:
- phpstan-baseline.neon

parameters:
level: 4
level: 5
paths:
- src
- config
- database
tmpDir: build/phpstan
checkOctaneCompatibility: true
checkModelProperties: true
checkMissingIterableValueType: false

69 changes: 28 additions & 41 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,43 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true"
verbose="true"
>
<testsuites>
<testsuite name="Soap Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<php>
<env name="DB_CONNECTION" value="testing"/>
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/>
</php>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" executionOrder="random" failOnWarning="true" failOnRisky="true" failOnEmptyTestSuite="true" beStrictAboutOutputDuringTests="true" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Unit Test Suite">
<directory>tests/Unit</directory>
</testsuite>
<testsuite name="Feature Test Suite">
<directory>tests/Feature</directory>
</testsuite>
</testsuites>
<coverage>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<php>
<env name="DB_CONNECTION" value="testing"/>
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/>
</php>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
8 changes: 3 additions & 5 deletions src/Facades/ThaiAddresses.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@
use Illuminate\Support\Facades\Facade;

/**
* @see \Soap\ThaiProvinces\ThaiProvinces
* @see \Soap\ThaiProvinces\ThaiAddesses
*/
class ThaiAddresses extends Facade
{
/**
* Alias of dynamic class, need to be registered in service provider
*
* @return string
*/
protected static function getFacadeAccessor()
protected static function getFacadeAccessor(): string
{
return 'thai-addresses';
return \Soap\ThaiAddresses\ThaiAddresses::class;
}
}
11 changes: 3 additions & 8 deletions src/Models/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ class Address extends Model
'deleted_at' => 'datetime',
];

public function __construct(array $attributes = [])
public function getTable()
{
parent::__construct($attributes);

$this->table = ThaiAddresses::getAddressTableName();
return ThaiAddresses::getAddressTableName();
}

/**
Expand All @@ -63,10 +61,7 @@ public function addressable(): MorphTo
return $this->morphTo('addressable', 'addressable_type', 'addressable_id', 'id');
}

/**
* @return BelongsTo
*/
public function subdistrict()
public function subdistrict(): BelongsTo
{
return $this->belongsTo(Subdistrict::class);
}
Expand Down
Loading
Loading