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 namespace Anomaly\Streams\Platform\Lang; |
||
7 | class Loader extends FileLoader |
||
8 | { |
||
9 | |||
10 | /** |
||
11 | * The application instance. |
||
12 | * |
||
13 | * @var Application |
||
14 | */ |
||
15 | protected $application; |
||
16 | |||
17 | /** |
||
18 | * Create a new Loader instance. |
||
19 | * |
||
20 | * @param Filesystem $files |
||
21 | * @param string $path |
||
22 | */ |
||
23 | public function __construct(Filesystem $files, $path) |
||
29 | |||
30 | /** |
||
31 | * Load namespaced overrides from |
||
32 | * system AND application paths. |
||
33 | * |
||
34 | * @param array $lines |
||
35 | * @param string $locale |
||
36 | * @param string $group |
||
37 | * @param string $namespace |
||
38 | * @return array |
||
39 | */ |
||
40 | protected function loadNamespaceOverrides(array $lines, $locale, $group, $namespace) |
||
47 | |||
48 | /** |
||
49 | * Load system overrides. |
||
50 | * |
||
51 | * @param array $lines |
||
52 | * @param $locale |
||
53 | * @param $group |
||
54 | * @param $namespace |
||
55 | * @return array |
||
56 | */ |
||
57 | protected function loadSystemOverrides(array $lines, $locale, $group, $namespace) |
||
79 | |||
80 | /** |
||
81 | * Load system overrides. |
||
82 | * |
||
83 | * @param array $lines |
||
84 | * @param $locale |
||
85 | * @param $group |
||
86 | * @param $namespace |
||
87 | * @return array |
||
88 | */ |
||
89 | protected function loadApplicationOverrides(array $lines, $locale, $group, $namespace) |
||
113 | } |
||
114 |
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.