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 |
||
5 | class Tools |
||
6 | { |
||
7 | /** |
||
8 | * 记录日志 |
||
9 | * |
||
10 | * @param $title |
||
11 | * @param $data |
||
12 | * @param $path |
||
13 | * |
||
14 | * @return int |
||
15 | */ |
||
16 | public static function dataRecodes($title, $data, $path) |
||
20 | |||
21 | /** |
||
22 | * 验证签名 成功 true 失败 false |
||
23 | * |
||
24 | * @param $token |
||
25 | * |
||
26 | * @return bool |
||
27 | */ |
||
28 | public static function verifySignature($token) |
||
49 | } |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: