Conditions | 1 |
Paths | 1 |
Total Lines | 36 |
Code Lines | 11 |
Lines | 36 |
Ratio | 100 % |
Changes | 0 |
1 | <?php |
||
19 | public function loadSearchHistory() |
||
20 | { |
||
21 | $proto = $this->modelFactory()->get(SearchLog::class); |
||
22 | $source = $proto->source(); |
||
23 | $table = $source->table(); |
||
24 | |||
25 | $q = ' |
||
26 | SELECT |
||
27 | `keyword`, |
||
28 | COUNT(`keyword`) as num_searches, |
||
29 | SUM(`num_results`) as num_results |
||
30 | FROM |
||
31 | `'.$table.'` |
||
32 | WHERE |
||
33 | `num_results` = 0 |
||
34 | AND |
||
35 | `ts` > :start |
||
36 | AND |
||
37 | `ts` <= :end |
||
38 | GROUP BY |
||
39 | `keyword` |
||
40 | ORDER BY |
||
41 | num_searches DESC |
||
42 | LIMIT |
||
43 | 20 |
||
44 | '; |
||
45 | |||
46 | $sth = $source->dbQuery($q, [ |
||
47 | 'start' => $this->startDate()->format('Y-m-d H:i:s'), |
||
48 | 'end' => $this->endDate()->format('Y-m-d H:i:s') |
||
49 | ]); |
||
50 | |||
51 | $results = $sth->fetchAll(PDO::FETCH_ASSOC); |
||
52 | |||
53 | return $results; |
||
54 | } |
||
55 | } |
||
56 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.