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 |
||
8 | class MetadataManager |
||
9 | { |
||
10 | private $V3Edmx = null; |
||
11 | |||
12 | private $serializer = null; |
||
13 | |||
14 | public function __construct($namespaceName = "Data", $containerName = "DefaultContainer") |
||
26 | |||
27 | public function getEdmx() |
||
31 | |||
32 | public function getEdmxXML() |
||
36 | |||
37 | public function addEntityType($name, $accessType = "Public") |
||
58 | |||
59 | /** |
||
60 | * Pluralizes a word if quantity is not one. |
||
61 | * |
||
62 | * @param int $quantity Number of items |
||
63 | * @param string $singular Singular form of word |
||
64 | * @param string $plural Plural form of word; function will attempt to deduce plural form from singular if not provided |
||
65 | * @return string Pluralized word if quantity is not one, otherwise singular |
||
66 | */ |
||
67 | View Code Duplication | public static function pluralize($quantity, $singular, $plural = null) |
|
82 | |||
83 | public function addComplexType(\ReflectionClass $refClass, $name, $namespace = null, $baseResourceType = null) |
||
87 | } |
||
88 |
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.