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 |
||
| 18 | View Code Duplication | class Genre |
|
| 19 | { |
||
| 20 | use TimestampableEntity; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var integer |
||
| 24 | * |
||
| 25 | * @ORM\Column(name="id", type="integer") |
||
| 26 | * @ORM\Id |
||
| 27 | * @ORM\GeneratedValue(strategy="AUTO") |
||
| 28 | */ |
||
| 29 | private $id; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var string |
||
| 33 | * |
||
| 34 | * @ORM\Column(name="name", type="string", length=50, nullable=false) |
||
| 35 | * @Assert\NotBlank() |
||
| 36 | * @Groups({"genre-read", "media-read"}) |
||
| 37 | */ |
||
| 38 | private $name; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @ORM\ManyToMany(targetEntity="\AudioCoreEntity\Entity\Media",mappedBy="genres") |
||
| 42 | * @Groups({"genre-read"}) |
||
| 43 | **/ |
||
| 44 | private $medias; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var string |
||
| 48 | * @Gedmo\Slug(fields={"name"}, unique=true) |
||
| 49 | * @ORM\Column(type="string", length=128, unique=true) |
||
| 50 | */ |
||
| 51 | protected $slug; |
||
| 52 | |||
| 53 | 3 | public function __construct($name = null) |
|
| 58 | |||
| 59 | /** |
||
| 60 | * Get id |
||
| 61 | * |
||
| 62 | * @return integer |
||
| 63 | */ |
||
| 64 | 1 | public function getId() |
|
| 68 | |||
| 69 | /** |
||
| 70 | * @return string |
||
| 71 | */ |
||
| 72 | 1 | public function getName() |
|
| 76 | |||
| 77 | /** |
||
| 78 | * @param string $name |
||
| 79 | * @return $this |
||
| 80 | */ |
||
| 81 | 3 | public function setName($name) |
|
| 87 | |||
| 88 | /** |
||
| 89 | * @return mixed |
||
| 90 | */ |
||
| 91 | 1 | public function getMedias() |
|
| 95 | |||
| 96 | /** |
||
| 97 | * @param mixed $medias |
||
| 98 | * @return Genre |
||
| 99 | */ |
||
| 100 | 1 | public function setMedias($medias) |
|
| 106 | |||
| 107 | /** |
||
| 108 | * @return string |
||
| 109 | */ |
||
| 110 | public function getSlug() |
||
| 114 | } |
||
| 115 |