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 |
||
10 | class GqlQueryMapQueryProvider implements QueryProviderInterface { |
||
11 | |||
12 | /** |
||
13 | * The cache backend for storing query map file paths. |
||
14 | * |
||
15 | * @var \Drupal\Core\Cache\CacheBackendInterface |
||
16 | */ |
||
17 | protected $cacheBackend; |
||
18 | |||
19 | /** |
||
20 | * The paths to use for finding query maps. |
||
21 | * |
||
22 | * @var string[] |
||
23 | */ |
||
24 | protected $lookupPaths; |
||
25 | |||
26 | /** |
||
27 | * QueryProvider constructor. |
||
28 | * |
||
29 | * @param \Drupal\Core\Cache\CacheBackendInterface $cacheBackend |
||
30 | * The cache backend for storing query map file paths. |
||
31 | * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory |
||
32 | * The config factory. |
||
33 | */ |
||
34 | public function __construct(CacheBackendInterface $cacheBackend, ConfigFactoryInterface $configFactory) { |
||
38 | |||
39 | /** |
||
40 | * {@inheritdoc} |
||
41 | */ |
||
42 | public function getQuery($id, OperationParams $operation) { |
||
58 | |||
59 | /** |
||
60 | * Discovers the available query maps within the configured lookup paths. |
||
61 | * |
||
62 | * @return array |
||
63 | * An associative array of query maps with the query map versions as keys. |
||
64 | */ |
||
65 | protected function discoverQueryMaps() { |
||
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.