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 |
||
21 | View Code Duplication | class FlysystemV2Resolver implements ResolverInterface |
|
|
|||
22 | { |
||
23 | /** |
||
24 | * @var FilesystemOperator |
||
25 | */ |
||
26 | protected $flysystem; |
||
27 | |||
28 | /** |
||
29 | * @var RequestContext |
||
30 | */ |
||
31 | protected $requestContext; |
||
32 | |||
33 | /** |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $webRoot; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $cachePrefix; |
||
42 | |||
43 | /** |
||
44 | * @var string |
||
45 | */ |
||
46 | protected $cacheRoot; |
||
47 | |||
48 | /** |
||
49 | * Flysystem specific visibility. |
||
50 | * |
||
51 | * @see Visibility |
||
52 | * |
||
53 | * @var string |
||
54 | */ |
||
55 | protected $visibility; |
||
56 | |||
57 | /** |
||
58 | * FlysystemResolver constructor. |
||
59 | * |
||
60 | * @param string $rootUrl |
||
61 | * @param string $cachePrefix |
||
62 | * @param string $visibility |
||
63 | */ |
||
64 | public function __construct( |
||
79 | |||
80 | /** |
||
81 | * Checks whether the given path is stored within this Resolver. |
||
82 | * |
||
83 | * @param string $path |
||
84 | * @param string $filter |
||
85 | * |
||
86 | * @return bool |
||
87 | */ |
||
88 | public function isStored($path, $filter) |
||
92 | |||
93 | /** |
||
94 | * Resolves filtered path for rendering in the browser. |
||
95 | * |
||
96 | * @param string $path The path where the original file is expected to be |
||
97 | * @param string $filter The name of the imagine filter in effect |
||
98 | * |
||
99 | * @throws NotResolvableException |
||
100 | * |
||
101 | * @return string The absolute URL of the cached image |
||
102 | */ |
||
103 | public function resolve($path, $filter) |
||
111 | |||
112 | /** |
||
113 | * Stores the content of the given binary. |
||
114 | * |
||
115 | * @param BinaryInterface $binary The image binary to store |
||
116 | * @param string $path The path where the original file is expected to be |
||
117 | * @param string $filter The name of the imagine filter in effect |
||
118 | */ |
||
119 | public function store(BinaryInterface $binary, $path, $filter) |
||
127 | |||
128 | /** |
||
129 | * @param string[] $paths The paths where the original files are expected to be |
||
130 | * @param string[] $filters The imagine filters in effect |
||
131 | */ |
||
132 | public function remove(array $paths, array $filters) |
||
155 | |||
156 | /** |
||
157 | * {@inheritdoc} |
||
158 | */ |
||
159 | protected function getFilePath($path, $filter) |
||
163 | |||
164 | /** |
||
165 | * {@inheritdoc} |
||
166 | */ |
||
167 | protected function getFileUrl($path, $filter) |
||
174 | } |
||
175 |
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.