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 |
||
| 41 | class SagaEntry |
||
| 42 | { |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @ORM\Id |
||
| 46 | * @ORM\Column(type="string", name="saga_id") |
||
| 47 | * @var string |
||
| 48 | */ |
||
| 49 | private $sagaId; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @ORM\Column(type="string", name="saga_type") |
||
| 53 | * @var string |
||
| 54 | */ |
||
| 55 | private $sagaType; |
||
| 56 | /** |
||
| 57 | * @ORM\Column(type="string", name="saga_revision", nullable=true) |
||
| 58 | * @var string |
||
| 59 | */ |
||
| 60 | private $revision; |
||
| 61 | /** |
||
| 62 | * @ORM\Column(type="text", name="serialized_saga") |
||
| 63 | * @var string |
||
| 64 | */ |
||
| 65 | private $serializedSaga; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @var SagaInterface |
||
| 69 | */ |
||
| 70 | private $saga; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Constructs a new SagaEntry for the given <code>saga</code>. The given saga must be serializable. The provided |
||
| 74 | * saga is not modified by this operation. |
||
| 75 | * |
||
| 76 | * @param SagaInterface $saga The saga to store |
||
| 77 | * @param SerializerInterface $serializer The serialization mechanism to convert the Saga to a byte stream |
||
| 78 | */ |
||
| 79 | 9 | View Code Duplication | public function __construct( |
| 90 | |||
| 91 | /** |
||
| 92 | * Returns the Saga instance stored in this entry. |
||
| 93 | * |
||
| 94 | * @param SerializerInterface $serializer The serializer to decode the Saga |
||
| 95 | * @return SagaInterface the Saga instance stored in this entry |
||
| 96 | */ |
||
| 97 | 1 | View Code Duplication | public function getSaga(SerializerInterface $serializer) |
| 113 | |||
| 114 | /** |
||
| 115 | * Returns the serialized form of the Saga. |
||
| 116 | * |
||
| 117 | * @return string the serialized form of the Saga |
||
| 118 | */ |
||
| 119 | 9 | public function getSerializedSaga() |
|
| 123 | |||
| 124 | /** |
||
| 125 | * Returns the identifier of the saga contained in this entry |
||
| 126 | * |
||
| 127 | * @return string the identifier of the saga contained in this entry |
||
| 128 | */ |
||
| 129 | 3 | public function getSagaId() |
|
| 133 | |||
| 134 | /** |
||
| 135 | * Returns the revision of the serialized saga |
||
| 136 | * |
||
| 137 | * @return string the revision of the serialized saga |
||
| 138 | */ |
||
| 139 | 6 | public function getRevision() |
|
| 143 | |||
| 144 | /** |
||
| 145 | * Returns the type identifier of the serialized saga. |
||
| 146 | * |
||
| 147 | * @return string the type identifier of the serialized saga |
||
| 148 | */ |
||
| 149 | 6 | public function getSagaType() |
|
| 153 | |||
| 154 | } |
||
| 155 |
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.