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 |
||
14 | class DoctrineOrmExtension extends \Twig_Extension |
||
15 | { |
||
16 | /** |
||
17 | * @var RegistryInterface |
||
18 | */ |
||
19 | private $doctrine; |
||
20 | |||
21 | 5 | public function __construct(RegistryInterface $doctrine) |
|
25 | |||
26 | /** |
||
27 | * {@inheritdoc} |
||
28 | */ |
||
29 | 1 | public function getName() |
|
33 | |||
34 | /** |
||
35 | * {@inheritdoc} |
||
36 | */ |
||
37 | 3 | View Code Duplication | public function getFunctions() |
48 | |||
49 | /** |
||
50 | * {@inheritdoc} |
||
51 | */ |
||
52 | 1 | View Code Duplication | public function getFilters() |
63 | |||
64 | /** |
||
65 | * Get table name for entity |
||
66 | * |
||
67 | * @param string|object $entity Entity |
||
68 | * @return string |
||
69 | */ |
||
70 | 1 | View Code Duplication | protected function getTableName($entity) |
78 | |||
79 | /** |
||
80 | * Get column name for property of the entity |
||
81 | * |
||
82 | * @param string $field Entity property |
||
83 | * @param string|object $entity |
||
84 | * @return string |
||
85 | */ |
||
86 | 1 | View Code Duplication | protected function getColumnName($field, $entity) |
94 | } |
||
95 |
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.