Completed
Push — master ( 91fdab...75a7b9 )
by
unknown
13:37
created

Command/GoogleAnalyticsConfigsListCommand.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
namespace Kunstmaan\DashboardBundle\Command;
3
4
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Output\OutputInterface;
7
use Doctrine\ORM\EntityManagerInterface;
8
9
/**
10
 * @final since 5.1
11
 * NEXT_MAJOR extend from `Command` and remove `$this->getContainer` usages
12
 */
13
class GoogleAnalyticsConfigsListCommand extends ContainerAwareCommand
14
{
15
    /**
16
     * @var EntityManagerInterface
17
     */
18
    private $em;
19
20
    /**
21
     * @param EntityManagerInterface|null   $em
22
     */
23
    public function __construct(/* EntityManagerInterface */ $em = null)
24
    {
25
        parent::__construct();
26
27
        if (!$em instanceof EntityManagerInterface) {
28
            @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);
29
30
            $this->setName(null === $em ? 'kuma:dashboard:widget:googleanalytics:config:list' : $em);
31
32
            return;
33
        }
34
35
        $this->em = $em;
36
    }
37
38
    protected function configure()
39
    {
40
        $this
41
            ->setName('kuma:dashboard:widget:googleanalytics:configs:list')
42
            ->setDescription('List available configs');
43
    }
44
45
    /**
46
     * @param InputInterface  $input
47
     * @param OutputInterface $output
48
     * @return int|null|void
49
     */
50
    protected function execute(InputInterface $input, OutputInterface $output)
51
    {
52
        if (null === $this->em) {
53
            $this->em = $this->getContainer()->get('doctrine.orm.entity_manager');
54
        }
55
56
        $configs = $this->getconfigs();
57
58
        if (count($configs)) {
59
            $result = "\t".'<fg=green>' . count($configs) . '</fg=green> configs found:';
60
            $output->writeln($result);
61
            foreach($configs as $config) {
62
                $result = "\t".'(id: <fg=cyan>' .$config->getId() . '</fg=cyan>)';
63
                $result .= "\t" . $config->getName();
64
65
                $output->writeln($result);
66
            }
67
        } else {
68
            $output->writeln('No configs found');
69
        }
70
71
    }
72
73
    /**
74
     * get all segments
75
     *
76
     * @return array
0 ignored issues
show
Consider making the return type a bit more specific; maybe use object[].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
77
     */
78
    private function getconfigs()
79
    {
80
        // get all segments
81
        $configRepository = $this->em->getRepository('KunstmaanDashboardBundle:AnalyticsConfig');
82
        return $configRepository->findAll();
83
    }
84
}
85