Skip to content

Commit

Permalink
Fix PHPStan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kpscyber committed Sep 28, 2024
1 parent a17633e commit b985ea0
Show file tree
Hide file tree
Showing 19 changed files with 81 additions and 139 deletions.
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
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@
}
],
"require": {
"php": "^8.1|^8.2",
"php": "^8.2|^8.3",
"illuminate/contracts": "^10.0|^11.0",
"illuminate/support": "^10.0|^11.0",
"laravel/pint": "^1.17",
"spatie/laravel-package-tools": "^1.9.2"
},
"require-dev": {
"nunomaduro/collision": "^6.0|^7.0",
"larastan/larastan": "^2.0.1",
"nunomaduro/collision": "^6.0|^7.0",
"orangehill/iseed": "^3.0",
"orchestra/testbench": "^8.0|^9.0",
"orchestra/testbench": "*",
"pestphp/pest": "^1.21",
"pestphp/pest-plugin-laravel": "^1.1",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.5",
"phpunit/phpunit": "^9.5|^10",
"spatie/laravel-ray": "^1.26"
},
"autoload": {
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);
}
};
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

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
12 changes: 6 additions & 6 deletions src/Models/District.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Soap\ThaiAddresses\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Soap\ThaiAddresses\Facades\ThaiAddresses;

class District extends Model
Expand All @@ -13,19 +15,17 @@ class District extends Model
'code',
];

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

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

public function province()
public function province(): BelongsTo
{
return $this->belongsTo(Province::class);
}

public function subdistricts()
public function subdistricts(): HasMany
{
return $this->hasMany(Subdistrict::class);
}
Expand Down
9 changes: 4 additions & 5 deletions src/Models/Geography.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Soap\ThaiAddresses\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Soap\ThaiAddresses\Facades\ThaiAddresses;

/**
Expand All @@ -16,14 +17,12 @@ class Geography extends Model
'name_en',
];

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

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

public function provinces()
public function provinces(): HasMany
{
return $this->hasMany(Province::class);
}
Expand Down
12 changes: 6 additions & 6 deletions src/Models/Province.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Soap\ThaiAddresses\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Soap\ThaiAddresses\Facades\ThaiAddresses;

class Province extends Model
Expand All @@ -13,19 +15,17 @@ class Province extends Model
'code',
];

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

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

public function geography()
public function geography(): BelongsTo
{
return $this->belongsTo(Geography::class);
}

public function districts()
public function districts(): HasMany
{
return $this->hasMany(District::class);
}
Expand Down
12 changes: 6 additions & 6 deletions src/Models/Subdistrict.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Soap\ThaiAddresses\Facades\ThaiAddresses;

class Subdistrict extends Model
Expand All @@ -16,19 +18,17 @@ class Subdistrict extends Model
'name_en',
];

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

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

public function district()
public function district(): BelongsTo
{
return $this->belongsTo(District::class);
}

public function addresses()
public function addresses(): HasMany
{
return $this->hasMany(Address::class);
}
Expand Down
Loading

0 comments on commit b985ea0

Please sign in to comment.