Skip to content

Commit

Permalink
Support Laravel 11, drop doctrine/dbal, replace soyhuce/classmap-gene…
Browse files Browse the repository at this point in the history
…rator with composer/class-map-generator
  • Loading branch information
bastien-phi committed Feb 16, 2024
1 parent b56c61e commit fea639d
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 25 deletions.
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/Domain/Factories/Actions/FindFactories.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/Domain/Macros/Actions/FindMacroableClasses.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/Domain/Models/Actions/FindModels.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 12 additions & 15 deletions src/Domain/Models/Actions/ResolveModelAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand All @@ -29,20 +30,16 @@ public function execute(Model $model): void
}

/**
* @return array<\Doctrine\DBAL\Schema\Column>
* @return array<Column>
*/
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
Expand Down
1 change: 1 addition & 0 deletions src/Domain/Models/AttributeTypeCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ private function resolveFromDatabaseType(Attribute $attribute): string
{
return match (Str::lower($attribute->type)) {
'char',
'varchar',
'string',
'text',
'mediumtext',
Expand Down
3 changes: 3 additions & 0 deletions tests/Feature/AliasesCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down
4 changes: 4 additions & 0 deletions tests/expected/_ide_aliases.stub
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ namespace
{
}

class Schedule extends \Illuminate\Support\Facades\Schedule
{
}

class Schema extends \Illuminate\Support\Facades\Schema
{
}
Expand Down

0 comments on commit fea639d

Please sign in to comment.