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 |
||
| 30 | class Serializer |
||
| 31 | { |
||
| 32 | /** |
||
| 33 | * Returns the directory containing the Serializer metadata. |
||
| 34 | * |
||
| 35 | * @return string The metadata directory |
||
| 36 | */ |
||
| 37 | public static function getMetadataDirectory() |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Registers serialization metadata for the xAPI models on a SerializerBuilder. |
||
| 44 | * |
||
| 45 | * @param SerializerBuilder $builder The SerializerBuilder |
||
| 46 | */ |
||
| 47 | public static function registerXApiMetadata(SerializerBuilder $builder) |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Registers event subscribers for the xAPI models on a SerializerBuilder. |
||
| 54 | * |
||
| 55 | * @param SerializerBuilder $builder The SerializerBuilder |
||
| 56 | */ |
||
| 57 | View Code Duplication | public static function registerXApiEventSubscriber(SerializerBuilder $builder) |
|
| 66 | |||
| 67 | /** |
||
| 68 | * Registers handlers for the xAPI models on a SerializerBuilder. |
||
| 69 | * |
||
| 70 | * @param SerializerBuilder $builder The SerializerBuilder |
||
| 71 | */ |
||
| 72 | public static function registerXApiHandler(SerializerBuilder $builder) |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Registers serialization metadata and event subscribers for the xAPI |
||
| 81 | * models on a SerializerBuilder. |
||
| 82 | * |
||
| 83 | * @param SerializerBuilder $builder The SerializerBuilder |
||
| 84 | */ |
||
| 85 | public static function registerXApi(SerializerBuilder $builder) |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Creates a SerializerBuilder with serialization metadata and serialization |
||
| 94 | * event subscribers registered for the xAPI models. |
||
| 95 | * |
||
| 96 | * @return SerializerBuilder The SerializerBuilder |
||
| 97 | */ |
||
| 98 | public static function createSerializerBuilder() |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Creates a new Serializer. |
||
| 108 | * |
||
| 109 | * @return SerializerInterface The Serializer |
||
| 110 | */ |
||
| 111 | public static function createSerializer() |
||
| 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.