From 5ba0b9a29d8be365b7e2ff749cb8fa95dea090a3 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 20 Mar 2024 13:10:16 +0800 Subject: [PATCH 1/5] wip Signed-off-by: Mior Muhammad Zaki --- src/Console/Commander.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Console/Commander.php b/src/Console/Commander.php index 96609f2..b55ba24 100644 --- a/src/Console/Commander.php +++ b/src/Console/Commander.php @@ -50,7 +50,8 @@ public function laravel() Collection::make($kernel->all()) ->reject(static function (SymfonyCommand $command, string $name) { - return str_starts_with('make:', $name) || $command instanceof GeneratorCommand; + return $command instanceof GeneratorCommand + || $command instanceof MigrateMakeCommand; })->each(static function (SymfonyCommand $command) { $command->setHidden(true); }); From 31b1f338fb9d2f3c97ccbc62b27d3e5bf86a02e5 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 21 Mar 2024 22:41:18 +0800 Subject: [PATCH 2/5] wip Signed-off-by: Mior Muhammad Zaki --- composer.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 6e3c796..2732776 100644 --- a/composer.json +++ b/composer.json @@ -31,17 +31,17 @@ "php": "^8.1", "composer-runtime-api": "^2.2", "composer/semver": "^3.0", - "illuminate/console": "^10.42", - "illuminate/database": "^10.42", - "illuminate/filesystem": "^10.42", - "illuminate/support": "^10.42", + "illuminate/console": "^10.48.4", + "illuminate/database": "^10.48.4", + "illuminate/filesystem": "^10.48.4", + "illuminate/support": "^10.48.4", "orchestra/canvas-core": "^8.10.2", "orchestra/testbench-core": "^8.19", "symfony/polyfill-php83": "^1.28", "symfony/yaml": "^6.2" }, "require-dev": { - "laravel/framework": "^10.42", + "laravel/framework": "^10.48.4", "laravel/pint": "^1.6", "mockery/mockery": "^1.5.1", "phpstan/phpstan": "^1.10.56", From 785197d5a3d9217514cd14be6ca18182ad8019fe Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 18 Jun 2024 16:02:07 +0800 Subject: [PATCH 3/5] wip Signed-off-by: Mior Muhammad Zaki --- bin/sync | 1 + src/Console/stubs/user-model.stub | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/sync b/bin/sync index 2220240..7d8667a 100755 --- a/bin/sync +++ b/bin/sync @@ -73,6 +73,7 @@ Symfony\Component\Process\Process::fromShellCommandline( $files->copy("{$workingPath}/skeleton/app/Models/User.php", "{$workingPath}/src/Console/stubs/user-model.stub"); transform([ 'namespace App\Models;' => 'namespace {{ namespace }};', + ' use HasApiTokens, HasFactory, Notifiable;'.PHP_EOL => ' use HasFactory, Notifiable;'.PHP_EOL ], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/src/Console/stubs/user-model.stub")); $files->copy("{$workingPath}/skeleton/database/factories/UserFactory.php", "{$workingPath}/src/Console/stubs/user-factory.stub"); diff --git a/src/Console/stubs/user-model.stub b/src/Console/stubs/user-model.stub index e5fa8f9..0c6d668 100644 --- a/src/Console/stubs/user-model.stub +++ b/src/Console/stubs/user-model.stub @@ -10,7 +10,7 @@ use Laravel\Sanctum\HasApiTokens; class User extends Authenticatable { - use HasApiTokens, HasFactory, Notifiable; + use HasFactory, Notifiable; /** * The attributes that are mass assignable. From 12be2b7b433aa3d531d687bc2d69eed48fa3ea0d Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 18 Jun 2024 16:08:10 +0800 Subject: [PATCH 4/5] wip Signed-off-by: Mior Muhammad Zaki --- bin/sync | 1 - src/Console/UserModelMakeCommand.php | 25 +++++++++++++++++++ src/Console/stubs/user-model.stub | 2 +- .../Console/UserModelMakeCommandTest.php | 1 + 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/bin/sync b/bin/sync index 7d8667a..2220240 100755 --- a/bin/sync +++ b/bin/sync @@ -73,7 +73,6 @@ Symfony\Component\Process\Process::fromShellCommandline( $files->copy("{$workingPath}/skeleton/app/Models/User.php", "{$workingPath}/src/Console/stubs/user-model.stub"); transform([ 'namespace App\Models;' => 'namespace {{ namespace }};', - ' use HasApiTokens, HasFactory, Notifiable;'.PHP_EOL => ' use HasFactory, Notifiable;'.PHP_EOL ], fn ($changes) => $files->replaceInFile(array_keys($changes), array_values($changes), "{$workingPath}/src/Console/stubs/user-model.stub")); $files->copy("{$workingPath}/skeleton/database/factories/UserFactory.php", "{$workingPath}/src/Console/stubs/user-factory.stub"); diff --git a/src/Console/UserModelMakeCommand.php b/src/Console/UserModelMakeCommand.php index db02871..9f18e10 100644 --- a/src/Console/UserModelMakeCommand.php +++ b/src/Console/UserModelMakeCommand.php @@ -2,6 +2,7 @@ namespace Orchestra\Canvas\Console; +use Composer\InstalledVersions; use Orchestra\Canvas\Core\Commands\GeneratorCommand; use Orchestra\Canvas\Core\Concerns\ResolvesPresetStubs; use Symfony\Component\Console\Attribute\AsCommand; @@ -21,6 +22,30 @@ class UserModelMakeCommand extends GeneratorCommand */ protected $type = 'Model'; + /** + * Build the class with the given name. + * + * @param string $name + * @return string + * + * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException + */ + #[\Override] + protected function buildClass($name) + { + return transform(parent::buildClass($name), function ($stub) { + if (! InstalledVersions::isInstalled('laravel/sanctum')) { + $stub = str_replace( + ' use HasApiTokens, HasFactory, Notifiable;'.PHP_EOL, + ' use HasFactory, Notifiable;'.PHP_EOL, + $stub + ); + } + + return $stub; + }); + } + /** * Get the stub file for the generator. * diff --git a/src/Console/stubs/user-model.stub b/src/Console/stubs/user-model.stub index 0c6d668..e5fa8f9 100644 --- a/src/Console/stubs/user-model.stub +++ b/src/Console/stubs/user-model.stub @@ -10,7 +10,7 @@ use Laravel\Sanctum\HasApiTokens; class User extends Authenticatable { - use HasFactory, Notifiable; + use HasApiTokens, HasFactory, Notifiable; /** * The attributes that are mass assignable. diff --git a/tests/Feature/Console/UserModelMakeCommandTest.php b/tests/Feature/Console/UserModelMakeCommandTest.php index b108006..a920379 100644 --- a/tests/Feature/Console/UserModelMakeCommandTest.php +++ b/tests/Feature/Console/UserModelMakeCommandTest.php @@ -21,6 +21,7 @@ public function it_can_generate_broadcasting_channel_file() 'namespace App\Models;', 'use Illuminate\Foundation\Auth\User as Authenticatable;', 'class User extends Authenticatable', + 'use HasFactory, Notifiable;', ], 'app/Models/User.php'); } } From 9bed1ce6084af2ce166e9ea1cb160ff22dc94a6d Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 18 Jun 2024 16:26:09 +0800 Subject: [PATCH 5/5] wip Signed-off-by: Mior Muhammad Zaki --- composer.json | 2 +- phpstan.neon.dist | 2 +- src/Console/UserModelMakeCommand.php | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index 2732776..925c58d 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "laravel/framework": "^10.48.4", "laravel/pint": "^1.6", "mockery/mockery": "^1.5.1", - "phpstan/phpstan": "^1.10.56", + "phpstan/phpstan": "^1.11", "phpunit/phpunit": "^10.5", "spatie/laravel-ray": "^1.33" }, diff --git a/phpstan.neon.dist b/phpstan.neon.dist index ee5e627..6fb4891 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -15,8 +15,8 @@ parameters: level: 7 ignoreErrors: + - identifier: missingType.generics - '#Method [a-zA-Z\\\<\>]+::handle\(\) should return bool\|null but returns int.#' - checkGenericClassInNonGenericObjectType: false checkMissingIterableValueType: false treatPhpDocTypesAsCertain: false diff --git a/src/Console/UserModelMakeCommand.php b/src/Console/UserModelMakeCommand.php index 9f18e10..75ebc7d 100644 --- a/src/Console/UserModelMakeCommand.php +++ b/src/Console/UserModelMakeCommand.php @@ -33,17 +33,17 @@ class UserModelMakeCommand extends GeneratorCommand #[\Override] protected function buildClass($name) { - return transform(parent::buildClass($name), function ($stub) { - if (! InstalledVersions::isInstalled('laravel/sanctum')) { - $stub = str_replace( - ' use HasApiTokens, HasFactory, Notifiable;'.PHP_EOL, - ' use HasFactory, Notifiable;'.PHP_EOL, - $stub - ); - } + $stub = parent::buildClass($name); - return $stub; - }); + if (! InstalledVersions::isInstalled('laravel/sanctum')) { + $stub = str_replace( + ' use HasApiTokens, HasFactory, Notifiable;'.PHP_EOL, + ' use HasFactory, Notifiable;'.PHP_EOL, + $stub + ); + } + + return $stub; } /**