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 |
||
| 17 | View Code Duplication | class ViewTranslation |
|
|
|
|||
| 18 | { |
||
| 19 | use Translation; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var string |
||
| 23 | * |
||
| 24 | * @Assert\NotBlank() |
||
| 25 | * @ORM\Column(name="name", type="string", length=255) |
||
| 26 | * @Serializer\Groups({"search"}) |
||
| 27 | */ |
||
| 28 | protected $name; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var string |
||
| 32 | * |
||
| 33 | * @Gedmo\Slug(handlers={ |
||
| 34 | * @Gedmo\SlugHandler(class="Victoire\Bundle\BusinessEntityBundle\Handler\TwigSlugHandler" |
||
| 35 | * )},fields={"name"}, updatable=false, unique=false) |
||
| 36 | * @ORM\Column(name="slug", type="string", length=255) |
||
| 37 | */ |
||
| 38 | protected $slug; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var string |
||
| 42 | * This property is computed by the method PageSubscriber::buildUrl |
||
| 43 | */ |
||
| 44 | protected $url; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Get name. |
||
| 48 | * |
||
| 49 | * @return string |
||
| 50 | */ |
||
| 51 | public function getName() |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Set name. |
||
| 58 | * |
||
| 59 | * @param string $name |
||
| 60 | * |
||
| 61 | * @return View |
||
| 62 | */ |
||
| 63 | public function setName($name) |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Set slug. |
||
| 72 | * |
||
| 73 | * @param string $slug |
||
| 74 | * |
||
| 75 | * @return View |
||
| 76 | */ |
||
| 77 | public function setSlug($slug) |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Get slug. |
||
| 86 | * |
||
| 87 | * @return string |
||
| 88 | */ |
||
| 89 | public function getSlug() |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @return string |
||
| 96 | */ |
||
| 97 | public function getUrl() |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @param string $url |
||
| 104 | */ |
||
| 105 | public function setUrl($url) |
||
| 111 | |||
| 112 | /** |
||
| 113 | * @inheritdoc |
||
| 114 | */ |
||
| 115 | public static function getTranslatableEntityClass() |
||
| 119 | } |
||
| 120 |
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.