MakeCRUD::createActions()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 10
nc 4
nop 3
dl 0
loc 16
rs 9.6111
c 0
b 0
f 0
1
<?php
2
3
namespace EasyPanel\Commands\Actions;
4
5
use Illuminate\Console\Command;
6
use Symfony\Component\Console\Exception\CommandNotFoundException;
7
use EasyPanel\Models\CRUD;
8
9
class MakeCRUD extends Command
10
{
11
12
    protected $signature = 'panel:crud {name?} {--f|force : Force mode}';
13
    protected $description = 'Create all action for CRUDs';
14
15
    public function handle()
16
    {
17
        $names = $this->argument('name') ?
18
            [$this->argument('name')] :
19
            CRUD::query()->where('active', true)->pluck('name')->toArray();
20
21
        if(is_null($names)) {
22
            throw new CommandNotFoundException("There is no action in config file");
23
        }
24
25
        foreach ($names as $name) {
26
            $args = ['name' => $name, '--force' => $this->option('force')];
27
            $instance = getCrudConfig($name);
28
29
            $this->createActions($instance, $name, $args);
30
        }
31
    }
32
33
    private function createActions($instance, $name, $args)
34
    {
35
        if (isset($instance->create) and $instance->create) {
36
            $this->call('panel:create', $args);
37
        } else {
38
            $this->warn("The create action is disabled for {$name}");
39
        }
40
41
        if (isset($instance->update) and $instance->update) {
42
            $this->call('panel:update', $args);
43
        } else {
44
            $this->warn("The update action is disabled for {$name}");
45
        }
46
47
        $this->call('panel:read', $args);
48
        $this->call('panel:single', $args);
49
    }
50
51
}
52