Code Duplication    Length = 66-68 lines in 2 locations

src/PlaygroundGame/Service/Mission.php 1 location

@@ 53-120 (lines=68) @@
50
        return $this->getMissionGameMapper()->findBy(array('mission'=>$mission));
51
    }
52
    
53
    public function checkMissionCondition($game, $winner, $prediction, $entry)
54
    {
55
        $missionGame = $this->findMissionGameByGame($game);
56
        if (empty($missionGame)) {
57
            return false;
58
        }
59
    
60
        if ($missionGame->getMission()->getActive() === false) {
61
            return false;
62
        }
63
    
64
        $nextMissionGame = $this->getMissionGameMapper()->getNextGame(
65
            $missionGame->getMission(),
66
            $missionGame->getPosition()
67
        );
68
    
69
        if (empty($nextMissionGame)) {
70
            return false;
71
        }
72
    
73
        $missionGameConditions = $this->findMissionGameConditionByMissionGame($nextMissionGame);
74
    
75
        if (empty($missionGameConditions)) {
76
            return false;
77
        }
78
    
79
        foreach ($missionGameConditions as $missionGameCondition) {
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

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