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 |
||
19 | class WebPathResolver implements ResolverInterface |
||
20 | { |
||
21 | /** |
||
22 | * @var Filesystem |
||
23 | */ |
||
24 | protected $filesystem; |
||
25 | |||
26 | /** |
||
27 | * @var RequestContext |
||
28 | */ |
||
29 | protected $requestContext; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $webRoot; |
||
35 | |||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $cachePrefix; |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | protected $cacheRoot; |
||
45 | |||
46 | /** |
||
47 | * @param Filesystem $filesystem |
||
48 | * @param RequestContext $requestContext |
||
49 | * @param string $webRootDir |
||
50 | * @param string $cachePrefix |
||
51 | */ |
||
52 | public function __construct( |
||
65 | |||
66 | /** |
||
67 | * {@inheritdoc} |
||
68 | */ |
||
69 | public function resolve($path, $filter) |
||
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | */ |
||
80 | public function isStored($path, $filter) |
||
84 | |||
85 | /** |
||
86 | * {@inheritdoc} |
||
87 | */ |
||
88 | public function store(BinaryInterface $binary, $path, $filter) |
||
95 | |||
96 | /** |
||
97 | * {@inheritdoc} |
||
98 | */ |
||
99 | public function remove(array $paths, array $filters) |
||
122 | |||
123 | /** |
||
124 | * {@inheritdoc} |
||
125 | */ |
||
126 | protected function getFilePath($path, $filter) |
||
130 | |||
131 | /** |
||
132 | * {@inheritdoc} |
||
133 | */ |
||
134 | protected function getFileUrl($path, $filter) |
||
138 | |||
139 | View Code Duplication | private function getFullPath($path, $filter) |
|
146 | |||
147 | /** |
||
148 | * @return string |
||
149 | */ |
||
150 | protected function getBaseUrl() |
||
174 | } |
||
175 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: