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 EntityQueryEntities extends FieldPluginBase implements ContainerFactoryPluginInterface { |
||
|
|||
33 | use DependencySerializationTrait; |
||
34 | |||
35 | /** |
||
36 | * The entity buffer service. |
||
37 | * |
||
38 | * @var \Drupal\graphql\GraphQL\Buffers\EntityBuffer |
||
39 | */ |
||
40 | protected $entityBuffer; |
||
41 | |||
42 | /** |
||
43 | * The entity type manager service. |
||
44 | * |
||
45 | * @var \Drupal\Core\Entity\EntityTypeManagerInterface |
||
46 | */ |
||
47 | protected $entityTypeManager; |
||
48 | |||
49 | /** |
||
50 | * The entity repository service. |
||
51 | * |
||
52 | * @var \Drupal\Core\Entity\EntityRepositoryInterface |
||
53 | */ |
||
54 | protected $entityRepository; |
||
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | View Code Duplication | public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition) { |
|
69 | |||
70 | /** |
||
71 | * EntityQueryEntities constructor. |
||
72 | * |
||
73 | * @param array $configuration |
||
74 | * The plugin configuration array. |
||
75 | * @param string $pluginId |
||
76 | * The plugin id. |
||
77 | * @param mixed $pluginDefinition |
||
78 | * The plugin definition array. |
||
79 | * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager |
||
80 | * The entity type manager service. |
||
81 | * @param \Drupal\Core\Entity\EntityRepositoryInterface $entityRepository |
||
82 | * The entity repository service. |
||
83 | * @param \Drupal\graphql\GraphQL\Buffers\EntityBuffer $entityBuffer |
||
84 | * The entity buffer service. |
||
85 | */ |
||
86 | View Code Duplication | public function __construct( |
|
99 | |||
100 | /** |
||
101 | * {@inheritdoc} |
||
102 | */ |
||
103 | public function resolveValues($value, array $args, ResolveInfo $info) { |
||
116 | |||
117 | /** |
||
118 | * Resolves entities lazily through the entity buffer. |
||
119 | * |
||
120 | * @param string $type |
||
121 | * The entity type. |
||
122 | * @param array $ids |
||
123 | * The entity ids to load. |
||
124 | * @param array $args |
||
125 | * The field arguments array. |
||
126 | * @param \Youshido\GraphQL\Execution\ResolveInfo $info |
||
127 | * The resolve info object. |
||
128 | * |
||
129 | * @return \Closure |
||
130 | * The deferred resolver. |
||
131 | */ |
||
132 | protected function resolveFromEntityIds($type, $ids, array $args, ResolveInfo $info) { |
||
138 | |||
139 | /** |
||
140 | * Resolves entity revisions. |
||
141 | * |
||
142 | * @param string $type |
||
143 | * The entity type. |
||
144 | * @param array $ids |
||
145 | * The entity revision ids to load. |
||
146 | * @param array $args |
||
147 | * The field arguments array. |
||
148 | * @param \Youshido\GraphQL\Execution\ResolveInfo $info |
||
149 | * The resolve info object. |
||
150 | * |
||
151 | * @return \Generator |
||
152 | * The resolved revisions. |
||
153 | */ |
||
154 | protected function resolveFromRevisionIds($type, $ids, array $args, ResolveInfo $info) { |
||
162 | |||
163 | /** |
||
164 | * Resolves entity objects and checks view permissions. |
||
165 | * |
||
166 | * @param array $entities |
||
167 | * The entities to resolve. |
||
168 | * @param array $args |
||
169 | * The field arguments array. |
||
170 | * @param \Youshido\GraphQL\Execution\ResolveInfo $info |
||
171 | * The resolve info object. |
||
172 | * |
||
173 | * @return \Generator |
||
174 | * The resolved entities. |
||
175 | */ |
||
176 | protected function resolveEntities(array $entities, array $args, ResolveInfo $info) { |
||
194 | |||
195 | } |
||
196 |