diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 16ca858..85581ff 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -1,18 +1,18 @@ -name: tests +name: phpstan on: push: branches: - main paths: - - **.php + - '**.php' - composer.json - .github/** pull_request: branches: - main paths: - - **.php + - '**.php' - composer.json - .github/** @@ -24,25 +24,25 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - php: [8.2, 8.3] + php: [8.2, 8.3, 8.4] laravel: ['10.*', '11.*', '12.*'] - dependency-version: [prefer-lowest, prefer-stable] + stability: [prefer-lowest, prefer-stable] include: - laravel: 10.* - testbench: 8.* - phpunit: 10.* + testbench: ^8.33 - laravel: 11.* - testbench: 9.* - phpunit: 11.* + testbench: ^9.0 - laravel: 12.* - testbench: 10.* - phpunit: '8.2' + testbench: ^10.0 + exclude: + - php: 8.4 + laravel: 10.* name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -59,7 +59,7 @@ jobs: - name: Install dependencies run: | - composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "phpunit/phpunit:${{ matrix.phpunit }}" --no-interaction --dev + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --dev composer update --${{ matrix.stability }} --prefer-dist --no-interaction - name: Validate composer.json and composer.lock diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index d835b21..aa75b77 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -5,14 +5,14 @@ on: branches: - main paths: - - **.php + - '**.php' - composer.json - .github/** pull_request: branches: - main paths: - - **.php + - '**.php' - composer.json - .github/** @@ -24,25 +24,25 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - php: [8.2, 8.3] + php: [8.2, 8.3, 8.4] laravel: ['10.*', '11.*', '12.*'] - dependency-version: [prefer-lowest, prefer-stable] + stability: [prefer-lowest, prefer-stable] include: - laravel: 10.* - testbench: 8.* - phpunit: 10.* + testbench: ^8.33 - laravel: 11.* - testbench: 9.* - phpunit: 11.* + testbench: ^9.0 - laravel: 12.* - testbench: 10.* - phpunit: '8.2' + testbench: ^10.0 + exclude: + - php: 8.4 + laravel: 10.* name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -59,7 +59,7 @@ jobs: - name: Install dependencies run: | - composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "phpunit/phpunit:${{ matrix.phpunit }}" --no-interaction --dev + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --dev composer update --${{ matrix.stability }} --prefer-dist --no-interaction - name: Validate composer.json and composer.lock diff --git a/.gitignore b/.gitignore index 5f33dd1..67ea2f9 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ testbench.yaml vendor node_modules .php-cs-fixer.cache +.phpunit.cache diff --git a/CHANGELOG.md b/CHANGELOG.md index a2b637b..4503b78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ All notable changes to `laravel-model-hashid` will be documented in this file. +## 2.5.0 - 2025-02-26 +* Add support for Laravel 12 by @laravel-shift in #30 +* Add support for PHP 8.4 by @frkcn in #31 ## 2.4.1 - 2023-08-04 * Str use path fixed in Generator.php by @frkcn in https://github.com/deligoez/laravel-model-hashid/pull/20 diff --git a/README.md b/README.md index bd6bc42..06ea107 100644 --- a/README.md +++ b/README.md @@ -78,13 +78,13 @@ You have complete control over your Hash Id length and style. Check out the conf The table below shows the compatibility across Laravel, PHP, and this package's **current version**. -| Package Version | Laravel version | PHP version | Compatible | -|-----------------|-----------------|-------------|------------| -| ^2.0 | 9.* , 10.* | 8.1.* | ✅ | -| ^1.0 | 8.* | 8.0.* | ✅ | -| | 8.* | 7.4.* | ❌ | -| | 8.* | 7.3.* | ❌ | -| | 7.x | * | ❌ | +| Package Version | Laravel version | PHP version | Compatible | +|-----------------|------------------------|---------------------------|------------| +| ^2.0 | 9.* , 10.*, 11.*, 12.* | 8.1.*, 8.2*, 8.3.*, 8.4.* | ✅ | +| ^1.0 | 8.* | 8.0.* | ✅ | +| | 8.* | 7.4.* | ❌ | +| | 8.* | 7.3.* | ❌ | +| | 7.x | * | ❌ | ## Installation diff --git a/composer.json b/composer.json index e0f67d5..405a88a 100644 --- a/composer.json +++ b/composer.json @@ -24,14 +24,15 @@ "source": "https://github.com/deligoez/laravel-model-hashid" }, "require": { - "php": "^8.2|^8.3", + "php": "^8.2|^8.3|^8.4", "ext-mbstring": "*", "hashids/hashids": "^4.1|^5.0", "illuminate/contracts": "^9.0|^10.0|^11.0|^12.0" }, "require-dev": { "laravel/pint": "^1.10", - "nunomaduro/larastan": "^2.4", + "nunomaduro/collision": "^7.0|^8.6", + "nunomaduro/larastan": "^2.4|^3.0", "orchestra/testbench": "^8.0|^9.0|^10.0", "phpstan/extension-installer": "^1.2", "phpstan/phpstan-deprecation-rules": "^1.1.1|^2.0", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 2540734..4a67650 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,5 @@ - + tests diff --git a/phpunit.xml.dist.bak b/phpunit.xml.dist.bak index e850722..4f7b790 100644 --- a/phpunit.xml.dist.bak +++ b/phpunit.xml.dist.bak @@ -1,39 +1,21 @@ - - - - tests - - - - - ./src - - - - - - - - - - + + + + tests + + + + + ./src + + + + + + + + + + diff --git a/src/LaravelModelHashIdServiceProvider.php b/src/LaravelModelHashIdServiceProvider.php index dbab6cf..2f981d9 100644 --- a/src/LaravelModelHashIdServiceProvider.php +++ b/src/LaravelModelHashIdServiceProvider.php @@ -49,12 +49,12 @@ public function register(): void */ protected function bootMixins(): void { - Builder::mixin(new FindByHashIdMixin()); - Builder::mixin(new FindManyByHashIdMixin()); - Builder::mixin(new FindOrFailByHashIdMixin()); - Builder::mixin(new FindOrByHashIdMixin()); - Builder::mixin(new FindOrNewByHashIdMixin()); - Builder::mixin(new WhereHashIdMixin()); - Builder::mixin(new WhereHashIdNotMixin()); + Builder::mixin(new FindByHashIdMixin); + Builder::mixin(new FindManyByHashIdMixin); + Builder::mixin(new FindOrFailByHashIdMixin); + Builder::mixin(new FindOrByHashIdMixin); + Builder::mixin(new FindOrNewByHashIdMixin); + Builder::mixin(new WhereHashIdMixin); + Builder::mixin(new WhereHashIdNotMixin); } } diff --git a/src/Support/Config.php b/src/Support/Config.php index f0be20d..d0a35a5 100644 --- a/src/Support/Config.php +++ b/src/Support/Config.php @@ -95,7 +95,7 @@ public static function checkIfParameterDefined(string $parameter): void public static function checkIfModelClassExist(Model|string $model): void { if (is_string($model) && !class_exists($model)) { - throw new ModelNotFoundException(); + throw new ModelNotFoundException; } } } diff --git a/src/Traits/HasHashId.php b/src/Traits/HasHashId.php index 23fa3c0..e15baa8 100644 --- a/src/Traits/HasHashId.php +++ b/src/Traits/HasHashId.php @@ -41,8 +41,6 @@ public function getHashIdAttribute(): ?string /** * Get the Raw Hash Id for the model. - * - * @return ?string */ public function getHashIdRawAttribute(): ?string { diff --git a/tests/Mixins/FindOrByHashIdMixinTest.php b/tests/Mixins/FindOrByHashIdMixinTest.php index 0d30caa..618b801 100644 --- a/tests/Mixins/FindOrByHashIdMixinTest.php +++ b/tests/Mixins/FindOrByHashIdMixinTest.php @@ -34,7 +34,7 @@ public function it_can_find_or_a_model_by_its_hash_id(): void // 2️⃣.2️⃣ Act 🏋🏻‍ ModelA::findOrByHashId($model->hashId, function (): void { - throw new RuntimeException(); + throw new RuntimeException; }); } @@ -59,7 +59,7 @@ public function it_can_find_or_fail_a_model_by_its_hash_id_from_specific_columns // 2️⃣.2️⃣ Act 🏋🏻‍ ModelA::findOrByHashId($model->hashId, function (): void { - throw new RuntimeException(); + throw new RuntimeException; }); } } diff --git a/tests/Support/HashIdModelConfigTest.php b/tests/Support/HashIdModelConfigTest.php index 6830d76..df5c9a8 100644 --- a/tests/Support/HashIdModelConfigTest.php +++ b/tests/Support/HashIdModelConfigTest.php @@ -98,7 +98,7 @@ public function it_can_get_specific_config_via_model_instance_or_class_name(): v Config::set(ConfigParameters::SEPARATOR, $modelSpecificSeparator, ModelA::class); // 2. Act 🏋🏻‍ - $modelSeparatorViaInstance = Config::get(ConfigParameters::SEPARATOR, new ModelA()); + $modelSeparatorViaInstance = Config::get(ConfigParameters::SEPARATOR, new ModelA); $modelSeparatorViaClassName = Config::get(ConfigParameters::SEPARATOR, ModelA::class); // 3. Assert ✅ diff --git a/tests/Support/ModelHashIdGeneratorTest.php b/tests/Support/ModelHashIdGeneratorTest.php index e02b2ed..a7ba1bc 100644 --- a/tests/Support/ModelHashIdGeneratorTest.php +++ b/tests/Support/ModelHashIdGeneratorTest.php @@ -25,7 +25,7 @@ class ModelHashIdGeneratorTest extends TestCase public function it_uses_default_prefix_logic_when_override_is_not_defined(): void { // 1. Arrange 🏗 - $model = new ModelA(); + $model = new ModelA; $prefixLength = $this->faker->numberBetween(1, mb_strlen(class_basename($model))); Config::set(ConfigParameters::PREFIX_LENGTH, $prefixLength, $model); @@ -68,7 +68,7 @@ public function it_can_use_a_defined_prefix_from_a_model_generator(): void public function it_can_set_prefix_length_for_a_model(): void { // 1. Arrange 🏗 - $model = new ModelA(); + $model = new ModelA; $prefixLength = $this->faker->numberBetween(1, mb_strlen(class_basename($model))); Config::set(ConfigParameters::PREFIX_LENGTH, $prefixLength, $model); @@ -83,7 +83,7 @@ public function it_can_set_prefix_length_for_a_model(): void public function prefix_length_will_be_the_length_of_class_name_if_prefix_length_is_under_zero(): void { // 1. Arrange 🏗 - $model = new ModelA(); + $model = new ModelA; $prefixLength = -1; Config::set(ConfigParameters::PREFIX_LENGTH, $prefixLength, $model); @@ -113,7 +113,7 @@ public function it_can_set_prefix_length_to_zero_and_prefix_to_empty(): void public function prefix_length_will_be_the_short_class_name_length_if_prefix_length_is_more_than_that(): void { // 1. Arrange 🏗 - $model = new ModelA(); + $model = new ModelA; $prefixLength = 10; Config::set(ConfigParameters::PREFIX_LENGTH, $prefixLength); $shortClassNameLength = mb_strlen(class_basename($model)); @@ -146,7 +146,7 @@ public function it_can_build_a_lower_case_prefix_from_a_model(): void Config::set(ConfigParameters::PREFIX_LENGTH, 6); Config::set(ConfigParameters::PREFIX_CASE, 'lower'); - $model = new ModelA(); + $model = new ModelA; // 2. Act 🏋🏻‍ $prefix = Generator::buildPrefixForModel($model); @@ -162,7 +162,7 @@ public function it_can_build_a_upper_case_prefix_from_a_model(): void Config::set(ConfigParameters::PREFIX_LENGTH, 6); Config::set(ConfigParameters::PREFIX_CASE, 'upper'); - $model = new ModelA(); + $model = new ModelA; // 2. Act 🏋🏻‍ $prefix = Generator::buildPrefixForModel($model); @@ -178,7 +178,7 @@ public function it_can_build_a_camel_case_prefix_from_a_model(): void Config::set(ConfigParameters::PREFIX_LENGTH, 6); Config::set(ConfigParameters::PREFIX_CASE, 'camel'); - $model = new ModelA(); + $model = new ModelA; // 2. Act 🏋🏻‍ $prefix = Generator::buildPrefixForModel($model); @@ -194,7 +194,7 @@ public function it_can_build_a_snake_case_prefix_from_a_model(): void Config::set(ConfigParameters::PREFIX_LENGTH, 6); Config::set(ConfigParameters::PREFIX_CASE, 'snake'); - $model = new ModelA(); + $model = new ModelA; // 2. Act 🏋🏻‍ $prefix = Generator::buildPrefixForModel($model); @@ -210,7 +210,7 @@ public function it_can_build_a_kebab_case_prefix_from_a_model(): void Config::set(ConfigParameters::PREFIX_LENGTH, 6); Config::set(ConfigParameters::PREFIX_CASE, 'kebab'); - $model = new ModelA(); + $model = new ModelA; // 2. Act 🏋🏻‍ $prefix = Generator::buildPrefixForModel($model); @@ -226,7 +226,7 @@ public function it_can_build_a_title_case_prefix_from_a_model(): void Config::set(ConfigParameters::PREFIX_LENGTH, 6); Config::set(ConfigParameters::PREFIX_CASE, 'title'); - $model = new ModelA(); + $model = new ModelA; // 2. Act 🏋🏻‍ $prefix = Generator::buildPrefixForModel($model); @@ -242,7 +242,7 @@ public function it_can_build_a_studly_case_prefix_from_a_model(): void Config::set(ConfigParameters::PREFIX_LENGTH, 6); Config::set(ConfigParameters::PREFIX_CASE, 'studly'); - $model = new ModelA(); + $model = new ModelA; // 2. Act 🏋🏻‍ $prefix = Generator::buildPrefixForModel($model); @@ -258,7 +258,7 @@ public function it_can_build_a_plural_studly_case_prefix_from_a_model(): void Config::set(ConfigParameters::PREFIX_LENGTH, 6); Config::set(ConfigParameters::PREFIX_CASE, 'plural_studly'); - $model = new ModelA(); + $model = new ModelA; // 2. Act 🏋🏻‍ $prefix = Generator::buildPrefixForModel($model); @@ -364,7 +364,7 @@ public function it_can_parse_a_model_hash_ids_into_parts(): void public function it_returns_null_if_model_does_not_have_a_key(): void { // 1. Arrange 🏗 - $model = new ModelA(); + $model = new ModelA; // 2. Act 🏋🏻‍ $hashIdForModel = Generator::forModel($model); @@ -377,7 +377,7 @@ public function it_returns_null_if_model_does_not_have_a_key(): void public function it_can_build_a_hash_id_generator_from_a_model_instance_or_class_name(): void { // 1. Arrange 🏗 - $model = new ModelA(); + $model = new ModelA; // 2. Act 🏋🏻‍ $generatorFromInstance = Generator::build($model); diff --git a/tests/TestCase.php b/tests/TestCase.php index e8a4b33..5df00b0 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -10,7 +10,7 @@ class TestCase extends Orchestra { - public function setUp(): void + protected function setUp(): void { parent::setUp(); diff --git a/tests/database/migrations/0000_00_00_000000_create_model_as_table.php b/tests/database/migrations/0000_00_00_000000_create_model_as_table.php index c228b74..992572d 100644 --- a/tests/database/migrations/0000_00_00_000000_create_model_as_table.php +++ b/tests/database/migrations/0000_00_00_000000_create_model_as_table.php @@ -6,7 +6,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; -return new class() extends Migration { +return new class extends Migration { public function up(): void { Schema::create('model_a_s', function (Blueprint $table): void { diff --git a/tests/database/migrations/0000_00_00_000001_create_model_bs_table.php b/tests/database/migrations/0000_00_00_000001_create_model_bs_table.php index 2916e1f..006d886 100644 --- a/tests/database/migrations/0000_00_00_000001_create_model_bs_table.php +++ b/tests/database/migrations/0000_00_00_000001_create_model_bs_table.php @@ -6,7 +6,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; -return new class() extends Migration { +return new class extends Migration { public function up(): void { Schema::create('model_b_s', function (Blueprint $table): void { diff --git a/tests/database/migrations/0000_00_00_000002_create_model_cs_table.php b/tests/database/migrations/0000_00_00_000002_create_model_cs_table.php index 3422915..f69dfae 100644 --- a/tests/database/migrations/0000_00_00_000002_create_model_cs_table.php +++ b/tests/database/migrations/0000_00_00_000002_create_model_cs_table.php @@ -6,7 +6,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; -return new class() extends Migration { +return new class extends Migration { public function up(): void { Schema::create('model_c_s', function (Blueprint $table): void { diff --git a/tests/database/migrations/0000_00_00_000003_create_model_ds_table.php b/tests/database/migrations/0000_00_00_000003_create_model_ds_table.php index 8052bcf..67ee708 100644 --- a/tests/database/migrations/0000_00_00_000003_create_model_ds_table.php +++ b/tests/database/migrations/0000_00_00_000003_create_model_ds_table.php @@ -6,7 +6,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; -return new class() extends Migration { +return new class extends Migration { public function up(): void { Schema::create('model_d_s', function (Blueprint $table): void {