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 |
||
9 | class WebPathResolver extends \Liip\ImagineBundle\Imagine\Cache\Resolver\WebPathResolver |
||
10 | { |
||
11 | /** |
||
12 | * @var FilterConfiguration |
||
13 | */ |
||
14 | protected $filterConfig; |
||
15 | |||
16 | /** |
||
17 | * @param Filesystem $filesystem |
||
18 | * @param RequestContext $requestContext |
||
19 | * @param string $webRootDir |
||
20 | * @param string $cachePrefix |
||
21 | * @param FilterConfiguration $filterConfig |
||
22 | */ |
||
23 | public function __construct(Filesystem $filesystem, RequestContext $requestContext, $webRootDir, $cachePrefix = 'media/cache', FilterConfiguration $filterConfig) |
||
29 | |||
30 | /** |
||
31 | * {@inheritdoc} |
||
32 | */ |
||
33 | protected function getFileUrl($path, $filter) |
||
40 | |||
41 | protected function getFilePath($path, $filter) |
||
49 | |||
50 | /** |
||
51 | * {@inheritdoc} |
||
52 | */ |
||
53 | public function resolve($path, $filter) |
||
57 | |||
58 | /** |
||
59 | * @param string $path |
||
60 | * @param string $format |
||
61 | * |
||
62 | * @return string |
||
63 | */ |
||
64 | View Code Duplication | private function changeFileExtension($path, $format) |
|
75 | |||
76 | /** |
||
77 | * Copy from \Liip\ImagineBundle\Imagine\Cache\Resolver\WebPathResolver::getFullPath |
||
78 | */ |
||
79 | private function getFullPath($path, $filter) |
||
86 | } |
||
87 |
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.