Code Duplication    Length = 29-29 lines in 2 locations

src/Report/Queries.php 2 locations

@@ 171-199 (lines=29) @@
168
     * @param   int|null    $rule
169
     * @return  int
170
     */
171
    public function count_added_violations($run_former, $run_latter, $rule = null) {
172
        $b = $this->result_db->builder();
173
        $q = $b
174
            ->select(
175
                "(SELECT COUNT (*) ".
176
                "FROM violation_locations vls ".
177
                "WHERE vls.run_id = :former AND vls.violation_id = vs.id) cnt_former")
178
            ->addSelect(
179
                "(SELECT COUNT (*) ".
180
                "FROM violation_locations vls ".
181
                "WHERE vls.run_id = :latter AND vls.violation_id = vs.id) cnt_latter")
182
            ->from("violations", "vs")
183
            ->where("cnt_former < cnt_latter")
184
            ->setParameter("former", $run_former)
185
            ->setParameter("latter", $run_latter);
186
        if ($rule !== null) {
187
            $q = $q
188
                ->andWhere("vs.rule_id = :rule")
189
                ->setParameter("rule", $rule);
190
        }
191
        $rows = $q->execute();
192
        $res = 0;
193
        while($r = $rows->fetch()) {
194
            if ((int)$r["cnt_latter"] > (int)$r["cnt_former"]) {
195
                $res += (int)$r["cnt_latter"] - (int)$r["cnt_former"];
196
            }
197
        }
198
        return $res;
199
    }
200
201
    /**
202
     * Get the amount of violations that were resolved in a run.
@@ 209-237 (lines=29) @@
206
     * @param   int|null    $rule
207
     * @return  int
208
     */
209
    public function count_resolved_violations($run_former, $run_latter, $rule = null) {
210
        $b = $this->result_db->builder();
211
        $q = $b
212
            ->select(
213
                "(SELECT COUNT (*) ".
214
                "FROM violation_locations vls ".
215
                "WHERE vls.run_id = :former AND vls.violation_id = vs.id) cnt_former")
216
            ->addSelect(
217
                "(SELECT COUNT (*) ".
218
                "FROM violation_locations vls ".
219
                "WHERE vls.run_id = :latter AND vls.violation_id = vs.id) cnt_latter")
220
            ->from("violations", "vs")
221
            ->where("cnt_former > cnt_latter")
222
            ->setParameter("former", $run_former)
223
            ->setParameter("latter", $run_latter);
224
        if ($rule !== null) {
225
            $q = $q
226
                ->andWhere("vs.rule_id = :rule")
227
                ->setParameter("rule", $rule);
228
        }
229
        $rows = $q->execute();
230
        $res = 0;
231
        while($r = $rows->fetch()) {
232
            if ((int)$r["cnt_former"] > (int)$r["cnt_latter"]) {
233
                $res += (int)$r["cnt_former"] - (int)$r["cnt_latter"];
234
            }
235
        }
236
        return $res;
237
    }
238
239
    /**
240
     * Get the rules that were analyzed in a run.