ExternalRequest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 12
c 0
b 0
f 0
dl 0
loc 54
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A create() 0 11 1
A resolveValues() 0 3 2
1
<?php
2
3
namespace Drupal\graphql_core\Plugin\GraphQL\Fields\Routing\ExternalUrl;
4
5
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\DependencyIn...dencySerializationTrait 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\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...
8
use Drupal\graphql\GraphQL\Execution\ResolveContext;
9
use Drupal\graphql\Plugin\GraphQL\Fields\FieldPluginBase;
10
use GuzzleHttp\ClientInterface;
0 ignored issues
show
Bug introduced by
The type GuzzleHttp\ClientInterface 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...
11
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...
12
use GraphQL\Type\Definition\ResolveInfo;
13
14
/**
15
 * Issue an external request and retrieve the response object.
16
 *
17
 * @GraphQLField(
18
 *   id = "external_url_request",
19
 *   name = "request",
20
 *   type = "ExternalResponse",
21
 *   parents = {"ExternalUrl"}
22
 * )
23
 */
24
class ExternalRequest extends FieldPluginBase implements ContainerFactoryPluginInterface {
25
  use DependencySerializationTrait;
26
27
  /**
28
   * @var \GuzzleHttp\ClientInterface
29
   */
30
  protected $httpClient;
31
32
  /**
33
   * {@inheritdoc}
34
   */
35
  public static function create(
36
    ContainerInterface $container,
37
    array $configuration,
38
    $plugin_id,
39
    $plugin_definition
40
  ) {
41
    return new static(
42
      $configuration,
43
      $plugin_id,
44
      $plugin_definition,
45
      $container->get('http_client')
46
    );
47
  }
48
49
  /**
50
   * ExternalRequest constructor.
51
   *
52
   * @param array $configuration
53
   *   The plugin configuration array.
54
   * @param string $pluginId
55
   *   The plugin id.
56
   * @param mixed $pluginDefinition
57
   *   The plugin definition array.
58
   * @param \GuzzleHttp\ClientInterface $httpClient
59
   *   The http client service.
60
   */
61
  public function __construct(
62
    array $configuration,
63
    $pluginId,
64
    $pluginDefinition,
65
    ClientInterface $httpClient
66
  ) {
67
    parent::__construct($configuration, $pluginId, $pluginDefinition);
68
    $this->httpClient = $httpClient;
69
  }
70
71
72
  /**
73
   * {@inheritdoc}
74
   */
75
  protected function resolveValues($value, array $args, ResolveContext $context, ResolveInfo $info) {
76
    if ($value instanceof Url) {
77
      yield $this->httpClient->request('GET', $value->toString());
78
    }
79
  }
80
81
}
82