Completed
Push — 8.x-3.x ( 32ff4d...d01c55 )
by Sebastian
05:23 queued 02:25
created

Breadcrumbs::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 8
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace Drupal\graphql_core\Plugin\GraphQL\Fields\Breadcrumbs;
4
5
use Drupal\Core\Breadcrumb\BreadcrumbManager;
6
use Drupal\Core\Routing\RouteMatchInterface;
7
use Drupal\graphql\GraphQL\Batching\BatchedFieldResolver;
8
use Drupal\graphql\Plugin\GraphQL\Fields\SubrequestFieldBase;
9
use Symfony\Component\DependencyInjection\ContainerInterface;
10
use Symfony\Component\HttpFoundation\RequestStack;
11
use Symfony\Component\HttpKernel\HttpKernelInterface;
12
use Youshido\GraphQL\Execution\ResolveInfo;
13
14
/**
15
 * Retrieve the breadcrumbs.
16
 *
17
 * TODO: Move this to `InternalUrl` (breaking change).
18
 *
19
 * @GraphQLField(
20
 *   id = "breadcrumb",
21
 *   secure = true,
22
 *   name = "breadcrumb",
23
 *   type = "Link",
24
 *   multi = true,
25
 *   parents = {"Url"},
26
 * )
27
 */
28
class Breadcrumbs extends SubrequestFieldBase {
29
30
  /**
31
   * The breadcrumb manager.
32
   *
33
   * @var \Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface
34
   */
35
  protected $breadcrumbManager;
36
37
  /**
38
   * The current route match.
39
   *
40
   * @var \Drupal\Core\Routing\RouteMatchInterface
41
   */
42
  protected $routeMatch;
43
44
  /**
45
   * The request stack.
46
   *
47
   * @var \Symfony\Component\HttpFoundation\RequestStack
48
   */
49
  protected $requestStack;
50
51
  /**
52
   * A http kernel to issue sub-requests to.
53
   *
54
   * @var \Symfony\Component\HttpKernel\HttpKernelInterface
55
   */
56
  protected $httpKernel;
57
58
59
  /**
60
   * {@inheritdoc}
61
   */
62 View Code Duplication
  public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
    return new static(
64
      $configuration,
65
      $pluginId,
66
      $pluginDefinition,
67
      $container->get('http_kernel'),
68
      $container->get('request_stack'),
69
      $container->get('graphql.batched_resolver'),
70
      $container->get('breadcrumb'),
71
      $container->get('current_route_match')
72
    );
73
  }
74
75
  /**
76
   * {@inheritdoc}
77
   */
78
  public function __construct(
79
    array $configuration,
80
    $pluginId,
81
    $pluginDefinition,
82
    HttpKernelInterface $httpKernel,
83
    RequestStack $requestStack,
84
    BatchedFieldResolver $batchedFieldResolver,
85
    BreadcrumbManager $breadcrumbManager,
86
    RouteMatchInterface $routeMatch
87
  ) {
88
    $this->breadcrumbManager = $breadcrumbManager;
0 ignored issues
show
Documentation Bug introduced by
It seems like $breadcrumbManager of type object<Drupal\Core\Breadcrumb\BreadcrumbManager> is incompatible with the declared type object<Drupal\Core\Bread...dcrumbBuilderInterface> of property $breadcrumbManager.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
89
    $this->routeMatch = $routeMatch;
90
    parent::__construct($configuration, $pluginId, $pluginDefinition, $httpKernel, $requestStack, $batchedFieldResolver);
91
  }
92
93
  /**
94
   * {@inheritdoc}
95
   */
96
  protected function resolveSubrequest($value, array $args, ResolveInfo $info) {
97
    return $this->breadcrumbManager->build($this->routeMatch)->getLinks();
98
  }
99
100
}
101