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 |
||
| 37 | View Code Duplication | class SimpleSerializedDomainEventData implements SerializedDomainEventDataInterface |
|
|
|
|||
| 38 | { |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var string |
||
| 42 | */ |
||
| 43 | private $eventIdentifier; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var string |
||
| 47 | */ |
||
| 48 | private $aggregateIdentifier; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var integer |
||
| 52 | */ |
||
| 53 | private $scn; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @var \DateTime |
||
| 57 | */ |
||
| 58 | private $timestamp; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @var SimpleSerializedObject |
||
| 62 | */ |
||
| 63 | private $serializedPayload; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @var SimpleSerializedObject |
||
| 67 | */ |
||
| 68 | private $serializedMetaData; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Initialize an instance using given properties. This constructor assumes the default SerializedType for meta data |
||
| 72 | * (name = 'org.axonframework.domain.MetaData' and revision = <em>null</em>). |
||
| 73 | * <p/> |
||
| 74 | * Note that the given <code>timestamp</code> must be in a format supported by {@link} DateTime#DateTime(Object)}. |
||
| 75 | * |
||
| 76 | * @param string $eventIdentifier The identifier of the event |
||
| 77 | * @param string $aggregateIdentifier The identifier of the aggregate |
||
| 78 | * @param integer $scn The sequence number of the event |
||
| 79 | * @param \DateTime $timestamp The timestamp of the event (format must be supported by {@link |
||
| 80 | * DateTime#DateTime(Object)}) |
||
| 81 | * @param string $payloadType The type identifier of the serialized payload |
||
| 82 | * @param string $payloadRevision The revision of the serialized payload |
||
| 83 | * @param mixed $payload The serialized representation of the event |
||
| 84 | * @param mixed $metaData The serialized representation of the meta data |
||
| 85 | */ |
||
| 86 | public function __construct($eventIdentifier, $aggregateIdentifier, $scn, |
||
| 98 | |||
| 99 | public function getEventIdentifier() |
||
| 103 | |||
| 104 | public function getAggregateIdentifier() |
||
| 108 | |||
| 109 | public function getScn() |
||
| 113 | |||
| 114 | public function getTimestamp() |
||
| 118 | |||
| 119 | public function getMetaData() |
||
| 123 | |||
| 124 | public function getPayload() |
||
| 128 | |||
| 129 | } |
||
| 130 |
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.