Code Duplication    Length = 48-52 lines in 2 locations

src/Kunstmaan/DashboardBundle/Command/DashboardCommand.php 1 location

@@ 17-64 (lines=48) @@
14
 * @final since 5.1
15
 * NEXT_MAJOR extend from `Command` and remove `$this->getContainer` usages
16
 */
17
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);
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

src/Kunstmaan/SearchBundle/Command/DeleteIndexCommand.php 1 location

@@ 19-70 (lines=52) @@
16
 * @final since 5.1
17
 * NEXT_MAJOR extend from `Command` and remove `$this->getContainer` usages
18
 */
19
class DeleteIndexCommand extends ContainerAwareCommand
20
{
21
    /**
22
     * @var SearchConfigurationChain
23
     */
24
    private $configurationChain;
25
26
    public function __construct(/* SearchConfigurationChain */ $configurationChain = null)
27
    {
28
        parent::__construct();
29
30
        if (!$configurationChain instanceof SearchConfigurationChain) {
31
            @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);
32
33
            $this->setName(null === $configurationChain ? 'kuma:search:delete' : $configurationChain);
34
35
            return;
36
        }
37
38
        $this->configurationChain = $configurationChain;
39
    }
40
41
    protected function configure()
42
    {
43
        $this
44
            ->setName('kuma:search:delete')
45
            ->setDescription('Delete the index(es)');
46
    }
47
48
    /**
49
     * @param InputInterface  $input
50
     * @param OutputInterface $output
51
     *
52
     * @return null|int null or 0 if everything went fine, or an error code
53
     */
54
    protected function execute(InputInterface $input, OutputInterface $output)
55
    {
56
        if (null === $this->configurationChain) {
57
            $this->configurationChain = $this->getContainer()->get('kunstmaan_search.search_configuration_chain');
58
        }
59
        /**
60
         * @var string
61
         * @var SearchConfigurationInterface $searchConfiguration
62
         */
63
        foreach ($this->configurationChain->getConfigurations() as $alias => $searchConfiguration) {
64
            $searchConfiguration->deleteIndex();
65
            $output->writeln('Index deleted : ' . $alias);
66
        }
67
68
        return 0;
69
    }
70
}
71