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 |
||
10 | class MySqlJsonSnapshotStore implements SnapshotStoreInterface, InitializableInterface |
||
11 | { |
||
12 | const SNAPSHOTS_TABLE = 'snapshots'; |
||
13 | |||
14 | /** |
||
15 | * @var \PDO |
||
16 | */ |
||
17 | private $connection; |
||
18 | |||
19 | /** |
||
20 | * @var SerializerInterface |
||
21 | */ |
||
22 | private $serializer; |
||
23 | |||
24 | /** |
||
25 | * @param \PDO $connection |
||
26 | * @param SerializerInterface $serializer |
||
27 | */ |
||
28 | 7 | public function __construct( |
|
35 | |||
36 | /** |
||
37 | * @param SnapshotInterface $snapshot |
||
38 | */ |
||
39 | 4 | public function addSnapshot($snapshot) |
|
50 | |||
51 | /** |
||
52 | * @param string $aggregateClass |
||
53 | * @param string $aggregateId |
||
54 | * @return SnapshotInterface|null |
||
55 | */ |
||
56 | 2 | public function findLastSnapshot($aggregateClass, $aggregateId) |
|
66 | |||
67 | /** |
||
68 | * @param string $aggregateClass |
||
69 | * @param string $aggregateId |
||
70 | * @param int $version |
||
71 | * @return SnapshotInterface|null |
||
72 | */ |
||
73 | 2 | public function findNearestSnapshotToVersion($aggregateClass, $aggregateId, $version) |
|
84 | |||
85 | 7 | public function initialize() |
|
99 | |||
100 | /** |
||
101 | * @return bool |
||
102 | */ |
||
103 | 3 | View Code Duplication | public function initialized() |
112 | } |
||
113 |