Passed
Push — master ( 6d2ec0...d97bf6 )
by Sebastiaan
02:45
created

View::execute()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 34
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 34
ccs 0
cts 27
cp 0
rs 8.8571
cc 3
eloc 22
nc 3
nop 2
crap 12
1
<?php
2
3
namespace Basebuilder\Scheduling\Command;
4
5
use Basebuilder\Scheduling\Schedule;
6
use Carbon\Carbon;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Helper\Table;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
/**
13
 * This command lets you inspect all the scheduled events
14
 */
15
class View extends Command
16
{
17
    /**
18
     * @var Schedule
19
     */
20
    protected $schedule;
21
22
    /**
23
     * @param Schedule $schedule
24
     * @param null|string $name
25
     */
26
    public function __construct(Schedule $schedule, $name = null)
27
    {
28
        $this->schedule = $schedule;
29
        parent::__construct($name);
30
    }
31
32
    /**
33
     * @inheritdoc
34
     */
35
    protected function configure()
36
    {
37
        $this->setName('scheduler:view');
38
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43
    protected function execute(InputInterface $input, OutputInterface $output)
44
    {
45
        $date = Carbon::now();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
46
        $schedule = $this->schedule;
47
48
        $output->writeln('======================================================');
49
        $output->writeln('# Schedule for <info>' . $schedule->getName() . '</info>');
50
        $output->writeln('======================================================');
51
        $output->writeln('');
52
53
        $events = $schedule->allEvents();
54
55
        if (empty($events)) {
56
            $output->writeln('<comment>No events found...</comment>');
57
            $output->writeln('');
58
            return;
59
        }
60
61
        $table = new Table($output);
62
        $table->setHeaders(['Event', 'Cron expression', 'Next run date']);
63
64
        foreach ($schedule->allEvents() as $event) {
65
            $exp = $event->getCronExpression();
66
67
            $table->addRow([
68
                (string) $event,
69
                (string) $exp,
70
                $exp->getNextRunDate($date)->format('d-m-Y H:i:s')
71
            ]);
72
        }
73
74
        $table->render();
75
        $output->writeln('');
76
    }
77
}
78