Code Duplication    Length = 42-50 lines in 2 locations

src/PlaygroundGame/Mapper/Entry.php 2 locations

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