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/Service/MissionGame.php (9 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\Service;
4
5
use Zend\ServiceManager\ServiceManager;
6
use Zend\EventManager\EventManagerAwareTrait;
7
use PlaygroundGame\Entity\MissionGame as MissionGameEntity;
8
use PlaygroundGame\Entity\MissionGameCondition as MissionGameConditionEntity;
9
use Zend\ServiceManager\ServiceLocatorInterface;
10
11
class MissionGame
12
{
13
    use EventManagerAwareTrait;
14
15
    /**
16
    * @var missionMapper
17
    */
18
    protected $missionMapper;
19
    /**
20
    * @var missionGameMapper
21
    */
22
    protected $missionGameMapper;
23
    /**
24
    * @var missionGameConditionMapper
25
    */
26
    protected $missionGameConditionMapper;
27
    /**
28
    * @var gameMapper
29
    */
30
    protected $gameMapper;
31
    /**
32
    * @var options
33
    */
34
    protected $options;
35
36
    /**
37
     *
38
     * @var ServiceManager
39
     */
40
    protected $serviceLocator;
41
42
    public function __construct(ServiceLocatorInterface $locator)
43
    {
44
        $this->serviceLocator = $locator;
0 ignored issues
show
Documentation Bug introduced by
$locator is of type object<Zend\ServiceManag...erviceLocatorInterface>, but the property $serviceLocator was declared to be of type object<Zend\ServiceManager\ServiceManager>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
45
    }
46
47
    public function checkGames($dataGames)
48
    {
49
        $nbGames = count($dataGames);
50
        for ($i=0; $i < $nbGames; $i++) {
51
            if (!empty($dataGames[$i+1])) {
52
                $game1 = $this->getGameMapper()->findById($dataGames[$i]['games']);
53
                $game2 = $this->getGameMapper()->findById($dataGames[$i+1]['games']);
54
55
                if ($game2->getEndDate() === null) {
56
                    continue;
57
                }
58
59
                // Si la date de fin du jeu 2 est inférieur a la date du jeu 1
60
                if ($game2->getEndDate()->getTimestamp() < $game1->getStartDate()->getTimestamp()) {
61
                    return false;
62
                }
63
            }
64
        }
65
66
        return true;
67
    }
68
69
70
    public function checkGamesInMission($dataGames)
71
    {
72
        $gamesId = array();
73
        $nbGames = count($dataGames);
74
        for ($i=0; $i < $nbGames; $i++) {
75
            $gamesId[] = $dataGames[$i]['games'];
76
        }
77
78
        $em = $this->serviceLocator->get('doctrine.entitymanager.orm_default');
79
80
        $query = $em->createQuery('SELECT mg 
81
                                   FROM PlaygroundGame\Entity\MissionGame mg
82
                                   WHERE mg.game IN (:gamesId)');
83
        $query->setParameter('gamesId', $gamesId);
84
        $games = $query->getResult();
85
86
        if (count($games) > 0) {
87
            return false;
88
        }
89
90
        return true;
91
    }
92
    /**
93
    * associate : Permet d'associer des jeux et des conditions à une mission
94
    * @param array $data
95
    * @param Mission $mission
96
    *
97
    * @return MissionGameEntity $missionGameEntity
98
    */
99
    public function associate($data, $mission)
100
    {
101
        $missionGameEntity = new MissionGameEntity();
102
        $game = $this->getGameMapper()->findById($data['games']);
103
        $missionGameEntity->setGame($game);
104
        $missionGameEntity->setPosition($data['position']);
105
        $missionGameEntity->setMission($mission);
106
        $missionGameEntity = $this->getMissionGameMapper()->insert($missionGameEntity);
107
108
        $missionGameConditionEntity = new MissionGameConditionEntity;
109
        $missionGameConditionEntity->setMissionGame($missionGameEntity);
110
        $missionGameConditionEntity->setAttribute($data['conditions']);
111
        $missionGameConditionEntity->setValue($data['points']);
112
        $missionGameConditionEntity = $this->getMissionGameConditionMapper()->insert($missionGameConditionEntity);
0 ignored issues
show
$missionGameConditionEntity is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
113
114
        return $missionGameEntity;
115
    }
116
117
    /**
118
    * clear : Permet de supprimer l'association des jeux et des conditions à une mission
119
    * @param Mission $mission
120
    */
121
    public function clear($mission)
122
    {
123
        $missionGames = $this->findMissionGameByMission($mission);
124
        foreach ($missionGames as $missionGames) {
125
            $this->getMissionGameMapper()->remove($missionGames);
126
        }
127
    }
128
129
130 View Code Duplication
    public function checkCondition($game, $winner, $prediction, $entry)
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...
131
    {
132
        $missionGame = $this->findMissionGameByGame($game);
133
        if (empty($missionGame)) {
134
            return false;
135
        }
136
137
        if ($missionGame->getMission()->getActive() === false) {
138
            return false;
139
        }
140
141
        $nextMissionGame = $this->getMissionGameMapper()->getNextGame(
142
            $missionGame->getMission(),
143
            $missionGame->getPosition()
144
        );
145
        
146
        if (empty($nextMissionGame)) {
147
            return false;
148
        }
149
150
        $missionGameConditions = $this->findMissionGameConditionByMissionGame($nextMissionGame);
151
        
152
        if (empty($missionGameConditions)) {
153
            return false;
154
        }
155
156
        foreach ($missionGameConditions as $missionGameCondition) {
157
            if ($missionGameCondition->getAttribute() == MissionGameConditionEntity::NONE) {
158
                continue;
159
            }
160
161
            // On passe au suivant si on a gagné
162
            if ($missionGameCondition->getAttribute() == MissionGameConditionEntity::VICTORY) {
163
                if (!($winner || $prediction)) {
164
                    return false;
165
                }
166
            }
167
168
            // On passe au suivant si on a perdu
169
            if ($missionGameCondition->getAttribute() == MissionGameConditionEntity::DEFEAT) {
170
                if ($winner || $prediction) {
171
                    return false;
172
                }
173
            }
174
175
            // On passe au suivant si on a perdu
176
            if ($missionGameCondition->getAttribute() == MissionGameConditionEntity::GREATER) {
177
                if (!$entry) {
178
                    return false;
179
                }
180
                if (!($entry->getPoints() > $missionGameCondition->getValue())) {
181
                    return false;
182
                }
183
            }
184
185
            // On passe au suivant si on a perdu
186
            if ($missionGameCondition->getAttribute() == MissionGameConditionEntity::LESS) {
187
                if (!$entry) {
188
                    return false;
189
                }
190
                if (!($entry->getPoints() < $missionGameCondition->getValue())) {
191
                    return false;
192
                }
193
            }
194
        }
195
196
        return $nextMissionGame->getGame();
197
    }
198
199
    /**
200
    * findMissionGameByMission : Permet de recuperer les missionsGame à partir d'une mission
201
    * @param Mission $mission
202
    *
203
    * @return Collection de MissionGame $missionGames
204
    */
205
    public function findMissionGameByMission($mission)
206
    {
207
        return $this->getMissionGameMapper()->findBy(array('mission'=>$mission));
208
    }
209
210
    /**
211
    * findMissionGameByMission : Permet de recuperer les missionsGame à partir d'une mission
212
    *
213
    * @return Collection de MissionGame $missionGames
214
    */
215
    public function findMissionGameByGame($game)
216
    {
217
        return $this->getMissionGameMapper()->findOneBy(array('game'=>$game));
218
    }
219
220
    /**
221
    * findMissionGameConditionByMissionGame : Permet de recuperer les missionsGameCondition à partir d'une missionGame
222
    * @param MissionGame $missionGame
223
    *
224
    * @return Collection de MissionGameCondition $missionGameConditions
225
    */
226
    public function findMissionGameConditionByMissionGame($missionGame)
227
    {
228
        return $this->getMissionGameConditionMapper()->findBy(array('missionGame'=>$missionGame));
229
    }
230
231
    /**
232
     * Retrieve service manager instance
233
     *
234
     * @return ServiceManager
235
     */
236
    public function getServiceManager()
237
    {
238
        return $this->serviceManager;
0 ignored issues
show
The property serviceManager does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
239
    }
240
241
    /**
242
     * Set service manager instance
243
     *
244
     * @return MissionGame
245
     */
246
    public function setServiceManager(ServiceManager $serviceManager)
247
    {
248
        $this->serviceManager = $serviceManager;
249
250
        return $this;
251
    }
252
253
    /**
254
    * getMissionGameConditionMapper : retrieve missionGameCondition mapper instance
255
    *
256
    * @return Mapper/missionGameCondition $missionGameConditionMapper
0 ignored issues
show
The doc-type Mapper/missionGameCondition could not be parsed: Unknown type name "Mapper/missionGameCondition" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
257
    */
258
    public function getMissionGameConditionMapper()
259
    {
260
        if (null === $this->missionGameConditionMapper) {
261
            $this->missionGameConditionMapper = $this->serviceLocator->get(
262
                'playgroundgame_mission_game_condition_mapper'
263
            );
264
        }
265
266
        return $this->missionGameConditionMapper;
267
    }
268
269
    /**
270
    * getMissionGameMapper : retrieve missionGame mapper instance
271
    *
272
    * @return Mapper/MissionGameMapper $missionGameMapper
0 ignored issues
show
The doc-type Mapper/MissionGameMapper could not be parsed: Unknown type name "Mapper/MissionGameMapper" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
273
    */
274 View Code Duplication
    public function getMissionGameMapper()
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...
275
    {
276
        if (null === $this->missionGameMapper) {
277
            $this->missionGameMapper = $this->serviceLocator->get('playgroundgame_mission_game_mapper');
278
        }
279
280
        return $this->missionGameMapper;
281
    }
282
283
    /**
284
    * getGameMapper : retrieve game mapper instance
285
    *
286
    * @return Mapper/GameMapper $gameMapper
0 ignored issues
show
The doc-type Mapper/GameMapper could not be parsed: Unknown type name "Mapper/GameMapper" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
287
    */
288 View Code Duplication
    public function getGameMapper()
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...
289
    {
290
        if (null === $this->gameMapper) {
291
            $this->gameMapper = $this->serviceLocator->get('playgroundgame_game_mapper');
292
        }
293
294
        return $this->gameMapper;
295
    }
296
}
297