diff --git a/composer.json b/composer.json index 86f2226..720a638 100644 --- a/composer.json +++ b/composer.json @@ -20,18 +20,18 @@ "require": { "php": "^8.2", "doctrine/dbal": "^3.5.1", - "illuminate/console": "^10.0", - "illuminate/database": "^10.0", - "illuminate/support": "^10.0", - "illuminate/view": "^10.0", + "illuminate/console": "^10.0||^11.0", + "illuminate/database": "^10.0||^11.0", + "illuminate/support": "^10.0||^11.0", + "illuminate/view": "^10.0||^11.0", "spatie/laravel-package-tools": "^1.9.2", - "soyhuce/classmap-generator": "^1.0" + "composer/class-map-generator": "^1.1" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.6", - "nunomaduro/collision": "^7.10", + "nunomaduro/collision": "^7.10||^8.0", "nunomaduro/larastan": "^2.0.1", - "orchestra/testbench": "^8.0", + "orchestra/testbench": "^8.0||^9.0", "pestphp/pest": "^2.24", "pestphp/pest-plugin-laravel": "^2.2", "phpstan/extension-installer": "^1.1", diff --git a/src/Domain/Factories/Actions/FindFactories.php b/src/Domain/Factories/Actions/FindFactories.php index eecfc7f..f0230a0 100644 --- a/src/Domain/Factories/Actions/FindFactories.php +++ b/src/Domain/Factories/Actions/FindFactories.php @@ -2,10 +2,10 @@ namespace Soyhuce\NextIdeHelper\Domain\Factories\Actions; +use Composer\ClassMapGenerator\ClassMapGenerator; use Illuminate\Database\Eloquent\Factories\Factory as EloquentFactory; use Illuminate\Support\Collection; use ReflectionClass; -use Soyhuce\ClassMapGenerator\ClassMapGenerator; use Soyhuce\NextIdeHelper\Domain\Factories\Entities\Factory; use Soyhuce\NextIdeHelper\Exceptions\DirectoryDoesNotExist; diff --git a/src/Domain/Macros/Actions/FindMacroableClasses.php b/src/Domain/Macros/Actions/FindMacroableClasses.php index b3124b0..611f53c 100644 --- a/src/Domain/Macros/Actions/FindMacroableClasses.php +++ b/src/Domain/Macros/Actions/FindMacroableClasses.php @@ -2,10 +2,10 @@ namespace Soyhuce\NextIdeHelper\Domain\Macros\Actions; +use Composer\ClassMapGenerator\ClassMapGenerator; use Illuminate\Support\Collection; use Illuminate\Support\Traits\Macroable; use ReflectionClass; -use Soyhuce\ClassMapGenerator\ClassMapGenerator; use Soyhuce\NextIdeHelper\Exceptions\DirectoryDoesNotExist; use function in_array; diff --git a/src/Domain/Models/Actions/FindModels.php b/src/Domain/Models/Actions/FindModels.php index fdbf8f8..13a8a4c 100644 --- a/src/Domain/Models/Actions/FindModels.php +++ b/src/Domain/Models/Actions/FindModels.php @@ -2,9 +2,9 @@ namespace Soyhuce\NextIdeHelper\Domain\Models\Actions; +use Composer\ClassMapGenerator\ClassMapGenerator; use Illuminate\Database\Eloquent\Model as EloquentModel; use ReflectionClass; -use Soyhuce\ClassMapGenerator\ClassMapGenerator; use Soyhuce\NextIdeHelper\Domain\Models\Collections\ModelCollection; use Soyhuce\NextIdeHelper\Domain\Models\Entities\Model; use Soyhuce\NextIdeHelper\Exceptions\DirectoryDoesNotExist; diff --git a/src/Domain/Models/Actions/ResolveModelAttributes.php b/src/Domain/Models/Actions/ResolveModelAttributes.php index 54029a4..a7dbff8 100644 --- a/src/Domain/Models/Actions/ResolveModelAttributes.php +++ b/src/Domain/Models/Actions/ResolveModelAttributes.php @@ -2,13 +2,14 @@ namespace Soyhuce\NextIdeHelper\Domain\Models\Actions; -use Doctrine\DBAL\Exception as DBalException; -use Doctrine\DBAL\Types\Type; use Soyhuce\NextIdeHelper\Contracts\ModelResolver; use Soyhuce\NextIdeHelper\Domain\Models\AttributeTypeCaster; use Soyhuce\NextIdeHelper\Domain\Models\Entities\Attribute; use Soyhuce\NextIdeHelper\Domain\Models\Entities\Model; +/** + * @phpstan-type Column array{name: string, type_name: string, nullable: bool} + */ class ResolveModelAttributes implements ModelResolver { public function execute(Model $model): void @@ -17,9 +18,9 @@ public function execute(Model $model): void $typeCaster = new AttributeTypeCaster($model); foreach ($columns as $column) { - $attribute = new Attribute($column->getName(), Type::getTypeRegistry()->lookupName($column->getType())); + $attribute = new Attribute($column['name'], $column['type_name']); $attribute->inDatabase = true; - if (!$column->getNotnull() && !$this->isLaravelTimestamp($model, $attribute)) { + if ($column['nullable'] && !$this->isLaravelTimestamp($model, $attribute)) { $attribute->nullable = true; $attribute->nullableInDatabase = true; } @@ -29,20 +30,16 @@ public function execute(Model $model): void } /** - * @return array<\Doctrine\DBAL\Schema\Column> + * @return array */ private function resolveColumns(Model $model): array { - $table = $model->instance()->getConnection()->getTablePrefix() . $model->instance()->getTable(); - - try { - return $model->instance() - ->getConnection() - ->getDoctrineSchemaManager() - ->listTableColumns($table); - } catch (DBalException) { - return []; - } + $model->instance()->getTable(); + + return $model->instance() + ->getConnection() + ->getSchemaBuilder() + ->getColumns($model->instance()->getTable()); } private function isLaravelTimestamp(Model $model, Attribute $attribute): bool diff --git a/src/Domain/Models/AttributeTypeCaster.php b/src/Domain/Models/AttributeTypeCaster.php index f0afdde..b8d580c 100644 --- a/src/Domain/Models/AttributeTypeCaster.php +++ b/src/Domain/Models/AttributeTypeCaster.php @@ -117,6 +117,7 @@ private function resolveFromDatabaseType(Attribute $attribute): string { return match (Str::lower($attribute->type)) { 'char', + 'varchar', 'string', 'text', 'mediumtext', diff --git a/tests/Feature/AliasesCommandTest.php b/tests/Feature/AliasesCommandTest.php index fc9f989..1dc94ce 100644 --- a/tests/Feature/AliasesCommandTest.php +++ b/tests/Feature/AliasesCommandTest.php @@ -25,6 +25,9 @@ public function theCommandIsSuccessful(): void if (config('app.aliases.Number') === null) { AliasLoader::getInstance(['Number' => \Illuminate\Support\Number::class]); } + if (config('app.aliases.Schedule') === null) { + AliasLoader::getInstance(['Schedule' => \Illuminate\Support\Facades\Schedule::class]); + } config([ 'next-ide-helper.aliases' => [ diff --git a/tests/expected/_ide_aliases.stub b/tests/expected/_ide_aliases.stub index 74523ca..8b1a0af 100644 --- a/tests/expected/_ide_aliases.stub +++ b/tests/expected/_ide_aliases.stub @@ -138,6 +138,10 @@ namespace { } + class Schedule extends \Illuminate\Support\Facades\Schedule + { + } + class Schema extends \Illuminate\Support\Facades\Schema { }