Issues (1039)

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.

src/Mapper/Entry.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 PlaygroundGame\Mapper;
4
5
use PlaygroundGame\Mapper\AbstractMapper;
6
7
class Entry extends AbstractMapper
8
{
9
    public function countByGame(\PlaygroundGame\Entity\Game $game)
10
    {
11
        $query = $this->em->createQuery('SELECT COUNT(e.id) FROM PlaygroundGame\Entity\Entry e WHERE e.game = :game');
12
        $query->setParameter('game', $game);
13
        return $query->getSingleScalarResult();
14
    }
15
16
    public function draw($game, $userClass, $total)
0 ignored issues
show
The parameter $userClass is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
17
    {
18
        $sql ='
19
            SELECT 
20
                u.user_id uid, 
21
                u.username, 
22
                u.firstname, 
23
                u.lastname, 
24
                u.email, 
25
                u.optin_partner, 
26
                e.created_at ecreated_at, 
27
                e.updated_at eupdated_at, 
28
                e.* 
29
            FROM game_entry as e
30
            INNER JOIN user AS u ON e.user_id = u.user_id
31
            WHERE e.game_id = :game_id AND e.drawable = 1
32
            GROUP BY u.user_id
33
            ORDER BY RAND()
34
            LIMIT :total
35
        ';
36
        
37
        $rsm = new \Doctrine\ORM\Query\ResultSetMappingBuilder($this->em);
38
        $rsm->addRootEntityFromClassMetadata(
39
            '\PlaygroundGame\Entity\Entry',
40
            'e',
41
            array('id' => 'id', 'created_at' => 'ecreated_at', 'updated_at' => 'eupdated_at')
42
        );
43
        $query = $this->em->createNativeQuery($sql, $rsm);
44
        $query->setParameter('game_id', $game->getId());
45
        $query->setParameter('total', $total);
46
        
47
        return $query->getResult();
48
    }
49
50
    public function queryByGame(\PlaygroundGame\Entity\Game $game)
51
    {
52
        $query = $this->em->createQuery('SELECT e FROM PlaygroundGame\Entity\Entry e WHERE e.game = :game');
53
        $query->setParameter('game', $game);
54
        return $query;
55
    }
56
57
    public function findByGameId($game)
58
    {
59
        return $this->getEntityRepository()->findBy(array('game' => $game));
60
    }
61
62
    /**
63
     * Get all the entries of the player except those offered as bonus
64
     *
65
     * @param unknown_type $game
66
     * @param unknown_type $user
67
     */
68 View Code Duplication
    public function findLastEntriesByUser($game, $user, $dateLimit)
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...
69
    {
70
        $query = $this->em->createQuery(
71
            'SELECT e.id FROM PlaygroundGame\Entity\Entry e 
72
             WHERE e.user = :user AND e.game = :game AND (e.bonus = 0 OR e.bonus IS NULL) AND e.created_at >= :date'
73
        );
74
        $query->setParameter('user', $user);
75
        $query->setParameter('game', $game);
76
        $query->setParameter('date', $dateLimit);
77
78
        $total = $query->getResult();
79
80
        return $total;
81
    }
82
    
83 View Code Duplication
    public function findLastEntriesByAnonymousIdentifier($game, $anonymousIdentifier, $dateLimit)
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...
84
    {
85
        $query = $this->em->createQuery(
86
            'SELECT e.id FROM PlaygroundGame\Entity\Entry e 
87
             WHERE e.anonymousIdentifier = :anonymousIdentifier AND e.game = :game 
88
             AND (e.bonus = 0 OR e.bonus IS NULL) AND e.created_at >= :date'
89
        );
90
        $query->setParameter('anonymousIdentifier', $anonymousIdentifier);
91
        $query->setParameter('game', $game);
92
        $query->setParameter('date', $dateLimit);
93
    
94
        $total = $query->getResult();
95
96
        return $total;
97
    }
98
99 View Code Duplication
    public function findLastEntriesByIp($game, $ip, $dateLimit)
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...
100
    {
101
        $query = $this->em->createQuery(
102
            'SELECT e.id FROM PlaygroundGame\Entity\Entry e 
103
             WHERE e.ip = :ip AND e.game = :game AND (e.bonus = 0 OR e.bonus IS NULL) AND e.created_at >= :date'
104
        );
105
        $query->setParameter('ip', $ip);
106
        $query->setParameter('game', $game);
107
        $query->setParameter('date', $dateLimit);
108
    
109
        $total = $query->getResult();
110
    
111
        return $total;
112
    }
113
114
    /**
115
     * Get all the entries of the player except those offered as bonus
116
     *
117
     * @param unknown_type $game
118
     * @param unknown_type $user
119
     */
120 View Code Duplication
    public function countLastEntriesByUser($game, $user, $dateLimit)
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...
121
    {
122
        $query = $this->em->createQuery(
123
            'SELECT COUNT(e.id) FROM PlaygroundGame\Entity\Entry e 
124
             WHERE e.user = :user AND e.game = :game AND (e.bonus = 0 OR e.bonus IS NULL) AND e.created_at >= :date'
125
        );
126
        $query->setParameter('user', $user);
127
        $query->setParameter('game', $game);
128
        $query->setParameter('date', $dateLimit);
129
130
        $total = $query->getSingleScalarResult();
131
132
        return $total;
133
    }
134
    
135 View Code Duplication
    public function countLastEntriesByAnonymousIdentifier($game, $anonymousIdentifier, $dateLimit)
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...
136
    {
137
        $query = $this->em->createQuery(
138
            'SELECT COUNT(e.id) FROM PlaygroundGame\Entity\Entry e 
139
             WHERE e.anonymousIdentifier = :anonymousIdentifier AND e.game = :game 
140
             AND (e.bonus = 0 OR e.bonus IS NULL) AND e.created_at >= :date'
141
        );
142
        $query->setParameter('anonymousIdentifier', $anonymousIdentifier);
143
        $query->setParameter('game', $game);
144
        $query->setParameter('date', $dateLimit);
145
    
146
        $total = $query->getSingleScalarResult();
147
148
        return $total;
149
    }
150
151 View Code Duplication
    public function countLastEntriesByIp($game, $ip, $dateLimit)
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...
152
    {
153
        $query = $this->em->createQuery(
154
            'SELECT COUNT(e.id) FROM PlaygroundGame\Entity\Entry e 
155
             WHERE e.ip = :ip AND e.game = :game AND (e.bonus = 0 OR e.bonus IS NULL) AND e.created_at >= :date'
156
        );
157
        $query->setParameter('ip', $ip);
158
        $query->setParameter('game', $game);
159
        $query->setParameter('date', $dateLimit);
160
    
161
        $total = $query->getSingleScalarResult();
162
    
163
        return $total;
164
    }
165
166
    /**
167
     * get users with only one participation able to
168
     * replay the game in the timeframe (I except offered entries marked as bonus)
169
     *
170
     * @param unknown_type $game
171
     */
172
    public function findPlayersWithOneEntryBy($game, $dateLimit)
173
    {
174
        $query = $this->em->createQuery(
175
            'SELECT e, u FROM PlaygroundGame\Entity\Entry e
176
            JOIN e.user u
177
            WHERE e.game = :game
178
                AND (e.bonus = 0 OR e.bonus IS NULL)
179
            GROUP BY e.user
180
            HAVING COUNT(e.id) = 1
181
            AND e.created_at <= :date '
182
        );
183
        $query->setParameter('game', $game);
184
        $query->setParameter('date', $dateLimit);
185
186
        $result = $query->getResult();
187
188
        return $result;
189
    }
190
191
    /**
192
     * Compte les nombre de participations bonus
193
     * @param unknown_type $game
194
     * @param unknown_type $user
195
     */
196
    public function checkBonusEntry($game, $user)
197
    {
198
        $query = $this->em->createQuery(
199
            'SELECT COUNT(e.id) FROM PlaygroundGame\Entity\Entry e 
200
             WHERE e.user = :user AND e.game = :game AND (e.bonus = 0 OR e.bonus IS NULL)'
201
        );
202
        $query->setParameter('user', $user);
203
        $query->setParameter('game', $game);
204
        $nbEntries = $query->getSingleScalarResult();
205
206
        $query = $this->em->createQuery(
207
            'SELECT COUNT(e.id) FROM PlaygroundGame\Entity\Entry e 
208
             WHERE e.user = :user AND e.game = :game AND e.bonus = 1'
209
        );
210
        $query->setParameter('user', $user);
211
        $query->setParameter('game', $game);
212
        $nbBonusEntries = $query->getSingleScalarResult();
213
214
        if (($nbEntries - $nbBonusEntries) <= 0) {
215
            return false;
216
        }
217
218
        return true;
219
    }
220
221
    public function getEntityRepository()
222
    {
223
        if (null === $this->er) {
224
            $this->er = $this->em->getRepository('PlaygroundGame\Entity\Entry');
225
        }
226
227
        return $this->er;
228
    }
229
}
230