Code Duplication    Length = 42-50 lines in 2 locations

src/PlaygroundGame/Mapper/Entry.php 2 locations

@@ 102-143 (lines=42) @@
99
        return $total;
100
    }
101
    
102
    public function findLastEntriesByIp($game, $ip, $limitScale)
103
    {
104
        $now = new \DateTime("now");
105
        switch ($limitScale) {
106
            case 'always':
107
                $interval = 'P100Y';
108
                $now->sub(new \DateInterval($interval));
109
                $dateLimit = $now->format('Y-m-d') . ' 0:0:0';
110
                break;
111
            case 'day':
112
                $dateLimit = $now->format('Y-m-d') . ' 0:0:0';
113
                break;
114
            case 'week':
115
                $interval = 'P7D';
116
                $now->sub(new \DateInterval($interval));
117
                $dateLimit = $now->format('Y-m-d') . ' 0:0:0';
118
                break;
119
            case 'month':
120
                $interval = 'P1M';
121
                $now->sub(new \DateInterval($interval));
122
                $dateLimit = $now->format('Y-m-d') . ' 0:0:0';
123
                break;
124
            case 'year':
125
                $interval = 'P1Y';
126
                $now->sub(new \DateInterval($interval));
127
                $dateLimit = $now->format('Y-m-d') . ' 0:0:0';
128
                break;
129
            default:
130
                $interval = 'P100Y';
131
                $now->sub(new \DateInterval($interval));
132
                $dateLimit = $now->format('Y-m-d') . ' 0:0:0';
133
        }
134
    
135
        $query = $this->em->createQuery(
136
            'SELECT COUNT(e.id) FROM PlaygroundGame\Entity\Entry e 
137
             WHERE e.ip = :ip AND e.game = :game AND (e.bonus = 0 OR e.bonus IS NULL) AND e.created_at >= :date'
138
        );
139
        $query->setParameter('ip', $ip);
140
        $query->setParameter('game', $game);
141
        $query->setParameter('date', $dateLimit);
142
    
143
        $total = $query->getSingleScalarResult();
144
    
145
        return $total;
146
    }
@@ 154-203 (lines=50) @@
151
     *
152
     * @param unknown_type $game
153
     */
154
    public function findPlayersWithOneEntryBy($game)
155
    {
156
        $now = new \DateTime("now");
157
        $limitScale = $game->getPlayLimitScale();
158
        switch ($limitScale) {
159
            case 'always':
160
                $interval = 'P100Y';
161
                $now->sub(new \DateInterval($interval));
162
                $dateLimit = $now->format('Y-m-d') . ' 0:0:0';
163
                break;
164
            case 'day':
165
                $dateLimit = $now->format('Y-m-d') . ' 0:0:0';
166
                break;
167
            case 'week':
168
                $interval = 'P7D';
169
                $now->sub(new \DateInterval($interval));
170
                $dateLimit = $now->format('Y-m-d') . ' 0:0:0';
171
                break;
172
            case 'month':
173
                $interval = 'P1M';
174
                $now->sub(new \DateInterval($interval));
175
                $dateLimit = $now->format('Y-m-d') . ' 0:0:0';
176
                break;
177
            case 'year':
178
                $interval = 'P1Y';
179
                $now->sub(new \DateInterval($interval));
180
                $dateLimit = $now->format('Y-m-d') . ' 0:0:0';
181
                break;
182
            default:
183
                $interval = 'P100Y';
184
                $now->sub(new \DateInterval($interval));
185
                $dateLimit = $now->format('Y-m-d') . ' 0:0:0';
186
        }
187
188
        $query = $this->em->createQuery(
189
            'SELECT e, u FROM PlaygroundGame\Entity\Entry e
190
            JOIN e.user u
191
            WHERE e.game = :game
192
                AND (e.bonus = 0 OR e.bonus IS NULL)
193
            GROUP BY e.user
194
            HAVING COUNT(e.id) = 1
195
            AND e.created_at <= :date '
196
        );
197
        $query->setParameter('game', $game);
198
        $query->setParameter('date', $dateLimit);
199
200
        $result = $query->getResult();
201
202
        return $result;
203
    }
204
205
    /**
206
     * Compte les nombre de participations bonus