Artisan   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 3
dl 0
loc 93
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A handle() 0 14 2
A forceCommand() 0 8 5
A getOptions() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Console\Console\Commands;
6
7
use InvalidArgumentException;
8
use Illuminate\Console\Command;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Input\StringInput;
11
use Illuminate\Contracts\Console\Kernel as ArtisanContract;
12
13
class Artisan extends Command
14
{
15
    /**
16
     * The console command name.
17
     *
18
     * @var string
19
     */
20
    protected $name = 'artisan';
21
22
    /**
23
     * The console command description.
24
     *
25
     * @var string
26
     */
27
    protected $description = 'Laravel Artisan';
28
29
    /**
30
     * no support array.
31
     *
32
     * @var array
33
     */
34
    protected $notSupport = [
35
        'down' => '',
36
        'tinker' => '',
37
    ];
38
39
    /**
40
     * $artisan.
41
     *
42
     * @var \Illuminate\Contracts\Console\Kernel
43
     */
44
    protected $artisan;
45
46
    /**
47
     * __construct.
48
     *
49
     * @param \Illuminate\Contracts\Console\Kernel $artisan
50
     */
51
    public function __construct(ArtisanContract $artisan)
52
    {
53
        parent::__construct();
54
55
        $this->artisan = $artisan;
56
    }
57
58
    /**
59
     * handle.
60
     *
61
     * @throws \InvalidArgumentException
62
     */
63
    public function handle()
64
    {
65
        $command = $this->forceCommand($this->option('command'));
66
67
        $input = new StringInput($command);
68
69
        $input->setInteractive(false);
70
71
        if (isset($this->notSupport[$input->getFirstArgument()]) === true) {
72
            throw new InvalidArgumentException('Command "'.$command.'" is not supported');
73
        }
74
75
        $this->artisan->handle($input, $this->getOutput());
76
    }
77
78
    /**
79
     * need focre option.
80
     *
81
     * @param string $command
82
     *
83
     * @return string
84
     */
85
    protected function forceCommand($command): string
86
    {
87
        return (
88
            starts_with($command, 'migrate') === true && starts_with($command, 'migrate:status') === false ||
0 ignored issues
show
Deprecated Code introduced by
The function starts_with() has been deprecated with message: Str::startsWith() should be used directly instead. Will be removed in Laravel 6.0.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
89
            starts_with($command, 'db:seed') === true
0 ignored issues
show
Deprecated Code introduced by
The function starts_with() has been deprecated with message: Str::startsWith() should be used directly instead. Will be removed in Laravel 6.0.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
90
        ) && mb_strpos('command', '--force') === false ?
91
            $command .= ' --force' : $command;
92
    }
93
94
    /**
95
     * Get the console command options.
96
     *
97
     * @return array
98
     */
99
    protected function getOptions(): array
100
    {
101
        return [
102
            ['command', null, InputOption::VALUE_OPTIONAL],
103
        ];
104
    }
105
}
106