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 Kint_Object_Blob extends Kint_Object |
||
4 | { |
||
5 | /** |
||
6 | * @var array Character encodings to detect |
||
7 | * |
||
8 | * @see http://php.net/manual/en/function.mb-detect-order.php |
||
9 | * |
||
10 | * In practice, mb_detect_encoding can only successfully determine the |
||
11 | * difference between the following common charsets at once without |
||
12 | * breaking things for one of the other charsets: |
||
13 | * - ASCII |
||
14 | * - UTF-8 |
||
15 | * - SJIS |
||
16 | * - EUC-JP |
||
17 | * |
||
18 | * If the array contains 'Windows-1252' special checking will be done |
||
19 | * *after* all other encodings have failed. (Since it's likely to match |
||
20 | * almost anything) |
||
21 | * |
||
22 | * The order of the charsets is significant. If you put UTF-8 before ASCII |
||
23 | * it will never match ASCII, because UTF-8 is a superset of ASCII. |
||
24 | * Similarly, SJIS and EUC-JP frequently match UTF-8 strings, so you should |
||
25 | * check UTF-8 first. SJIS and EUC-JP seem to work either way, but SJIS is |
||
26 | * more common so it should probably be first. |
||
27 | * |
||
28 | * Keep this behavior in mind when setting up your char_encodings array. |
||
29 | * |
||
30 | * Note that HHVM doesn't support SJIS or EUC-JP making them moot. |
||
31 | */ |
||
32 | public static $char_encodings = array( |
||
33 | 'ASCII', |
||
34 | 'UTF-8', |
||
35 | ); |
||
36 | |||
37 | public $type = 'string'; |
||
38 | public $encoding = false; |
||
39 | public $hints = array('string'); |
||
40 | |||
41 | public function getType() |
||
51 | |||
52 | public function getValueShort() |
||
58 | |||
59 | public function transplant(Kint_Object $new) |
||
66 | |||
67 | public static function strlen($string, $encoding = false) |
||
81 | |||
82 | public static function substr($string, $start, $length = null, $encoding = false) |
||
96 | |||
97 | public static function detectEncoding($string) |
||
123 | |||
124 | public static function escape($string, $encoding = false) |
||
164 | } |
||
165 |
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.