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 |
||
20 | class EncryptedColumnLegacySupport extends Type |
||
21 | { |
||
22 | const ENCRYPTED = 'encrypted'; |
||
23 | |||
24 | /** |
||
25 | * @var EncryptionService |
||
26 | */ |
||
27 | private $encryptionService; |
||
28 | |||
29 | 1 | View Code Duplication | public static function create(EncryptionService $encryptionService) |
|
|||
30 | { |
||
31 | 1 | Type::addType(EncryptedColumnLegacySupport::ENCRYPTED, EncryptedColumnLegacySupport::class); |
|
32 | /** @var EncryptedColumnLegacySupport $instance */ |
||
33 | 1 | $instance = Type::getType(EncryptedColumnLegacySupport::ENCRYPTED); |
|
34 | 1 | $instance->encryptionService = $encryptionService; |
|
35 | 1 | } |
|
36 | |||
37 | 1 | public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) |
|
41 | |||
42 | 1 | public function requiresSQLCommentHint(AbstractPlatform $platform) |
|
46 | |||
47 | 1 | public function getName() |
|
51 | |||
52 | 2 | public function convertToPHPValue($value, AbstractPlatform $platform) |
|
74 | 1 | ||
75 | View Code Duplication | public function convertToDatabaseValue($value, AbstractPlatform $platform) |
|
83 | |||
84 | /** |
||
85 | * Based on: https://github.com/schmittjoh/serializer/blob/master/src/JMS/Serializer/JsonDeserializationVisitor.php |
||
86 | * |
||
87 | * @param $value |
||
88 | * @return mixed |
||
89 | * @throws ConversionException |
||
90 | 2 | */ |
|
91 | View Code Duplication | private function decodeJson($value) |
|
115 | } |
||
116 |
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.