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 |
||
| 7 | class PointUserExtension extends \Twig_Extension |
||
| 8 | { |
||
| 9 | const POINT_HOST = 'point.im'; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * @var UserApi |
||
| 13 | */ |
||
| 14 | private $userApi; |
||
| 15 | |||
| 16 | 12 | public function __construct(UserApi $userApi) |
|
| 20 | |||
| 21 | 6 | View Code Duplication | public function getFunctions() |
| 32 | |||
| 33 | 6 | View Code Duplication | public function getFilters() |
| 44 | |||
| 45 | public function pointAvatarSmallFunction(string $login): string |
||
| 49 | |||
| 50 | public function pointAvatarMediumFunction(string $login): string |
||
| 54 | |||
| 55 | 1 | public function pointAvatarLargeFunction(string $login): string |
|
| 59 | |||
| 60 | 1 | public function pointAvatarFunction(string $login, $size): string |
|
| 64 | |||
| 65 | /** |
||
| 66 | * @param string $login |
||
| 67 | * @param bool $forceHttps |
||
| 68 | * |
||
| 69 | * @return string |
||
| 70 | */ |
||
| 71 | public function pointUserUrl(string $login, bool $forceHttps = false): string |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @param string $login |
||
| 78 | * @param bool $forceHttps |
||
| 79 | * |
||
| 80 | * @return string |
||
| 81 | */ |
||
| 82 | 3 | public function pointUserBlogUrl(string $login, bool $forceHttps = false): string |
|
| 86 | } |
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.