Code Duplication    Length = 66-66 lines in 2 locations

src/PlaygroundGame/Service/Mission.php 1 location

@@ 55-120 (lines=66) @@
52
        return $this->getMissionGameMapper()->findBy(array('mission'=>$mission));
53
    }
54
    
55
    public function checkMissionCondition($game, $winner, $prediction, $entry)
56
    {
57
        $missionGame = $this->findMissionGameByGame($game);
58
        if(empty($missionGame)){
59
            return false;
60
        }
61
    
62
        if($missionGame->getMission()->getActive() === false){
63
            return false;
64
        }
65
    
66
        $nextMissionGame = $this->getMissionGameMapper()->getNextGame($missionGame->getMission(), $missionGame->getPosition());
67
    
68
        if(empty($nextMissionGame)){
69
            return false;
70
        }
71
    
72
        $missionGameConditions = $this->findMissionGameConditionByMissionGame($nextMissionGame);
73
    
74
        if(empty($missionGameConditions)){
75
            return false;
76
        }
77
    
78
        foreach ($missionGameConditions as $missionGameCondition) {
79
    
80
            if ($missionGameCondition->getAttribute() == MissionGameConditionEntity::NONE) {
81
                continue;
82
            }
83
    
84
            // On passe au suivant si on a gagné
85
            if ($missionGameCondition->getAttribute() == MissionGameConditionEntity::VICTORY) {
86
                if(!($winner || $prediction)){
87
                    return false;
88
                }
89
            }
90
    
91
            // On passe au suivant si on a perdu
92
            if ($missionGameCondition->getAttribute() == MissionGameConditionEntity::DEFEAT) {
93
                if($winner || $prediction){
94
                    return false;
95
                }
96
            }
97
    
98
            // On passe au suivant si on a perdu
99
            if ($missionGameCondition->getAttribute() == MissionGameConditionEntity::GREATER) {
100
                if (!$entry) {
101
                    return false;
102
                }
103
                if(!($entry->getPoints() > $missionGameCondition->getValue())){
104
                    return false;
105
                }
106
            }
107
    
108
            // On passe au suivant si on a perdu
109
            if ($missionGameCondition->getAttribute() == MissionGameConditionEntity::LESS) {
110
                if (!$entry) {
111
                    return false;
112
                }
113
                if(!($entry->getPoints() < $missionGameCondition->getValue())){
114
                    return false;
115
                }
116
            }
117
        }
118
    
119
        return $nextMissionGame->getGame();
120
    }
121
122
    public function getGameEntity()
123
    {

src/PlaygroundGame/Service/MissionGame.php 1 location

@@ 121-186 (lines=66) @@
118
    }
119
120
121
    public function checkCondition($game, $winner, $prediction, $entry)
122
    {
123
        $missionGame = $this->findMissionGameByGame($game);
124
        if(empty($missionGame)){
125
            return false;
126
        }
127
128
        if($missionGame->getMission()->getActive() === false){
129
            return false;
130
        }
131
132
        $nextMissionGame = $this->getMissionGameMapper()->getNextGame($missionGame->getMission(), $missionGame->getPosition());
133
        
134
        if(empty($nextMissionGame)){
135
            return false;
136
        }
137
138
        $missionGameConditions = $this->findMissionGameConditionByMissionGame($nextMissionGame);
139
        
140
        if(empty($missionGameConditions)){
141
            return false;
142
        }
143
144
        foreach ($missionGameConditions as $missionGameCondition) {
145
146
            if ($missionGameCondition->getAttribute() == MissionGameConditionEntity::NONE) {
147
                continue;
148
            }
149
150
            // On passe au suivant si on a gagné
151
            if ($missionGameCondition->getAttribute() == MissionGameConditionEntity::VICTORY) {
152
                if(!($winner || $prediction)){
153
                    return false;
154
                }
155
            }
156
157
            // On passe au suivant si on a perdu
158
            if ($missionGameCondition->getAttribute() == MissionGameConditionEntity::DEFEAT) {
159
                if($winner || $prediction){
160
                    return false;
161
                }
162
            }
163
164
            // On passe au suivant si on a perdu
165
            if ($missionGameCondition->getAttribute() == MissionGameConditionEntity::GREATER) {
166
                if (!$entry) {
167
                    return false;
168
                }
169
                if(!($entry->getPoints() > $missionGameCondition->getValue())){
170
                    return false;
171
                }
172
            }
173
174
            // On passe au suivant si on a perdu
175
            if ($missionGameCondition->getAttribute() == MissionGameConditionEntity::LESS) {
176
                if (!$entry) {
177
                    return false;
178
                }
179
                if(!($entry->getPoints() < $missionGameCondition->getValue())){
180
                    return false;
181
                }
182
            }
183
        }
184
185
        return $nextMissionGame->getGame();
186
    }
187
188
    /**
189
    * findMissionGameByMission : Permet de recuperer les missionsGame à partir d'une mission