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 |
||
3 | class AutomatedLinkReportTask extends Controller { |
||
1 ignored issue
–
show
|
|||
4 | |||
5 | private $GlobalSettings; |
||
6 | private $Links; |
||
7 | |||
8 | private static $exclude_classes = array('RedirectorPage', 'VirtualPage'); |
||
1 ignored issue
–
show
|
|||
9 | |||
10 | public function index() { |
||
20 | |||
21 | /** |
||
22 | * Check each page on the site and add the data of the links |
||
23 | * found in AutomatedLinkPageResult Objects |
||
24 | * |
||
25 | * @see AutomatedLinkPageResult |
||
26 | * @return ArrayList |
||
27 | */ |
||
28 | public function checkLinks() { |
||
59 | |||
60 | /** |
||
61 | * Returns all the data on how the provided $page was |
||
62 | * affected by automated links |
||
63 | * |
||
64 | * @param SiteTree $page |
||
65 | * @param array $includeIn |
||
66 | * |
||
67 | * @return SiteTree|false $page |
||
68 | */ |
||
69 | private function getLinkData(SiteTree $page, array $includeIn) { |
||
106 | |||
107 | /** |
||
108 | * Return all possible database fields for the |
||
109 | * $class provided |
||
110 | * |
||
111 | * @param String $class |
||
112 | * @return array |
||
113 | */ |
||
114 | private function getAllDatabaseFields($class) { |
||
121 | |||
122 | /** |
||
123 | * Returns a rendered version of the page supplied |
||
124 | * creating automated links according inside a DOMDocument |
||
125 | * object or false if anything fails. |
||
126 | * |
||
127 | * @param SiteTree $page |
||
128 | * @return DOMDocument |
||
129 | */ |
||
130 | private function getPageDOM(SiteTree $page) { |
||
171 | |||
172 | /** |
||
173 | * Checks if the page could have the possibility of automated links |
||
174 | * |
||
175 | * @param SiteTree $page |
||
176 | * @param array $includeIn |
||
177 | * |
||
178 | * @return Boolean |
||
179 | */ |
||
180 | private function checkForPossibleLinks(SiteTree $page, array $includeIn) { |
||
187 | |||
188 | } |
||
189 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.