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\Image; |
||
16 | class ImagePaths |
||
17 | { |
||
18 | |||
19 | /** |
||
20 | * Predefined paths. |
||
21 | * |
||
22 | * @var array |
||
23 | */ |
||
24 | protected $paths = []; |
||
25 | |||
26 | /** |
||
27 | * The config repository. |
||
28 | * |
||
29 | * @var Repository |
||
30 | */ |
||
31 | protected $config; |
||
32 | |||
33 | /** |
||
34 | * The request object. |
||
35 | * |
||
36 | * @var Request |
||
37 | */ |
||
38 | protected $request; |
||
39 | |||
40 | /** |
||
41 | * The application object. |
||
42 | * |
||
43 | * @var Application |
||
44 | */ |
||
45 | protected $application; |
||
46 | |||
47 | /** |
||
48 | * Create a new ImagePaths instance. |
||
49 | * |
||
50 | * @param Repository $config |
||
51 | * @param Request $request |
||
52 | * @param Application $application |
||
53 | */ |
||
54 | View Code Duplication | public function __construct(Repository $config, Request $request, Application $application) |
|
62 | |||
63 | /** |
||
64 | * Get the paths. |
||
65 | * |
||
66 | * @return array|mixed |
||
67 | */ |
||
68 | public function getPaths() |
||
72 | |||
73 | /** |
||
74 | * Set the paths. |
||
75 | * |
||
76 | * @param array $paths |
||
77 | * @return $this |
||
78 | */ |
||
79 | public function setPaths(array $paths) |
||
85 | |||
86 | /** |
||
87 | * Add an image path hint. |
||
88 | * |
||
89 | * @param $namespace |
||
90 | * @param $path |
||
91 | * @return $this |
||
92 | */ |
||
93 | public function addPath($namespace, $path) |
||
99 | |||
100 | /** |
||
101 | * Return the real path for a given path. |
||
102 | * |
||
103 | * @param $path |
||
104 | * @return string |
||
105 | * @throws \Exception |
||
106 | */ |
||
107 | View Code Duplication | public function realPath($path) |
|
122 | |||
123 | /** |
||
124 | * Return the output path for an image. |
||
125 | * |
||
126 | * @param $path |
||
127 | * @return string |
||
128 | */ |
||
129 | public function outputPath(Image $image) |
||
193 | |||
194 | /** |
||
195 | * Return the path prefix. |
||
196 | * |
||
197 | * @return string |
||
198 | */ |
||
199 | public function prefix() |
||
203 | } |
||
204 |