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 |
||
| 18 | class WebPathResolver implements ResolverInterface |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * @var Filesystem |
||
| 22 | */ |
||
| 23 | protected $filesystem; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var RequestContext |
||
| 27 | */ |
||
| 28 | protected $requestContext; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var string |
||
| 32 | */ |
||
| 33 | protected $webRoot; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var string |
||
| 37 | */ |
||
| 38 | protected $cachePrefix; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var string |
||
| 42 | */ |
||
| 43 | protected $cacheRoot; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @param Filesystem $filesystem |
||
| 47 | * @param RequestContext $requestContext |
||
| 48 | * @param string $webRootDir |
||
| 49 | * @param string $cachePrefix |
||
| 50 | */ |
||
| 51 | public function __construct( |
||
| 64 | |||
| 65 | /** |
||
| 66 | * {@inheritdoc} |
||
| 67 | */ |
||
| 68 | public function resolve($path, $filter) |
||
| 75 | |||
| 76 | /** |
||
| 77 | * {@inheritdoc} |
||
| 78 | */ |
||
| 79 | public function isStored($path, $filter) |
||
| 83 | |||
| 84 | /** |
||
| 85 | * {@inheritdoc} |
||
| 86 | */ |
||
| 87 | public function store(BinaryInterface $binary, $path, $filter) |
||
| 94 | |||
| 95 | /** |
||
| 96 | * {@inheritdoc} |
||
| 97 | */ |
||
| 98 | public function remove(array $paths, array $filters) |
||
| 121 | |||
| 122 | /** |
||
| 123 | * {@inheritdoc} |
||
| 124 | */ |
||
| 125 | protected function getFilePath($path, $filter) |
||
| 129 | |||
| 130 | /** |
||
| 131 | * {@inheritdoc} |
||
| 132 | */ |
||
| 133 | View Code Duplication | protected function getFileUrl($path, $filter) |
|
| 140 | |||
| 141 | /** |
||
| 142 | * @return string |
||
| 143 | */ |
||
| 144 | protected function getBaseUrl() |
||
| 157 | } |
||
| 158 |
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: