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 |
||
18 | final class LiteralString |
||
19 | { |
||
20 | /** |
||
21 | * @param Tokenizer $tokenizer |
||
22 | * @param string $string |
||
23 | * @param array $matches |
||
24 | */ |
||
25 | public static function isFunction(Tokenizer $tokenizer, $string, array &$matches) |
||
31 | |||
32 | /** |
||
33 | * A function must be succeeded by '('. |
||
34 | * This makes it so that a function such as "COUNT(" is considered a function, but "COUNT" alone is not function. |
||
35 | * |
||
36 | * @param string $string |
||
37 | * @param array $matches |
||
38 | * @param string $regexFunction |
||
39 | * |
||
40 | * @return bool |
||
41 | */ |
||
42 | protected static function isFunctionString($string, array &$matches, $regexFunction) |
||
46 | |||
47 | /** |
||
48 | * @param string $string |
||
49 | * @param array $matches |
||
50 | * |
||
51 | * @return array |
||
52 | */ |
||
53 | View Code Duplication | protected static function getFunctionString($string, array &$matches) |
|
60 | |||
61 | /** |
||
62 | * @param Tokenizer $tokenizer |
||
63 | * @param string $string |
||
64 | * @param array $matches |
||
65 | */ |
||
66 | public static function getNonReservedString(Tokenizer $tokenizer, $string, array &$matches) |
||
81 | } |
||
82 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.