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 |
||
16 | class CSS |
||
17 | { |
||
18 | /** Pattern for matching CSS url */ |
||
19 | const P_URL = '/url\s*\(\s*(\'|\")?([^\)\s\'\"]+)(\'|\")?\s*\)/i'; |
||
20 | |||
21 | /** @var string Path to current resource file */ |
||
22 | protected $currentResource; |
||
23 | |||
24 | /** |
||
25 | * LESS resource compiler. |
||
26 | * |
||
27 | * @param string $resource Resource full path |
||
28 | * @param string $extension Resource extension |
||
29 | * @param string $content Compiled output resource content |
||
30 | */ |
||
31 | 2 | public function compile($resource, $extension, &$content) |
|
40 | |||
41 | /** |
||
42 | * Callback for CSS url(...) rewriting. |
||
43 | * |
||
44 | * @param array $matches Regular expression matches collection |
||
45 | * |
||
46 | * @return string Rewritten url(..) with static resource handler url |
||
47 | * @throws ResourceNotFound |
||
48 | */ |
||
49 | 1 | public function rewriteUrls($matches) |
|
74 | } |
||
75 |
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.