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 |
||
4 | class BannerPageTypesManager |
||
|
|||
5 | { |
||
6 | |||
7 | const PAGE_TYPE_MAIN = 'main'; |
||
8 | const PAGE_TYPE_SHOP_CATEGORY = 'shop_category'; |
||
9 | const PAGE_TYPE_PRODUCT = 'product'; |
||
10 | const PAGE_TYPE_CATEGORY = 'category'; |
||
11 | const PAGE_TYPE_PAGE = 'page'; |
||
12 | const PAGE_TYPE_BRAND = 'brand'; |
||
13 | const PAGE_TYPE_SEARCH = 'search'; |
||
14 | |||
15 | /** |
||
16 | * @var BannerPageTypesManager instance |
||
17 | */ |
||
18 | private static $instance = NULL; |
||
19 | |||
20 | private function __construct() { |
||
23 | |||
24 | /** |
||
25 | * Get BannerPageTypesManager instance |
||
26 | * @return BannerPageTypesManager instance |
||
27 | */ |
||
28 | public static function getInstance() { |
||
34 | |||
35 | /** |
||
36 | * Get banner pages type|types: ['main', 'shop_category', 'product',...] on nothing to get all types array |
||
37 | * @param string $type - banner type |
||
38 | * @return array |
||
39 | */ |
||
40 | public function getPagesTypes($type = NULL) { |
||
74 | |||
75 | /** |
||
76 | * Get banner type view |
||
77 | * @param string $type - banner page type name type: ['main', 'shop_category', 'product',...] |
||
78 | * @param string $locale - locale name |
||
79 | * @return array |
||
80 | */ |
||
81 | View Code Duplication | public function getView($type, $locale = NULL) { |
|
93 | |||
94 | /** |
||
95 | * Get banner page type allowed pages list |
||
96 | * @param string $type - banner page type name type: ['main', 'shop_category', 'product',...] |
||
97 | * @param string $locale - locale name |
||
98 | * @return array |
||
99 | */ |
||
100 | View Code Duplication | public function getPages($type, $locale = NULL) { |
|
112 | } |