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 |
||
| 26 | class EntityQueryEntities extends FieldPluginBase implements ContainerFactoryPluginInterface { |
||
|
|
|||
| 27 | use DependencySerializationTrait; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * The entity buffer service. |
||
| 31 | * |
||
| 32 | * @var \Drupal\graphql\GraphQL\Buffers\EntityBuffer |
||
| 33 | */ |
||
| 34 | protected $entityBuffer; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * The entity type manager service. |
||
| 38 | * |
||
| 39 | * @var \Drupal\Core\Entity\EntityTypeManagerInterface |
||
| 40 | */ |
||
| 41 | protected $entityTypeManager; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * EntityQueryEntities constructor. |
||
| 45 | * |
||
| 46 | * @param array $configuration |
||
| 47 | * The plugin configuration array. |
||
| 48 | * @param string $pluginId |
||
| 49 | * The plugin id. |
||
| 50 | * @param mixed $pluginDefinition |
||
| 51 | * The plugin definition array. |
||
| 52 | * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager |
||
| 53 | * The entity type manager service. |
||
| 54 | * @param \Drupal\graphql\GraphQL\Buffers\EntityBuffer $entityBuffer |
||
| 55 | * The entity buffer service. |
||
| 56 | */ |
||
| 57 | public function __construct( |
||
| 68 | |||
| 69 | /** |
||
| 70 | * {@inheritdoc} |
||
| 71 | */ |
||
| 72 | public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition) { |
||
| 81 | |||
| 82 | /** |
||
| 83 | * {@inheritdoc} |
||
| 84 | */ |
||
| 85 | public function resolveValues($value, array $args, ResolveInfo $info) { |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Resolves entities lazily through the entity buffer. |
||
| 101 | * |
||
| 102 | * @param string $type |
||
| 103 | * The entity type. |
||
| 104 | * @param array $ids |
||
| 105 | * The entity ids to load. |
||
| 106 | * |
||
| 107 | * @return \Closure |
||
| 108 | * The deferred resolver. |
||
| 109 | */ |
||
| 110 | protected function resolveFromEntityIds($type, $ids) { |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Resolves entity revisions. |
||
| 119 | * |
||
| 120 | * @param string $type |
||
| 121 | * The entity type. |
||
| 122 | * @param array $ids |
||
| 123 | * The entity revision ids to load. |
||
| 124 | * |
||
| 125 | * @return \Generator |
||
| 126 | * The resolved revisions. |
||
| 127 | */ |
||
| 128 | protected function resolveFromRevisionIds($type, $ids) { |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Resolves entity objects and checks view permissions. |
||
| 139 | * |
||
| 140 | * @param array $entities |
||
| 141 | * The entities to resolve. |
||
| 142 | * |
||
| 143 | * @return \Generator |
||
| 144 | * The resolved entities. |
||
| 145 | */ |
||
| 146 | protected function resolveEntities(array $entities) { |
||
| 159 | |||
| 160 | } |
||
| 161 |