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 |
||
14 | class UltravioletIndexController |
||
15 | { |
||
16 | /** |
||
17 | * @var \Netgen\Bundle\OpenWeatherMapBundle\API\OpenWeatherMap\Weather\UltravioletIndexInterface |
||
18 | */ |
||
19 | protected $ultravioletIndex; |
||
20 | |||
21 | /** |
||
22 | * UltravioletIndexController constructor. |
||
23 | * |
||
24 | * @param \Netgen\Bundle\OpenWeatherMapBundle\API\OpenWeatherMap\Weather\UltravioletIndexInterface $ultravioletIndex |
||
25 | */ |
||
26 | public function __construct(UltravioletIndexInterface $ultravioletIndex) |
||
30 | |||
31 | /** |
||
32 | * Returns ultraviolet index. |
||
33 | * |
||
34 | * @param float $latitude |
||
35 | * @param float $longitude |
||
36 | * @param string $datetime ISO 8601 date string |
||
37 | * |
||
38 | * @return \Symfony\Component\HttpFoundation\Response |
||
39 | */ |
||
40 | View Code Duplication | public function getUltravioletIndex($latitude, $longitude, $datetime = 'current') |
|
65 | } |
||
66 |
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.