Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
15 | class StatsPasswordConversion extends StatisticsPage |
||
16 | { |
||
17 | protected function execute() |
||
18 | { |
||
19 | $query = <<<sql |
||
20 | SELECT '0' AS 'Version', 'Active' AS 'Type', COUNT(*) AS 'Count' FROM user WHERE password NOT LIKE ':%' AND (status = 'User' OR status = 'Admin') |
||
21 | UNION |
||
22 | SELECT '0', 'Inactive', COUNT(*) FROM user WHERE password NOT LIKE ':%' AND NOT (status = 'User' OR status = 'Admin') |
||
23 | UNION |
||
24 | SELECT SUBSTRING(password FROM 2 FOR 1), 'Active', COUNT(*) FROM user WHERE password LIKE ':%' AND (status = 'User' OR status = 'Admin') GROUP BY SUBSTRING(password FROM 2 FOR 1) |
||
25 | UNION |
||
26 | SELECT SUBSTRING(password FROM 2 FOR 1), 'Inactive', COUNT(*) FROM user WHERE password LIKE ':%' AND NOT (status = 'User' OR status = 'Admin') GROUP BY SUBSTRING(password FROM 2 FOR 1) |
||
27 | ORDER BY `Version` ASC, 'Type' ASC |
||
28 | ; |
||
29 | sql; |
||
30 | |||
31 | $qb = new QueryBrowser(); |
||
32 | $qb->rowFetchMode = PDO::FETCH_NUM; |
||
33 | $r = $qb->executeQueryToTable($query); |
||
34 | |||
35 | return $r; |
||
36 | } |
||
37 | |||
38 | public function getPageTitle() |
||
39 | { |
||
40 | return "Password conversion status"; |
||
41 | } |
||
42 | |||
43 | public function getPageName() |
||
44 | { |
||
45 | return "PasswordConversion"; |
||
46 | } |
||
47 | |||
48 | public function isProtected() |
||
49 | { |
||
50 | return true; |
||
51 | } |
||
52 | |||
53 | public function requiresWikiDatabase() |
||
56 | } |
||
57 | } |
||
58 |