DashboardCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 6
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 6
loc 6
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Kunstmaan\DashboardBundle\Command;
4
5
use Kunstmaan\DashboardBundle\Manager\WidgetManager;
6
use Kunstmaan\DashboardBundle\Widget\DashboardWidget;
7
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
/**
12
 * Symfony CLI command to collect all the widget dashboard data using bin/console kuma:dashboard:collect
13
 *
14
 * @final since 5.1
15
 * NEXT_MAJOR extend from `Command` and remove `$this->getContainer` usages
16
 */
17 View Code Duplication
class DashboardCommand extends ContainerAwareCommand
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Bundle\Framework...d\ContainerAwareCommand has been deprecated with message: since Symfony 4.2, use {@see Command} instead.

This class, trait or interface 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 type will be removed from the class and what other constant to use instead.

Loading history...
18
{
19
    private $widgetManager;
20
21
    public function __construct(WidgetManager $widgetManager = null)
22
    {
23
        parent::__construct();
24
25
        if (!$widgetManager instanceof WidgetManager) {
26
            @trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version symfony 3.4 and will be removed in symfony 4.0. If the command was registered by convention, make it a service instead. ', __METHOD__), E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
27
28
            $this->setName(null === $widgetManager ? 'kuma:dashboard:collect' : $widgetManager);
29
30
            return;
31
        }
32
33
        $this->widgetManager = $widgetManager;
34
    }
35
36
    protected function configure()
37
    {
38
        $this
39
            ->setName('kuma:dashboard:collect')
40
            ->setDescription('Collect all the widget dashboard data');
41
    }
42
43
    /**
44
     * @param InputInterface  $input
45
     * @param OutputInterface $output
46
     *
47
     * @return int|void|null
48
     */
49
    protected function execute(InputInterface $input, OutputInterface $output)
50
    {
51
        if (null === $this->widgetManager) {
52
            $this->widgetManager = $this->getContainer()->get('kunstmaan_dashboard.manager.widgets');
53
        }
54
55
        /** @var DashboardWidget[] $widgets */
56
        $widgets = $this->widgetManager->getWidgets();
57
        foreach ($widgets as $widget) {
58
            /* @var DashboardWidget $widget */
59
            $widget->getCommand()->execute($input, $output);
60
        }
61
62
        return 0;
63
    }
64
}
65