Issues (3099)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

GoogleAnalyticsOverviewsGenerateCommand.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
3
namespace Kunstmaan\DashboardBundle\Command;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Kunstmaan\DashboardBundle\Entity\AnalyticsConfig;
7
use Kunstmaan\DashboardBundle\Entity\AnalyticsOverview;
8
use Kunstmaan\DashboardBundle\Entity\AnalyticsSegment;
9
use Kunstmaan\DashboardBundle\Repository\AnalyticsSegmentRepository;
10
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Input\InputOption;
13
use Symfony\Component\Console\Output\OutputInterface;
14
15
/**
16
 * @final since 5.1
17
 * NEXT_MAJOR extend from `Command` and remove `$this->getContainer` usages
18
 */
19
class GoogleAnalyticsOverviewsGenerateCommand extends ContainerAwareCommand
20
{
21
    /** @var EntityManagerInterface */
22
    private $em;
23
24
    /**
25
     * @param EntityManagerInterface|null $em
26
     */
27
    public function __construct(/* EntityManagerInterface */ $em = null)
28
    {
29
        parent::__construct();
30
31
        if (!$em instanceof EntityManagerInterface) {
32
            @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);
33
34
            $this->setName(null === $em ? 'kuma:dashboard:widget:googleanalytics:overviews:generate' : $em);
35
36
            return;
37
        }
38
39
        $this->em = $em;
40
    }
41
42 View Code Duplication
    protected function configure()
43
    {
44
        $this
45
            ->setName('kuma:dashboard:widget:googleanalytics:overviews:generate')
46
            ->setDescription('Generate overviews')
47
            ->addOption(
48
                'config',
49
                null,
50
                InputOption::VALUE_OPTIONAL,
51
                'Specify to only update one config',
52
                false
53
            )
54
            ->addOption(
55
                'segment',
56
                null,
57
                InputOption::VALUE_OPTIONAL,
58
                'Specify to only update one segment',
59
                false
60
            );
61
    }
62
63
    /**
64
     * @param InputInterface  $input
65
     * @param OutputInterface $output
66
     *
67
     * @return int|void|null
68
     */
69
    protected function execute(InputInterface $input, OutputInterface $output)
70
    {
71
        if (null === $this->em) {
72
            $this->em = $this->getContainer()->get('doctrine.orm.entity_manager');
73
        }
74
75
        // get params
76
        $configId = false;
77
        $segmentId = false;
78
79
        try {
80
            $configId = $input->getOption('config');
81
            $segmentId = $input->getOption('segment');
82
        } catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
83
        }
84
85
        try {
86
            if ($segmentId) {
87
                $this->generateOverviewsOfSegment($segmentId);
88
            } elseif ($configId) {
89
                $this->generateOverviewsOfConfig($configId);
90
            } else {
91
                $this->generateAllOverviews();
92
            }
93
94
            $output->writeln('<fg=green>Overviews succesfully generated</fg=green>');
95
96
            return 0;
97
        } catch (\InvalidArgumentException $e) {
98
            $output->writeln('<fg=red>' . $e->getMessage() . '</fg=red>');
99
100
            return 1;
101
        }
102
    }
103
104
    /**
105
     * Get all overviews of a segment
106
     *
107
     * @param int $segmentId
108
     *
109
     * @return array
110
     *
111
     * @throws \InvalidArgumentException
112
     */
113 View Code Duplication
    private function generateOverviewsOfSegment($segmentId)
114
    {
115
        /** @var AnalyticsSegmentRepository $segmentRepository */
116
        $segmentRepository = $this->em->getRepository(AnalyticsSegment::class);
117
        $segment = $segmentRepository->find($segmentId);
118
119
        if (!$segment) {
120
            throw new \InvalidArgumentException('Unknown segment ID');
121
        }
122
123
        // init the segment
124
        $segmentRepository->initSegment($segment);
125
    }
126
127
    /**
128
     * Get all overviews of a config
129
     *
130
     * @param int $configId
131
     *
132
     * @return array
133
     *
134
     * @throws \InvalidArgumentException
135
     */
136
    private function generateOverviewsOfConfig($configId)
137
    {
138
        $configRepository = $this->em->getRepository(AnalyticsConfig::class);
139
        $segmentRepository = $this->em->getRepository(AnalyticsSegment::class);
140
        $overviewRepository = $this->em->getRepository(AnalyticsOverview::class);
141
        // get specified config
142
        $config = $configRepository->find($configId);
143
144
        if (!$config) {
145
            throw new \InvalidArgumentException('Unknown config ID');
146
        }
147
148
        // create default overviews for this config if none exist yet
149
        if (!\count($config->getOverviews())) {
150
            $overviewRepository->addOverviews($config);
151
        }
152
153
        // init all the segments for this config
154
        $segments = $config->getSegments();
155
        foreach ($segments as $segment) {
156
            $segmentRepository->initSegment($segment);
157
        }
158
    }
159
160
    /**
161
     * get all overviews
162
     *
163
     * @return array
164
     */
165 View Code Duplication
    private function generateAllOverviews()
166
    {
167
        $configRepository = $this->em->getRepository(AnalyticsConfig::class);
168
        $overviewRepository = $this->em->getRepository(AnalyticsOverview::class);
169
        $segmentRepository = $this->em->getRepository(AnalyticsSegment::class);
170
        $configs = $configRepository->findAll();
171
172
        foreach ($configs as $config) {
173
            // add overviews if none exist yet
174
            if (!\count($configRepository->findDefaultOverviews($config))) {
175
                $overviewRepository->addOverviews($config);
176
            }
177
178
            // init all the segments for this config
179
            $segments = $config->getSegments();
180
            foreach ($segments as $segment) {
181
                $segmentRepository->initSegment($segment);
182
            }
183
        }
184
    }
185
}
186