Passed
Push — master ( 136ed3...181ef2 )
by Bruno
03:16
created

ModelariumRenderableCommand   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 67
rs 10
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
B handle() 0 31 6
A __construct() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Modelarium\Laravel\Console\Commands;
4
5
use Formularium\Factory\DatatypeFactory;
6
use Formularium\Exception\Exception;
7
use HaydenPierce\ClassFinder\ClassFinder;
8
use Illuminate\Console\Command;
9
10
use function Safe\substr;
11
12
class ModelariumRenderableCommand extends Command
13
{
14
    /**
15
     * The name and signature of the console command.
16
     *
17
     * @var string
18
     */
19
    protected $signature = 'modelarium:renderable
20
        {name : The datatype name}
21
        {--framework=* : The frameworks to use. You can use this options several times. Use "*" for all.}
22
        {--namespace=App\\Frontend : path to save the file. Defaults to "App\\Frontend" }
23
        {--path= : base path of the namespace. Defaults to base_path("app/Frontend") }
24
    ';
25
26
    /**
27
     * The console command description.
28
     *
29
     * @var string
30
     */
31
    protected $description = 'Creates scaffolding using Modelarium';
32
33
    /**
34
     * Create a new command instance.
35
     *
36
     * @return void
37
     */
38
    public function __construct()
39
    {
40
        parent::__construct();
41
    }
42
43
    /**
44
     * Execute the console command.
45
     *
46
     * @return mixed
47
     */
48
    public function handle()
49
    {
50
        $name = $this->argument('name');
51
        if (!is_string($name)) {
52
            $this->error('Name must be a string');
53
            return;
54
        }
55
        $ns = $this->option('namespace');
56
        if (!is_string($ns)) {
0 ignored issues
show
introduced by
The condition is_string($ns) is always true.
Loading history...
57
            $this->error('Namespace must be a string');
58
            return;
59
        }
60
        $path = $this->option('path') ?: base_path("app/Frontend");
0 ignored issues
show
Bug introduced by
The function base_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

60
        $path = $this->option('path') ?: /** @scrutinizer ignore-call */ base_path("app/Frontend");
Loading history...
61
62
        if (!is_dir($path)) {
63
            \Safe\mkdir($path, 0777, true);
64
        }
65
66
        // call formularium
67
        $formulariumCall = $this->call('formularium:renderable', [
68
            'name' => $name,
69
            '--framework' => $this->option('framework'),
70
            '--namespace' => $ns,
71
            '--path' => $path,
72
        ]);
73
        if ($formulariumCall) {
74
            $this->error('Error calling formularium:renderable');
75
            return;
76
        }
77
78
        $this->info('You might want to run composer dump-autoload');
79
    }
80
}
81