Code Duplication    Length = 66-66 lines in 2 locations

src/PlaygroundGame/Service/Mission.php 1 location

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

src/PlaygroundGame/Service/MissionGame.php 1 location

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