Passed
Branch develop (b36b95)
by Nuno
02:06
created

Command::task()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
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 LogicException;
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
     * Execute the console command.
35
     *
36
     * @return void
37
     *
38
     * @throws \LogicException
39
     */
40 1
    public function handle(): void
41
    {
42 1
        throw new LogicException('You must override the handle() method in the concrete command class.');
43
    }
44
45
    /**
46
     * Define the command's schedule.
47
     *
48
     * @param  \Illuminate\Console\Scheduling\Schedule $schedule
49
     *
50
     * @return void
51
     */
52 29
    public function schedule(Schedule $schedule): void
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

52
    public function schedule(/** @scrutinizer ignore-unused */ Schedule $schedule): void

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...
53
    {
54 29
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59 29
    public function setLaravel($laravel): void
60
    {
61 29
        parent::setLaravel($this->app = $laravel);
62 29
    }
63
64
    /*
65
     * Returns a menu builder.
66
     *
67
     * @param  string $title
68
     * @param  array $options
69
     *
70
     * @return \NunoMaduro\LaravelConsoleMenu\Menu
71
     */
72
    public function menu(string $title, array $options = []): Menu
73
    {
74
        return $this->__call('menu', func_get_args());
75
    }
76
77
    /*
78
     * Performs the given task, outputs and
79
     * returns the result.
80
     *
81
     * @param  string $title
82
     * @param  callable|null $task
83
     *
84
     * @return bool With the result of the task.
85
     */
86 13
    public function task(string $title = '', $task = null): bool
87
    {
88 13
        return $this->__call('task', func_get_args());
89
    }
90
91
    /**
92
     * Displays a title.
93
     *
94
     * @param  string $title
95
     *
96
     * @return \LaravelZero\Framework\Commands\Command
97
     */
98 2
    public function title(string $title): Command
99
    {
100 2
        $size = strlen($title);
101 2
        $spaces = str_repeat(' ', $size);
102
103 2
        $this->output->newLine();
104 2
        $this->output->writeln("<bg=blue;fg=white>$spaces$spaces$spaces</>");
105 2
        $this->output->writeln("<bg=blue;fg=white>$spaces$title$spaces</>");
106 2
        $this->output->writeln("<bg=blue;fg=white>$spaces$spaces$spaces</>");
107 2
        $this->output->newLine();
108
109 2
        return $this;
110
    }
111
}
112