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 |
||
| 26 | class JmsSerializeListenerAbstract |
||
| 27 | { |
||
| 28 | /** |
||
| 29 | * @var RequestContext $requestContext Request context |
||
| 30 | */ |
||
| 31 | protected $requestContext; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var CachedReader $annotationReader Cached annotation reader |
||
| 35 | */ |
||
| 36 | protected $annotationReader; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var CacheManager $cacheManager LiipImagineBundle Cache Manager |
||
| 40 | */ |
||
| 41 | protected $cacheManager; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var StorageInterface $storage Vich storage |
||
| 45 | */ |
||
| 46 | protected $vichStorage; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var array $config Bundle config |
||
| 50 | */ |
||
| 51 | protected $config; |
||
| 52 | |||
| 53 | /** @noinspection MoreThanThreeArgumentsInspection |
||
| 54 | * |
||
| 55 | * JmsSerializeListenerAbstract constructor. |
||
| 56 | * |
||
| 57 | * @param RequestContext $requestContext |
||
| 58 | * @param CachedReader $annotationReader |
||
| 59 | * @param CacheManager $cacheManager |
||
| 60 | * @param StorageInterface $vichStorage |
||
| 61 | * @param array $config |
||
| 62 | */ |
||
| 63 | public function __construct( |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @param ObjectEvent $event Event |
||
| 79 | * @return mixed |
||
| 80 | */ |
||
| 81 | protected function getObject(ObjectEvent $event) |
||
| 93 | |||
| 94 | /** @noinspection GenericObjectTypeUsageInspection |
||
| 95 | * @param LiipImagineSerializableField $liipAnnotation |
||
| 96 | * @param object $object Serialized object |
||
| 97 | * @param string $value Value of field |
||
| 98 | * @return array|string |
||
| 99 | */ |
||
| 100 | protected function serializeValue(LiipImagineSerializableField $liipAnnotation, $object, $value) |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Get host url (scheme, host, port) |
||
| 143 | * |
||
| 144 | * @return string Host url |
||
| 145 | */ |
||
| 146 | protected function getHostUrl() |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Removes host and scheme (protocol) from passed url |
||
| 161 | * |
||
| 162 | * @param $url |
||
| 163 | * @return string |
||
| 164 | */ |
||
| 165 | private function stripHostFromUrl($url) |
||
| 176 | } |
||
| 177 |
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.