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 |
||
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 | |||
74 | /** |
||
75 | * get all segments |
||
76 | * |
||
77 | * @return array |
||
0 ignored issues
–
show
|
|||
78 | */ |
||
79 | private function getconfigs() |
||
80 | { |
||
81 | // get all segments |
||
82 | $configRepository = $this->em->getRepository('KunstmaanDashboardBundle:AnalyticsConfig'); |
||
83 | |||
84 | return $configRepository->findAll(); |
||
85 | } |
||
86 | } |
||
87 |
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.