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 |
||
15 | class SnsExtendedClientConfiguration |
||
16 | { |
||
17 | /** @var S3Client */ |
||
18 | private $s3Client; |
||
19 | |||
20 | /** @var string */ |
||
21 | private $s3BucketName; |
||
22 | |||
23 | /** @var ClaimCheckFactoryInterface */ |
||
24 | private $claimCheckFactory; |
||
25 | |||
26 | /** @var ClaimCheckSerializerInterface */ |
||
27 | private $claimCheckSerializer; |
||
28 | |||
29 | /** |
||
30 | * ExtendedClientConfiguration constructor. |
||
31 | * @param S3Client $s3Client |
||
32 | * @param string $s3BucketName |
||
33 | * @throws ExceptionInterface |
||
34 | */ |
||
35 | 7 | View Code Duplication | public function __construct(S3Client $s3Client, $s3BucketName) |
49 | |||
50 | /** |
||
51 | * @return S3Client |
||
52 | */ |
||
53 | 2 | public function getS3Client() |
|
57 | |||
58 | /** |
||
59 | * @param S3Client $s3Client |
||
60 | */ |
||
61 | 1 | public function setS3Client($s3Client) |
|
65 | |||
66 | /** |
||
67 | * @return string |
||
68 | */ |
||
69 | 2 | public function getS3BucketName() |
|
73 | |||
74 | /** |
||
75 | * @param string $s3BucketName |
||
76 | */ |
||
77 | 1 | public function setS3BucketName($s3BucketName) |
|
81 | |||
82 | /** |
||
83 | * @return ClaimCheckFactoryInterface |
||
84 | */ |
||
85 | 2 | public function getClaimCheckFactory() |
|
89 | |||
90 | /** |
||
91 | * @param ClaimCheckFactoryInterface $claimCheckFactory |
||
92 | */ |
||
93 | 1 | public function setClaimCheckFactory($claimCheckFactory) |
|
97 | |||
98 | /** |
||
99 | * @return ClaimCheckSerializerInterface |
||
100 | */ |
||
101 | 2 | public function getClaimCheckSerializer() |
|
105 | |||
106 | /** |
||
107 | * @param ClaimCheckSerializerInterface $claimCheckSerializer |
||
108 | */ |
||
109 | 1 | public function setClaimCheckSerializer(ClaimCheckSerializerInterface $claimCheckSerializer) |
|
113 | } |
||
114 |
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.