Skip to content

Commit d7514da

Browse files
authored
Merge pull request #153 from RonasIT/149-remove-useless-makeEntityCommand-parts
refactor: remove useless
2 parents 70673ab + 88c27f5 commit d7514da

File tree

3 files changed

+18
-79
lines changed

3 files changed

+18
-79
lines changed

composer.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@
2929
"autoload": {
3030
"psr-4": {
3131
"RonasIT\\Support\\": "src/"
32-
},
33-
"files": [
34-
"src/helpers.php"
35-
]
32+
}
3633
},
3734
"autoload-dev": {
3835
"psr-4": {

src/Commands/MakeEntityCommand.php

Lines changed: 17 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
use Illuminate\Console\Command;
66
use Illuminate\Support\Arr;
77
use Illuminate\Support\Facades\Config;
8+
use Illuminate\Support\Facades\Event;
89
use Illuminate\Support\Str;
910
use RonasIT\Support\DTO\RelationsDTO;
1011
use RonasIT\Support\Events\SuccessCreateMessage;
1112
use RonasIT\Support\Events\WarningEvent;
1213
use RonasIT\Support\Exceptions\ClassNotExistsException;
13-
use RonasIT\Support\Exceptions\EntityCreateException;
14+
use Exception;
1415
use RonasIT\Support\Generators\ControllerGenerator;
1516
use RonasIT\Support\Generators\EntityGenerator;
1617
use RonasIT\Support\Generators\FactoryGenerator;
@@ -25,25 +26,8 @@
2526
use RonasIT\Support\Generators\TestsGenerator;
2627
use RonasIT\Support\Generators\TranslationsGenerator;
2728
use RonasIT\Support\Generators\SeederGenerator;
28-
use Illuminate\Contracts\Events\Dispatcher as EventDispatcher;
2929
use UnexpectedValueException;
3030

31-
/**
32-
* @property ControllerGenerator $controllerGenerator
33-
* @property MigrationGenerator $migrationGenerator
34-
* @property ModelGenerator $modelGenerator
35-
* @property RepositoryGenerator $repositoryGenerator
36-
* @property RequestsGenerator $requestsGenerator
37-
* @property ServiceGenerator $serviceGenerator
38-
* @property FactoryGenerator $factoryGenerator
39-
* @property TestsGenerator $testGenerator
40-
* @property TranslationsGenerator $translationsGenerator
41-
* @property SeederGenerator $seederGenerator
42-
* @property ResourceGenerator $resourceGenerator
43-
* @property NovaResourceGenerator $novaResourceGenerator
44-
* @property NovaTestGenerator $novaTestGenerator
45-
* @property EventDispatcher $eventDispatcher
46-
*/
4731
class MakeEntityCommand extends Command
4832
{
4933
const CRUD_OPTIONS = [
@@ -98,21 +82,6 @@ class MakeEntityCommand extends Command
9882
*/
9983
protected $description = 'Make entity with Model, Repository, Service, Migration, Controller, Resource and Nova Resource.';
10084

101-
protected $controllerGenerator;
102-
protected $migrationGenerator;
103-
protected $modelGenerator;
104-
protected $repositoryGenerator;
105-
protected $requestsGenerator;
106-
protected $serviceGenerator;
107-
protected $factoryGenerator;
108-
protected $testGenerator;
109-
protected $translationsGenerator;
110-
protected $seederGenerator;
111-
protected $resourceGenerator;
112-
protected $novaResourceGenerator;
113-
protected $novaTestGenerator;
114-
protected $eventDispatcher;
115-
11685
protected $rules = [
11786
'only' => [
11887
'only-api' => [ResourceGenerator::class, ControllerGenerator::class, RequestsGenerator::class, TestsGenerator::class],
@@ -139,26 +108,6 @@ class MakeEntityCommand extends Command
139108
NovaTestGenerator::class
140109
];
141110

142-
public function __construct()
143-
{
144-
parent::__construct();
145-
146-
$this->controllerGenerator = app(ControllerGenerator::class);
147-
$this->migrationGenerator = app(MigrationGenerator::class);
148-
$this->modelGenerator = app(ModelGenerator::class);
149-
$this->repositoryGenerator = app(RepositoryGenerator::class);
150-
$this->requestsGenerator = app(RequestsGenerator::class);
151-
$this->serviceGenerator = app(ServiceGenerator::class);
152-
$this->factoryGenerator = app(FactoryGenerator::class);
153-
$this->testGenerator = app(TestsGenerator::class);
154-
$this->translationsGenerator = app(TranslationsGenerator::class);
155-
$this->seederGenerator = app(SeederGenerator::class);
156-
$this->resourceGenerator = app(ResourceGenerator::class);
157-
$this->novaResourceGenerator = app(NovaResourceGenerator::class);
158-
$this->novaTestGenerator = app(NovaTestGenerator::class);
159-
$this->eventDispatcher = app(EventDispatcher::class);
160-
}
161-
162111
/**
163112
* Execute the console command.
164113
*
@@ -168,20 +117,11 @@ public function handle(): void
168117
{
169118
$this->validateInput();
170119
$this->checkConfigs();
171-
172-
$this->eventDispatcher->listen(
173-
events: SuccessCreateMessage::class,
174-
listener: fn (SuccessCreateMessage $event) => $this->info($event->message),
175-
);
176-
177-
$this->eventDispatcher->listen(
178-
events: WarningEvent::class,
179-
listener: fn (WarningEvent $event) => $this->warn($event->message),
180-
);
120+
$this->listenEvents();
181121

182122
try {
183123
$this->generate();
184-
} catch (EntityCreateException $e) {
124+
} catch (Exception $e) {
185125
$this->error($e->getMessage());
186126
}
187127
}
@@ -321,4 +261,17 @@ protected function validateOnlyApiOption()
321261
}
322262
}
323263
}
264+
265+
protected function listenEvents(): void
266+
{
267+
Event::listen(
268+
events: SuccessCreateMessage::class,
269+
listener: fn (SuccessCreateMessage $event) => $this->info($event->message),
270+
);
271+
272+
Event::listen(
273+
events: WarningEvent::class,
274+
listener: fn (WarningEvent $event) => $this->warn($event->message),
275+
);
276+
}
324277
}

src/helpers.php

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)