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 |
||
22 | class QuerySourcesIterator implements \IteratorAggregate |
||
23 | { |
||
24 | private $kernel; |
||
25 | private $rootDir; |
||
26 | private $queries; |
||
27 | private $paths; |
||
28 | |||
29 | /** |
||
30 | * @param KernelInterface $kernel A KernelInterface instance |
||
31 | * @param string $rootDir The directory where global query sources can be stored |
||
32 | * @param array $paths Additional Twig paths to warm |
||
33 | */ |
||
34 | public function __construct(KernelInterface $kernel, $rootDir, array $paths = array()) |
||
40 | |||
41 | /** |
||
42 | * {@inheritdoc} |
||
43 | */ |
||
44 | public function getIterator() |
||
70 | |||
71 | /** |
||
72 | * Find query sources in the given directory. |
||
73 | * |
||
74 | * @param string $dir The directory where to look for query sources |
||
75 | * @param string|null $namespace The query source namespace |
||
76 | * |
||
77 | * @return array |
||
78 | */ |
||
79 | private function findQuerySourcesInDirectory($dir, $namespace = null) |
||
92 | } |
||
93 |
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.