Completed
Push — master ( 06c1ce...67d37c )
by Jeroen
06:20
created

Command/GoogleAnalyticsConfigsListCommand.php (2 issues)

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