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; |
||
15 | class ImagePaths |
||
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 ImagePaths instance. |
||
48 | * |
||
49 | * @param Repository $config |
||
50 | * @param Request $request |
||
51 | * @param Application $application |
||
52 | */ |
||
53 | View Code Duplication | public function __construct(Repository $config, Request $request, Application $application) |
|
61 | |||
62 | /** |
||
63 | * Get the paths. |
||
64 | * |
||
65 | * @return array|mixed |
||
66 | */ |
||
67 | public function getPaths() |
||
71 | |||
72 | /** |
||
73 | * Set the paths. |
||
74 | * |
||
75 | * @param array $paths |
||
76 | * @return $this |
||
77 | */ |
||
78 | public function setPaths(array $paths) |
||
84 | |||
85 | /** |
||
86 | * Add an image path hint. |
||
87 | * |
||
88 | * @param $namespace |
||
89 | * @param $path |
||
90 | * @return $this |
||
91 | */ |
||
92 | public function addPath($namespace, $path) |
||
98 | |||
99 | /** |
||
100 | * Return the real path for a given path. |
||
101 | * |
||
102 | * @param $path |
||
103 | * @return string |
||
104 | * @throws \Exception |
||
105 | */ |
||
106 | public function realPath($path) |
||
120 | |||
121 | /** |
||
122 | * Return the output path for an image. |
||
123 | * |
||
124 | * @param $path |
||
125 | * @return string |
||
126 | */ |
||
127 | public function outputPath(Image $image) |
||
196 | } |
||
197 |