Code Duplication    Length = 29-29 lines in 2 locations

src/Report/Queries.php 2 locations

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