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 fulltext_directory extends helper |
||
16 | { |
||
17 | /** @var \phpbb\db\driver\driver_interface */ |
||
18 | protected $db; |
||
19 | |||
20 | /** |
||
21 | * Constructor |
||
22 | * |
||
23 | * @param \phpbb\db\driver\driver_interface $db |
||
24 | */ |
||
25 | public function __construct(\phpbb\db\driver\driver_interface $db) |
||
29 | |||
30 | /** |
||
31 | * Performs a search on keywords depending on display specific params. You have to run split_keywords() first |
||
32 | * |
||
33 | * @param array $keywords_ary contains each words to search |
||
34 | * @param string $fields contains either titleonly (link titles should be searched), desconly (only description bodies should be searched) |
||
35 | * @param string $terms is either 'all' (use query as entered, words without prefix should default to "have to be in field") or 'any' (ignore search query parts and just return all posts that contain any of the specified words) |
||
36 | * @param array $sort_by_sql contains SQL code for the ORDER BY part of a query |
||
37 | * @param string $sort_key is the key of $sort_by_sql for the selected sorting |
||
38 | * @param string $sort_dir is either a or d representing ASC and DESC |
||
39 | * @param string $sort_days specifies the maximum amount of days a post may be old |
||
40 | * @param array $ex_cid_ary specifies an array of category ids which should not be searched |
||
41 | * @param int $cat_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched |
||
42 | * @param array &$id_ary passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered |
||
43 | * @param int $start indicates the first index of the page |
||
44 | * @param int $per_page number of ids each page is supposed to contain |
||
45 | * @return int total number of results |
||
46 | */ |
||
47 | public function keyword_search($keywords_ary, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_cid_ary, $cat_id, &$id_ary, $start, $per_page) |
||
123 | } |
||
124 |