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 |
||
32 | class RouteEntity extends FieldPluginBase implements ContainerFactoryPluginInterface { |
||
|
|||
33 | use DependencySerializationTrait; |
||
34 | |||
35 | /** |
||
36 | * The entity type manager. |
||
37 | * |
||
38 | * @var \Drupal\Core\Entity\EntityTypeManagerInterface |
||
39 | */ |
||
40 | protected $entityTypeManager; |
||
41 | |||
42 | /** |
||
43 | * The language manager. |
||
44 | * |
||
45 | * @var \Drupal\Core\Language\LanguageManagerInterface |
||
46 | */ |
||
47 | protected $languageManager; |
||
48 | |||
49 | /** |
||
50 | * The sub-request buffer service. |
||
51 | * |
||
52 | * @var \Drupal\graphql\GraphQL\Buffers\SubRequestBuffer |
||
53 | */ |
||
54 | protected $subrequestBuffer; |
||
55 | |||
56 | /** |
||
57 | * The entity repository service. |
||
58 | * |
||
59 | * @var \Drupal\Core\Entity\EntityRepositoryInterface |
||
60 | */ |
||
61 | protected $entityRepository; |
||
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | View Code Duplication | public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition) { |
|
77 | |||
78 | /** |
||
79 | * RouteEntity constructor. |
||
80 | * |
||
81 | * @param array $configuration |
||
82 | * The plugin configuration array. |
||
83 | * @param string $pluginId |
||
84 | * The plugin id. |
||
85 | * @param mixed $pluginDefinition |
||
86 | * The plugin definition array. |
||
87 | * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager |
||
88 | * The entity type manager service. |
||
89 | * @param \Drupal\Core\Entity\EntityRepositoryInterface $entityRepository |
||
90 | * The entity repository service. |
||
91 | * @param \Drupal\Core\Language\LanguageManagerInterface $languageManager |
||
92 | * The language manager service. |
||
93 | * @param \Drupal\graphql\GraphQL\Buffers\SubRequestBuffer $subrequestBuffer |
||
94 | */ |
||
95 | View Code Duplication | public function __construct( |
|
110 | |||
111 | /** |
||
112 | * {@inheritdoc} |
||
113 | */ |
||
114 | public function resolveValues($value, array $args, ResolveInfo $info) { |
||
131 | |||
132 | /** |
||
133 | * @param \Drupal\Core\Entity\EntityInterface $entity |
||
134 | * The entity to resolve. |
||
135 | * @param \Drupal\Core\Url $url |
||
136 | * The url of the entity to resolve. |
||
137 | * @param array $args |
||
138 | * The field arguments array. |
||
139 | * @param \Youshido\GraphQL\Execution\ResolveInfo $info |
||
140 | * The resolve info object. |
||
141 | * |
||
142 | * @return \Generator |
||
143 | */ |
||
144 | protected function resolveEntity(EntityInterface $entity, Url $url, array $args, ResolveInfo $info) { |
||
153 | |||
154 | /** |
||
155 | * Resolves the entity translation from the given url context. |
||
156 | * |
||
157 | * @param \Drupal\Core\Entity\EntityInterface $entity |
||
158 | * The entity to resolve. |
||
159 | * @param \Drupal\Core\Url $url |
||
160 | * The url of the entity to resolve. |
||
161 | * @param array $args |
||
162 | * The field arguments array. |
||
163 | * @param \Youshido\GraphQL\Execution\ResolveInfo $info |
||
164 | * The resolve info object. |
||
165 | * |
||
166 | * @return \Closure |
||
167 | */ |
||
168 | protected function resolveEntityTranslation(EntityInterface $entity, Url $url, array $args, ResolveInfo $info) { |
||
179 | |||
180 | /** |
||
181 | * m |
||
182 | * |
||
183 | * @param \Drupal\Core\Url $url |
||
184 | * The url of the entity to resolve. |
||
185 | * @param array $args |
||
186 | * The field arguments array. |
||
187 | * @param \Youshido\GraphQL\Execution\ResolveInfo $info |
||
188 | * The resolve info object. |
||
189 | * |
||
190 | * @return \Generator |
||
191 | */ |
||
192 | protected function resolveMissingEntity(Url $url, $args, $info) { |
||
195 | } |
||
196 | |||
197 |