Completed
Push — master ( aba493...5356ed )
by Ruud
315:38 queued 305:00
created

DashboardBundle/Command/DashboardCommand.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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);
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|null|void
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
}
63