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 Messages extends AbstractHelper |
||
6 | { |
||
7 | |||
8 | static $_cssClass = array( |
||
|
|||
9 | 'warning' => 'alert alert-warning', |
||
10 | 'error' => 'alert alert-danger', |
||
11 | 'success' => 'alert alert-success', |
||
12 | 'info' => 'alert alert-info', |
||
13 | ); |
||
14 | |||
15 | 1 | public static function warning($items = array(), $wrap = true) |
|
19 | |||
20 | 1 | public static function info($items = array(), $wrap = true) |
|
24 | |||
25 | public static function success($items = array(), $wrap = true) |
||
29 | |||
30 | public static function error($items = array(), $wrap = true) |
||
34 | |||
35 | 2 | public static function render($items = array(), $type = false, $wrap = true) |
|
63 | } |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.