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 |
|
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
|
|||
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 | return 0; |
||
63 | } |
||
64 | } |
||
65 |
If you suppress an error, we recommend checking for the error condition explicitly: