Completed
Pull Request — master (#336)
by
unknown
01:48
created

MakeCrud   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 18 1
1
<?php
2
3
namespace App\Console\Commands;
4
5
use Artisan;
6
use Illuminate\Console\Command;
7
8
class MakeCrud extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'make:crud {name}';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Creates a new backpack crud';
23
24
    /**
25
     * Create a new command instance.
26
     *
27
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
28
     */
29
    public function __construct()
30
    {
31
        parent::__construct();
32
    }
33
34
    /**
35
     * Execute the console command.
36
     */
37
    public function handle()
38
    {
39
        $argument  = str_singular($this->argument('name'));
0 ignored issues
show
Bug introduced by
It seems like $this->argument('name') targeting Illuminate\Console\Command::argument() can also be of type array or null; however, str_singular() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
40
        $plural    = title_case(str_plural($argument));
41
        $snakeName = snake_case($argument);
42
        $camelName = camel_case($argument);
43
44
        $routeArgument   = sprintf("CRUD::resource('%s', '%sCrudController');", $snakeName, $camelName);
45
        $sidebarArgument = sprintf(
46
            "<li><a href='{{ backpack_url('%s') }}'><i class='fa fa-question-circle'></i> <span>%s</span></a></li>",
47
            $argument,
48
            $plural
49
        );
50
51
        Artisan::call('backpack:crud', ['name' => $snakeName]);
52
        Artisan::call('backpack:base:add-custom-route', ['code' => $routeArgument]);
53
        Artisan::call('backpack:base:add-sidebar-content', ['code' => $sidebarArgument]);
54
    }
55
}
56