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 |
||
33 | class EntityQueryEntities extends FieldPluginBase implements ContainerFactoryPluginInterface { |
||
|
|||
34 | use DependencySerializationTrait; |
||
35 | |||
36 | /** |
||
37 | * The entity buffer service. |
||
38 | * |
||
39 | * @var \Drupal\graphql\GraphQL\Buffers\EntityBuffer |
||
40 | */ |
||
41 | protected $entityBuffer; |
||
42 | |||
43 | /** |
||
44 | * The entity type manager service. |
||
45 | * |
||
46 | * @var \Drupal\Core\Entity\EntityTypeManagerInterface |
||
47 | */ |
||
48 | protected $entityTypeManager; |
||
49 | |||
50 | /** |
||
51 | * The entity repository service. |
||
52 | * |
||
53 | * @var \Drupal\Core\Entity\EntityRepositoryInterface |
||
54 | */ |
||
55 | protected $entityRepository; |
||
56 | |||
57 | /** |
||
58 | * {@inheritdoc} |
||
59 | */ |
||
60 | View Code Duplication | public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition) { |
|
70 | |||
71 | /** |
||
72 | * EntityQueryEntities constructor. |
||
73 | * |
||
74 | * @param array $configuration |
||
75 | * The plugin configuration array. |
||
76 | * @param string $pluginId |
||
77 | * The plugin id. |
||
78 | * @param mixed $pluginDefinition |
||
79 | * The plugin definition array. |
||
80 | * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager |
||
81 | * The entity type manager service. |
||
82 | * @param \Drupal\Core\Entity\EntityRepositoryInterface $entityRepository |
||
83 | * The entity repository service. |
||
84 | * @param \Drupal\graphql\GraphQL\Buffers\EntityBuffer $entityBuffer |
||
85 | * The entity buffer service. |
||
86 | */ |
||
87 | View Code Duplication | public function __construct( |
|
100 | |||
101 | /** |
||
102 | * {@inheritdoc} |
||
103 | */ |
||
104 | public function resolveValues($value, array $args, ResolveInfo $info) { |
||
118 | |||
119 | /** |
||
120 | * Resolves entities lazily through the entity buffer. |
||
121 | * |
||
122 | * @param string $type |
||
123 | * The entity type. |
||
124 | * @param array $ids |
||
125 | * The entity ids to load. |
||
126 | * @param mixed $context |
||
127 | * The query context. |
||
128 | * @param array $args |
||
129 | * The field arguments array. |
||
130 | * @param \Youshido\GraphQL\Execution\ResolveInfo $info |
||
131 | * The resolve info object. |
||
132 | * |
||
133 | * @return \Closure |
||
134 | * The deferred resolver. |
||
135 | */ |
||
136 | protected function resolveFromEntityIds($type, $ids, $context, array $args, ResolveInfo $info) { |
||
142 | |||
143 | /** |
||
144 | * Resolves entity revisions. |
||
145 | * |
||
146 | * @param string $type |
||
147 | * The entity type. |
||
148 | * @param array $ids |
||
149 | * The entity revision ids to load. |
||
150 | * @param mixed $context |
||
151 | * The query context. |
||
152 | * @param array $args |
||
153 | * The field arguments array. |
||
154 | * @param \Youshido\GraphQL\Execution\ResolveInfo $info |
||
155 | * The resolve info object. |
||
156 | * |
||
157 | * @return \Generator |
||
158 | * The resolved revisions. |
||
159 | */ |
||
160 | protected function resolveFromRevisionIds($type, $ids, $context, array $args, ResolveInfo $info) { |
||
168 | |||
169 | /** |
||
170 | * Resolves entity objects and checks view permissions. |
||
171 | * |
||
172 | * @param array $entities |
||
173 | * The entities to resolve. |
||
174 | * @param mixed $context |
||
175 | * The query context. |
||
176 | * @param array $args |
||
177 | * The field arguments array. |
||
178 | * @param \Youshido\GraphQL\Execution\ResolveInfo $info |
||
179 | * The resolve info object. |
||
180 | * |
||
181 | * @return \Generator |
||
182 | * The resolved entities. |
||
183 | */ |
||
184 | protected function resolveEntities(array $entities, $context, array $args, ResolveInfo $info) { |
||
203 | |||
204 | /** |
||
205 | * Negotiate the language for the resolved entities. |
||
206 | * |
||
207 | * @param mixed $context |
||
208 | * The query context. |
||
209 | * @param array $args |
||
210 | * The field arguments array. |
||
211 | * @param \Youshido\GraphQL\Execution\ResolveInfo $info |
||
212 | * The resolve info object. |
||
213 | * |
||
214 | * @return string|null |
||
215 | * The negotiated language id. |
||
216 | */ |
||
217 | protected function negotiateLanguage($context, $args, ResolveInfo $info) { |
||
228 | |||
229 | } |
||
230 |