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

Breadcrumbs   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 73
Duplicated Lines 16.44 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 12
loc 73
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 12 12 1
A __construct() 0 14 1
A resolveSubrequest() 0 3 1

How to fix   Duplicated Code   

Duplicated Code

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
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