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\Asset; |
||
14 | class AssetPaths |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * Predefined paths. |
||
19 | * |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $paths = []; |
||
23 | |||
24 | /** |
||
25 | * The config repository. |
||
26 | * |
||
27 | * @var Repository |
||
28 | */ |
||
29 | protected $config; |
||
30 | |||
31 | /** |
||
32 | * The request object. |
||
33 | * |
||
34 | * @var Request |
||
35 | */ |
||
36 | protected $request; |
||
37 | |||
38 | /** |
||
39 | * The application object. |
||
40 | * |
||
41 | * @var Application |
||
42 | */ |
||
43 | protected $application; |
||
44 | |||
45 | /** |
||
46 | * Create a new AssetPaths instance. |
||
47 | * |
||
48 | * @param Repository $config |
||
49 | * @param Request $request |
||
50 | */ |
||
51 | View Code Duplication | public function __construct(Repository $config, Request $request, Application $application) |
|
59 | |||
60 | /** |
||
61 | * Get the paths. |
||
62 | * |
||
63 | * @return array|mixed |
||
64 | */ |
||
65 | public function getPaths() |
||
69 | |||
70 | /** |
||
71 | * Set the paths. |
||
72 | * |
||
73 | * @param array $paths |
||
74 | * @return $this |
||
75 | */ |
||
76 | public function setPaths(array $paths) |
||
82 | |||
83 | /** |
||
84 | * Add an image path hint. |
||
85 | * |
||
86 | * @param $namespace |
||
87 | * @param $path |
||
88 | * @return $this |
||
89 | */ |
||
90 | public function addPath($namespace, $path) |
||
96 | |||
97 | /** |
||
98 | * Get a single path. |
||
99 | * |
||
100 | * @param $namespace |
||
101 | * @return string|null |
||
102 | */ |
||
103 | public function getPath($namespace) |
||
107 | |||
108 | /** |
||
109 | * Return the hinted extension. |
||
110 | * |
||
111 | * @param $path |
||
112 | * @return string |
||
113 | */ |
||
114 | public function hint($path) |
||
126 | |||
127 | /** |
||
128 | * Return the extension of the path. |
||
129 | * |
||
130 | * @param $path |
||
131 | * @return string |
||
132 | */ |
||
133 | public function extension($path) |
||
137 | |||
138 | /** |
||
139 | * Return the real path for a given path. |
||
140 | * |
||
141 | * @param $path |
||
142 | * @return string |
||
143 | * @throws \Exception |
||
144 | */ |
||
145 | public function realPath($path) |
||
164 | |||
165 | /** |
||
166 | * Return the download path for a remote asset. |
||
167 | * |
||
168 | * @param $url |
||
169 | * @param null $path |
||
170 | * @return string |
||
171 | */ |
||
172 | public function downloadPath($url, $path = null) |
||
180 | |||
181 | /** |
||
182 | * Return the output path. |
||
183 | * |
||
184 | * @param $collection |
||
185 | * @return string |
||
186 | */ |
||
187 | public function outputPath($collection) |
||
219 | } |
||
220 |