MakeEntity::loadServices()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 0
cts 12
cp 0
rs 9.7666
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
namespace Webfactor\Laravel\Generators\Commands;
4
5
use Webfactor\Laravel\Generators\Contracts\CommandAbstract;
6
use Webfactor\Laravel\Generators\Contracts\ServiceInterface;
7
use Webfactor\Laravel\Generators\Schemas\Schema;
8
use Webfactor\Laravel\Generators\Services\AddToGitService;
9
use Webfactor\Laravel\Generators\Services\OpenIdeService;
10
11
class MakeEntity extends CommandAbstract
12
{
13
    /**
14
     * The name and signature of the console command.
15
     *
16
     * @var string
17
     */
18
    protected $signature = 'make:entity {entity} {--schema=name:string} {--migrate} {--git} {--ide=}';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Make Entity';
26
27
    /**
28
     * The Schema object.
29
     *
30
     * @var Schema
31
     */
32
    public $schema;
33
34
    /**
35
     * Execute the console command.
36
     *
37
     * @return mixed
38
     */
39
    public function handle()
40
    {
41
        $this->entity = $this->argument('entity');
42
43
        $this->loadSchema();
44
        $this->loadNaming();
45
        $this->loadServices();
46
    }
47
48
    private function loadSchema()
49
    {
50
        $this->info('Loading Schema');
51
        $this->schema = new Schema($this->option('schema'));
52
    }
53
54
    private function loadNaming()
55
    {
56
        $this->info('Loading Naming Classes');
57
58
        $namingClasses = config('webfactor.generators.naming');
59
        $count = count($namingClasses);
60
        $counter = 0;
61
62
        foreach ($namingClasses as $key => $naming) {
63
            $this->info(++$counter . '/' . $count . ' Naming Class: ' . $naming, 'v');
64
65
            $namingObject = new $naming($this->entity);
66
            $this->naming[$key] = $namingObject;
67
        }
68
69
        $this->line('');
70
    }
71
72
    private function loadServices()
73
    {
74
        $services = $this->getServicesToBeExecuted();
75
        $progressBar = $this->output->createProgressBar(count($services));
76
77
        foreach ($services as $k => $serviceClass) {
78
            $serviceInstance = new $serviceClass($this);
79
            $this->executeService($serviceInstance);
80
81
            $progressBar->advance();
82
            $this->info(' '.$serviceInstance->getConsoleOutput());
83
        }
84
85
        $this->line('');
86
    }
87
88
    private function getServicesToBeExecuted(): array
89
    {
90
        $serviceClassesToBeExecuted = config('webfactor.generators.services', []);
91
        array_push($serviceClassesToBeExecuted, OpenIdeService::class);
92
        array_push($serviceClassesToBeExecuted, AddToGitService::class);
93
94
        return $serviceClassesToBeExecuted;
95
    }
96
97
    private function executeService(ServiceInterface $service)
98
    {
99
        $service->call();
100
    }
101
}
102