Completed
Pull Request — 6.0 (#1872)
by Sander
102:24 queued 60:56
created

GoogleAnalyticsConfigsListCommand::getConfigs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Kunstmaan\DashboardBundle\Command;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
/**
11
 * Class GoogleAnalyticsConfigsListCommand
12
 */
13
class GoogleAnalyticsConfigsListCommand extends ContainerAwareCommand
14
{
15
    /** @var EntityManagerInterface $em */
16
    private $em;
17
18
    protected function configure()
19
    {
20
        $this
21
            ->setName('kuma:dashboard:widget:googleanalytics:configs:list')
22
            ->setDescription('List available configs');
23
    }
24
25
    /**
26
     * Inits instance variables for global usage.
27
     */
28
    private function init()
29
    {
30
        $this->em = $this->getContainer()->get('doctrine')->getManager();
31
    }
32
33
    protected function execute(InputInterface $input, OutputInterface $output)
34
    {
35
        $this->init();
36
37
        $configs = $this->getConfigs();
38
39
        if (\count($configs)) {
40
            $result = "\t".'<fg=green>'.\count($configs).'</fg=green> configs found:';
41
            $output->writeln($result);
42
            foreach ($configs as $config) {
43
                $result = "\t".'(id: <fg=cyan>'.$config->getId().'</fg=cyan>)';
44
                $result .= "\t".$config->getName();
45
46
                $output->writeln($result);
47
            }
48
        } else {
49
            $output->writeln('No configs found');
50
        }
51
52
    }
53
54
    /**
55
     * get all segments
56
     *
57
     * @return array
58
     */
59
    private function getConfigs()
60
    {
61
        // get all segments
62
        $configRepository = $this->em->getRepository('KunstmaanDashboardBundle:AnalyticsConfig');
63
64
        return $configRepository->findAll();
65
    }
66
}
67