Artisan::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 6
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Recca0120\Terminal\Console\Commands;
4
5
use Illuminate\Contracts\Console\Kernel as ArtisanContract;
6
use Illuminate\Support\Str;
7
use InvalidArgumentException;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Input\StringInput;
10
11
class Artisan extends Command
12
{
13
    /**
14
     * The console command name.
15
     *
16
     * @var string
17
     */
18
    protected $name = 'artisan';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'laravel artisan';
26
27
    /**
28
     * no support array.
29
     *
30
     * @var array
31
     */
32
    protected $notSupported = ['down' => '', 'tinker' => ''];
33
34
    /**
35
     * $artisan.
36
     *
37
     * @var ArtisanContract
38
     */
39
    protected $artisan;
40
41
    /**
42
     * __construct.
43
     *
44
     * @param ArtisanContract $artisan
45
     */
46
    public function __construct(ArtisanContract $artisan)
47
    {
48
        parent::__construct();
49 4
50
        $this->artisan = $artisan;
51 4
    }
52
53 4
    /**
54 4
     * Handle the command.
55
     *
56
     * @throws InvalidArgumentException
57
     */
58
    public function handle()
59
    {
60
        $command = $this->fixCommand(trim($this->option('command')));
61 4
62
        $input = new StringInput($command);
63 4
        $input->setInteractive(false);
64 4
        if (isset($this->notSupported[$input->getFirstArgument()]) === true) {
65
            throw new InvalidArgumentException('Command "'.$command.'" is not supported');
66
        }
67 4
        $this->artisan->handle($input, $this->getOutput());
68 4
    }
69 4
70 1
    /**
71
     * need focre option.
72 3
     *
73 3
     * @param string $command
74
     * @return string
75
     */
76
    protected function fixCommand($command)
77
    {
78
        $isMigrateCommand = Str::startsWith($command, 'migrate') === true && Str::startsWith($command, 'migrate:status') === false;
79 View Code Duplication
        if (($isMigrateCommand || Str::startsWith($command, 'db:seed') === true) && strpos($command, '--force') === false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
80
            $command .= ' --force';
81 4
        }
82
83
        $isLaravel55 = $this->laravel !== null && version_compare($this->laravel->version(), 5.5, '>=');
84 4 View Code Duplication
        if (($isLaravel55 && Str::startsWith($command, 'vendor:publish') === true) && strpos($command, '--all') === false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
85 4
            $command .= ' --all';
86 4
        }
87 1
88
        return $command;
89
    }
90
91 4
    /**
92 4
     * Get the console command options.
93 4
     *
94 4
     * @return array
95 1
     */
96
    protected function getOptions()
97
    {
98 4
        return [
99
            ['command', null, InputOption::VALUE_REQUIRED],
100
        ];
101
    }
102
}
103