Breadcrumbs::resolveValues()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 14
rs 9.9666
cc 3
nc 2
nop 4
1
<?php
2
3
namespace Drupal\graphql_core\Plugin\GraphQL\Fields\Breadcrumbs;
4
5
use Drupal\Core\Breadcrumb\BreadcrumbManager;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Breadcrumb\BreadcrumbManager was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Plugin\ContainerFactoryPluginInterface was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Drupal\Core\Routing\RouteMatchInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Routing\RouteMatchInterface was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Drupal\Core\Url;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Url was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Drupal\graphql\GraphQL\Buffers\SubRequestBuffer;
10
use Drupal\graphql\GraphQL\Cache\CacheableValue;
11
use Drupal\graphql\GraphQL\Execution\ResolveContext;
12
use Drupal\graphql\Plugin\GraphQL\Fields\FieldPluginBase;
13
use Symfony\Component\DependencyInjection\ContainerInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Depend...tion\ContainerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use GraphQL\Type\Definition\ResolveInfo;
15
16
/**
17
 * Retrieve the breadcrumbs.
18
 *
19
 * @GraphQLField(
20
 *   id = "breadcrumb",
21
 *   secure = true,
22
 *   name = "breadcrumb",
23
 *   type = "[Link]",
24
 *   parents = {"InternalUrl"},
25
 * )
26
 */
27
class Breadcrumbs extends FieldPluginBase implements ContainerFactoryPluginInterface {
28
29
  /**
30
   * The subrequest buffer service.
31
   *
32
   * @var \Drupal\graphql\GraphQL\Buffers\SubRequestBuffer
33
   */
34
  protected $subRequestBuffer;
35
36
  /**
37
   * The breadcrumb manager service.
38
   *
39
   * @var \Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
40
   */
41
  protected $breadcrumbManager;
42
43
  /**
44
   * The current route match.
45
   *
46
   * @var \Drupal\Core\Routing\RouteMatchInterface
47
   */
48
  protected $routeMatch;
49
50
  /**
51
   * {@inheritdoc}
52
   */
53
  public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition) {
54
    return new static(
55
      $configuration,
56
      $pluginId,
57
      $pluginDefinition,
58
      $container->get('graphql.buffer.subrequest'),
59
      $container->get('breadcrumb'),
60
      $container->get('current_route_match')
61
    );
62
  }
63
64
  /**
65
   * Breadcrumbs constructor.
66
   *
67
   * @param array $configuration
68
   *   The plugin configuration array.
69
   * @param string $pluginId
70
   *   The plugin id.
71
   * @param mixed $pluginDefinition
72
   *   The plugin definition.
73
   * @param \Drupal\graphql\GraphQL\Buffers\SubRequestBuffer $subRequestBuffer
74
   *   The sub-request buffer service.
75
   * @param \Drupal\Core\Breadcrumb\BreadcrumbManager $breadcrumbManager
76
   *   The breadcrumb manager service.
77
   * @param \Drupal\Core\Routing\RouteMatchInterface $routeMatch
78
   *   The current route match.
79
   */
80
  public function __construct(
81
    array $configuration,
82
    $pluginId,
83
    $pluginDefinition,
84
    SubRequestBuffer $subRequestBuffer,
85
    BreadcrumbManager $breadcrumbManager,
86
    RouteMatchInterface $routeMatch
87
  ) {
88
    parent::__construct($configuration, $pluginId, $pluginDefinition);
89
    $this->subRequestBuffer = $subRequestBuffer;
90
    $this->breadcrumbManager = $breadcrumbManager;
91
    $this->routeMatch = $routeMatch;
92
  }
93
94
  /**
95
   * {@inheritdoc}
96
   */
97
  protected function resolveValues($value, array $args, ResolveContext $context, ResolveInfo $info) {
98
    if ($value instanceof Url) {
99
      $resolve = $this->subRequestBuffer->add($value, function () {
100
        $links = $this->breadcrumbManager->build($this->routeMatch)->getLinks();
101
        return $links;
102
      });
103
104
      return function ($value, array $args, ResolveContext $context, ResolveInfo $info) use ($resolve) {
0 ignored issues
show
Unused Code introduced by
The parameter $args is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

104
      return function ($value, /** @scrutinizer ignore-unused */ array $args, ResolveContext $context, ResolveInfo $info) use ($resolve) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $context is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

104
      return function ($value, array $args, /** @scrutinizer ignore-unused */ ResolveContext $context, ResolveInfo $info) use ($resolve) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $info is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

104
      return function ($value, array $args, ResolveContext $context, /** @scrutinizer ignore-unused */ ResolveInfo $info) use ($resolve) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $value is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

104
      return function (/** @scrutinizer ignore-unused */ $value, array $args, ResolveContext $context, ResolveInfo $info) use ($resolve) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
105
        /** @var \Drupal\graphql\GraphQL\Cache\CacheableValue $response */
106
        $response = $resolve();
107
        $links = $response->getValue();
108
109
        foreach ($links as $link) {
110
          yield new CacheableValue($link, [$response]);
111
        }
112
      };
113
    }
114
  }
115
116
}
117