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; |
||
15 | class AssetPaths |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * Predefined paths. |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | protected $paths = []; |
||
24 | |||
25 | /** |
||
26 | * The config repository. |
||
27 | * |
||
28 | * @var Repository |
||
29 | */ |
||
30 | protected $config; |
||
31 | |||
32 | /** |
||
33 | * The request object. |
||
34 | * |
||
35 | * @var Request |
||
36 | */ |
||
37 | protected $request; |
||
38 | |||
39 | /** |
||
40 | * The application object. |
||
41 | * |
||
42 | * @var Application |
||
43 | */ |
||
44 | protected $application; |
||
45 | |||
46 | /** |
||
47 | * Create a new AssetPaths instance. |
||
48 | * |
||
49 | * @param Repository $config |
||
50 | * @param Request $request |
||
51 | */ |
||
52 | View Code Duplication | public function __construct(Repository $config, Request $request, Application $application) |
|
53 | { |
||
54 | $this->config = $config; |
||
55 | $this->request = $request; |
||
56 | $this->application = $application; |
||
57 | |||
58 | $this->paths = $config->get('streams::assets.paths', []); |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * Add an asset path hint. |
||
63 | * |
||
64 | * @param $namespace |
||
65 | * @param $path |
||
66 | * @return $this |
||
67 | */ |
||
68 | public function addPath($namespace, $path) |
||
74 | |||
75 | /** |
||
76 | * Return the hinted extension. |
||
77 | * |
||
78 | * @param $path |
||
79 | * @return string |
||
80 | */ |
||
81 | public function hint($path) |
||
93 | |||
94 | /** |
||
95 | * Return the extension of the path. |
||
96 | * |
||
97 | * @param $path |
||
98 | * @return string |
||
99 | */ |
||
100 | public function extension($path) |
||
104 | |||
105 | /** |
||
106 | * Return the real path for a given path. |
||
107 | * |
||
108 | * @param $path |
||
109 | * @return string |
||
110 | * @throws \Exception |
||
111 | */ |
||
112 | View Code Duplication | public function realPath($path) |
|
127 | |||
128 | /** |
||
129 | * Return the download path for a remote asset. |
||
130 | * |
||
131 | * @param $url |
||
132 | * @param null $path |
||
133 | * @return string |
||
134 | */ |
||
135 | public function downloadPath($url, $path = null) |
||
143 | |||
144 | /** |
||
145 | * Return the output path. |
||
146 | * |
||
147 | * @param $collection |
||
148 | * @return string |
||
149 | */ |
||
150 | public function outputPath($collection) |
||
182 | |||
183 | /** |
||
184 | * Return the path prefix. |
||
185 | * |
||
186 | * @return string |
||
187 | */ |
||
188 | public function prefix() |
||
192 | } |
||
193 |