| Conditions | 10 |
| Paths | 1 |
| Total Lines | 55 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 71 | public function resolve($value, array $args, ResolveContext $context, ResolveInfo $info) { |
||
| 72 | // There are cases where the Drupal entity API calls emit the cache metadata |
||
| 73 | // in the current render context. In such cases |
||
| 74 | // EarlyRenderingControllerWrapperSubscriber throws the leaked cache |
||
| 75 | // metadata exception. To avoid this, wrap the execution in its own render |
||
| 76 | // context. |
||
| 77 | return $this->renderer->executeInRenderContext(new RenderContext(), function () use ($value, $args, $context, $info) { |
||
| 78 | $entityTypeId = $this->pluginDefinition['entity_type']; |
||
| 79 | $bundleName = $this->pluginDefinition['entity_bundle']; |
||
| 80 | $storage = $this->entityTypeManager->getStorage($entityTypeId); |
||
| 81 | |||
| 82 | /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ |
||
| 83 | if (!$entity = $storage->load($args['id'])) { |
||
| 84 | return new EntityCrudOutputWrapper(NULL, NULL, [ |
||
| 85 | $this->t('The requested @bundle could not be loaded.', ['@bundle' => $bundleName]), |
||
| 86 | ]); |
||
| 87 | } |
||
| 88 | |||
| 89 | if (!$entity->bundle() === $bundleName) { |
||
| 90 | return new EntityCrudOutputWrapper(NULL, NULL, [ |
||
| 91 | $this->t('The requested entity is not of the expected type @bundle.', ['@bundle' => $bundleName]), |
||
| 92 | ]); |
||
| 93 | } |
||
| 94 | |||
| 95 | if (!$entity->access('update')) { |
||
| 96 | return new EntityCrudOutputWrapper(NULL, NULL, [ |
||
| 97 | $this->t('You do not have the necessary permissions to update this @bundle.', ['@bundle' => $bundleName]), |
||
| 98 | ]); |
||
| 99 | } |
||
| 100 | |||
| 101 | // The raw input needs to be converted to use the proper field and property |
||
| 102 | // keys because we usually convert them to camel case when adding them to |
||
| 103 | // the schema. Allow the other implementations to control this easily. |
||
| 104 | $input = $this->extractEntityInput($value, $args, $context, $info); |
||
| 105 | |||
| 106 | try { |
||
| 107 | foreach ($input as $key => $value) { |
||
| 108 | $entity->get($key)->setValue($value); |
||
| 109 | } |
||
| 110 | } |
||
| 111 | catch (\InvalidArgumentException $exception) { |
||
| 112 | return new EntityCrudOutputWrapper(NULL, NULL, [ |
||
| 113 | $this->t('The entity update failed with exception: @exception.', ['@exception' => $exception->getMessage()]), |
||
| 114 | ]); |
||
| 115 | } |
||
| 116 | |||
| 117 | if (($violations = $entity->validate()) && $violations->count()) { |
||
| 118 | return new EntityCrudOutputWrapper(NULL, $violations); |
||
| 119 | } |
||
| 120 | |||
| 121 | if (($status = $entity->save()) && $status === SAVED_UPDATED) { |
||
| 122 | return new EntityCrudOutputWrapper($entity); |
||
| 123 | } |
||
| 124 | |||
| 125 | return NULL; |
||
| 126 | }); |
||
| 149 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths