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 |
||
13 | class RequestHandler |
||
14 | { |
||
15 | /** |
||
16 | * @param ParamMeta[] $paramMates |
||
17 | */ |
||
18 | 4 | public function __construct(array $paramMates=[]){ |
|
21 | |||
22 | /** |
||
23 | * @param Application $app |
||
24 | * @param Request $request |
||
25 | * @param array $params |
||
26 | * @param array $reference |
||
27 | * @return void |
||
28 | */ |
||
29 | 1 | public function handle(Application $app, Request $request, array &$params, array &$reference){ |
|
80 | |||
81 | public function getParamNames(){ |
||
84 | |||
85 | /** |
||
86 | * 获取参数列表 |
||
87 | * @return ParamMeta[] |
||
88 | */ |
||
89 | 5 | public function getParamMetas(){ |
|
92 | |||
93 | /** |
||
94 | * 获取指定参数信息 |
||
95 | * @param $name |
||
96 | * @return ParamMeta|null |
||
97 | */ |
||
98 | 3 | public function getParamMeta($name){ |
|
106 | |||
107 | /** |
||
108 | * @param \PhpBoot\Metas\ParamMeta[] $paramMetas |
||
109 | */ |
||
110 | 4 | public function setParamMetas($paramMetas) |
|
114 | /** |
||
115 | * @var ParamMeta[] |
||
116 | */ |
||
117 | private $paramMetas = []; |
||
118 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.