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.

Repository/AnalyticsConfigRepository.php (7 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\Repository;
4
5
use Doctrine\ORM\EntityRepository;
6
use Kunstmaan\DashboardBundle\Entity\AnalyticsConfig;
7
use Kunstmaan\DashboardBundle\Entity\AnalyticsOverview;
8
9
/**
10
 * AnalyticsConfigRepository
11
 *
12
 * This class was generated by the Doctrine ORM. Add your own custom
13
 * repository methods below.
14
 */
15
class AnalyticsConfigRepository extends EntityRepository
16
{
17
    /**
18
     * Get the first config from the database, creates a new entry if the config doesn't exist yet
19
     *
20
     * @return AnalyticsConfig $config
21
     */
22
    public function findFirst($createNew = true)
23
    {
24
        // Backwards compatibility: select the first config, still used in the dashboard, specified config ids are set in the dashboard collection bundle
25
        $em = $this->getEntityManager();
26
        $query = $em->createQuery('SELECT c FROM KunstmaanDashboardBundle:AnalyticsConfig c');
27
        $result = $query->getResult();
28
        // if no configs exist, create a new one
29
        if (!$result && $createNew) {
30
            return $this->createConfig();
31
        }
32
33
        if ($result) {
34
            return $result[0];
35
        }
36
37
        return false;
38
    }
39
40
    /**
41
     * Get the default overviews for a config
42
     *
43
     * @return AnalyticsConfig $config
0 ignored issues
show
Should the return type not be object[]?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
44
     */
45
    public function findDefaultOverviews($config)
46
    {
47
        $em = $this->getEntityManager();
48
49
        return $em->getRepository(AnalyticsOverview::class)
50
            ->findBy(array(
51
                    'config' => $config,
52
                    'segment' => null,
53
                ));
54
    }
55
56
    /**
57
     * Create a new config
58
     *
59
     * @return AnalyticsConfig
60
     */
61
    public function createConfig()
62
    {
63
        $em = $this->getEntityManager();
64
65
        $config = new AnalyticsConfig();
66
        $em->persist($config);
67
        $em->flush();
68
69
        $this->getEntityManager()->getRepository(AnalyticsOverview::class)->addOverviews($config);
70
71
        return $config;
72
    }
73
74
    /**
75
     * Flush a config
76
     *
77
     * @param int $id the config id
0 ignored issues
show
Should the type for parameter $id not be false|integer?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
78
     */
79
    public function flushConfig($id = false)
80
    {
81
        $em = $this->getEntityManager();
82
83
        // Backward compatibilty to flush overviews without a config set
84
        if (!$id) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $id of type false|integer is loosely compared to false; this is ambiguous if the integer can be zero. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
85
            $overviewRepository = $em->getRepository(AnalyticsOverview::class);
86
            foreach ($overviewRepository->findAll() as $overview) {
87
                $em->remove($overview);
88
            }
89
            $em->flush();
90
91
            return;
92
        }
93
94
        $config = $id ? $this->find($id) : $this->findFirst();
95
        foreach ($config->getOverviews() as $overview) {
96
            $em->remove($overview);
97
        }
98
        foreach ($config->getSegments() as $segment) {
99
            $em->remove($segment);
100
        }
101
        $em->flush();
102
    }
103
104
    /**
105
     * Update the timestamp when data is collected
106
     *
107
     * @param int id
108
     */
109
    public function setUpdated($id = false)
110
    {
111
        $em = $this->getEntityManager();
112
        $config = $id ? $this->find($id) : $this->findFirst();
113
        $config->setLastUpdate(new \DateTime());
114
        $em->persist($config);
115
        $em->flush();
116
    }
117
118
    /**
119
     * saves the token
120
     *
121
     * @param string $token
122
     */
123
    public function saveToken($token, $id = false)
124
    {
125
        $em = $this->getEntityManager();
126
        $config = $id ? $this->find($id) : $this->findFirst();
127
        $config->setToken($token);
128
        $em->persist($config);
129
        $em->flush();
130
    }
131
132
    /**
133
     * saves the property id
134
     *
135
     * @param string $propertyId
136
     */
137
    public function savePropertyId($propertyId, $id = false)
138
    {
139
        $em = $this->getEntityManager();
140
        $config = $id ? $this->find($id) : $this->findFirst();
141
        $config->setPropertyId($propertyId);
142
        $em->persist($config);
143
        $em->flush();
144
    }
145
146
    /**
147
     * saves the account id
148
     *
149
     * @param string $accountId
150
     */
151
    public function saveAccountId($accountId, $id = false)
152
    {
153
        $em = $this->getEntityManager();
154
        $config = $id ? $this->find($id) : $this->findFirst();
155
        $config->setAccountId($accountId);
156
        $em->persist($config);
157
        $em->flush();
158
    }
159
160
    /**
161
     * saves the profile id
162
     *
163
     * @param string $profileId
164
     */
165 View Code Duplication
    public function saveProfileId($profileId, $id = false)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
166
    {
167
        $em = $this->getEntityManager();
168
        $config = $id ? $this->find($id) : $this->findFirst();
169
        $config->setProfileId($profileId);
170
        $em->persist($config);
171
        $em->flush();
172
    }
173
174
    /**
175
     * saves the config name
176
     *
177
     * @param string $profileId
0 ignored issues
show
There is no parameter named $profileId. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
178
     */
179 View Code Duplication
    public function saveConfigName($name, $id = false)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
180
    {
181
        $em = $this->getEntityManager();
182
        $config = $id ? $this->find($id) : $this->findFirst();
183
        $config->setName($name);
184
        $em->persist($config);
185
        $em->flush();
186
    }
187
188
    /**
189
     * Resets the profile id
190
     *
191
     * @param int id
192
     */
193 View Code Duplication
    public function resetProfileId($id = false)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
194
    {
195
        $em = $this->getEntityManager();
196
        $config = $id ? $this->find($id) : $this->findFirst();
197
        $config->setProfileId('');
198
        $em->persist($config);
199
        $em->flush();
200
    }
201
202
    /**
203
     * Resets the  account id, property id and profile id
204
     *
205
     * @param int id
206
     */
207
    public function resetPropertyId($id = false)
208
    {
209
        $em = $this->getEntityManager();
210
        $config = $id ? $this->find($id) : $this->findFirst();
211
        $config->setAccountId('');
212
        $config->setProfileId('');
213
        $config->setPropertyId('');
214
        $em->persist($config);
215
        $em->flush();
216
    }
217
}
218