Test Failed
Pull Request — stable (#303)
by Sander
07:26
created

Command::menu()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Laravel Zero.
7
 *
8
 * (c) Nuno Maduro <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace LaravelZero\Framework\Commands;
15
16
use LaravelZero\Framework\Providers\CommandRecorder\CommandRecorder;
17
use function strlen;
18
use function str_repeat;
19
use function func_get_args;
20
use NunoMaduro\LaravelConsoleMenu\Menu;
21
use Illuminate\Console\Scheduling\Schedule;
22
use Illuminate\Console\Command as BaseCommand;
23
24
abstract class Command extends BaseCommand
25
{
26
    /**
27
     * Holds an instance of the app, if any.
28
     *
29
     * @var \LaravelZero\Framework\Application
30
     */
31
    protected $app;
32
33
    /**
34
     * @var CommandRecorder
35
     */
36
    protected $recorder;
37
38 32
    public function __construct()
39
    {
40 32
        parent::__construct();
41
42
        $this->recorder = app(CommandRecorder::class);
43
    }
44
45 32
    /**
46
     * Define the command's schedule.
47 32
     *
48 32
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
49
     * @return void
50
     */
51
    public function schedule(Schedule $schedule)
0 ignored issues
show
Unused Code introduced by
The parameter $schedule is not used and could be removed. ( Ignorable by Annotation )

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

51
    public function schedule(/** @scrutinizer ignore-unused */ Schedule $schedule)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
52
    {
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function setLaravel($laravel): void
59
    {
60
        parent::setLaravel($this->app = $laravel);
61
    }
62 15
63
    /**
64 15
     * Returns a menu builder.
65
     */
66
    public function menu(string $title, array $options = []): Menu
67
    {
68
        return $this->__call('menu', func_get_args());
69
    }
70 2
71
    /**
72 2
     * Performs the given task, outputs and
73 2
     * returns the result.
74
     */
75 2
    public function task(string $title = '', $task = null): bool
76 2
    {
77 2
        return $this->__call('task', func_get_args());
78 2
    }
79 2
80
    /*
81 2
     * Displays the given string as title.
82
     */
83
    public function title(string $title): Command
84
    {
85
        $size = strlen($title);
86
        $spaces = str_repeat(' ', $size);
87
88
        $this->output->newLine();
89
        $this->output->writeln("<bg=blue;fg=white>$spaces$spaces$spaces</>");
90
        $this->output->writeln("<bg=blue;fg=white>$spaces$title$spaces</>");
91
        $this->output->writeln("<bg=blue;fg=white>$spaces$spaces$spaces</>");
92
        $this->output->newLine();
93
94
        return $this;
95
    }
96
97
    public function call($command, array $arguments = [])
98
    {
99
        $this->record($command, $arguments);
100
101
        return parent::call($command, $arguments);
102
    }
103
104
    public function callSilent($command, array $arguments = [])
105
    {
106
        $this->record($command, $arguments, CommandRecorder::MODE_SILENT);
107
108
        return parent::callSilent($command, $arguments);
109
    }
110
111
    protected function record($command, $arguments, $mode = CommandRecorder::MODE_DEFAULT)
112
    {
113
        $this->recorder->record($command, $arguments, $mode);
114
    }
115
}
116