Completed
Push — 8.x-3.x ( f26ecc...a804f1 )
by Sebastian
06:01 queued 02:20
created

Translate::resolveValues()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 6
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 3
dl 6
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\graphql_core\Plugin\GraphQL\Fields\Routing;
4
5
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
6
use Drupal\Core\Language\LanguageManagerInterface;
7
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
8
use Drupal\Core\Url;
9
use Drupal\graphql\Plugin\GraphQL\Fields\FieldPluginBase;
10
use Symfony\Component\DependencyInjection\ContainerInterface;
11
use Youshido\GraphQL\Execution\ResolveInfo;
12
13
/**
14
 * @GraphQLField(
15
 *   id = "url_translate",
16
 *   secure = true,
17
 *   name = "translate",
18
 *   description = @Translation("The translated url object."),
19
 *   type = "Url",
20
 *   parents = {"Url"},
21
 *   arguments = {
22
 *     "language" = "LanguageId!"
23
 *   }
24
 * )
25
 */
26 View Code Duplication
class Translate extends FieldPluginBase implements ContainerFactoryPluginInterface {
0 ignored issues
show
Duplication introduced by
This class 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...
Bug introduced by
There is one abstract method getPluginDefinition in this class; you could implement it, or declare this class as abstract.
Loading history...
27
  use DependencySerializationTrait;
28
29
  /**
30
   * The language manager service.
31
   *
32
   * @var \Drupal\Core\Language\LanguageManagerInterface
33
   */
34
  protected $languageManager;
35
36
  /**
37
   * {@inheritdoc}
38
   */
39
  public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition) {
40
    return new static(
41
      $configuration,
42
      $pluginId,
43
      $pluginDefinition,
44
      $container->get('language_manager')
45
    );
46
  }
47
48
  /**
49
   * Alias constructor.
50
   *
51
   * @param array $configuration
52
   *   The plugin configuration array.
53
   * @param string $pluginId
54
   *   The plugin id.
55
   * @param mixed $pluginDefinition
56
   *   The plugin definition.
57
   * @param \Drupal\Core\Language\LanguageManagerInterface $languageManager
58
   *   The language manager service.
59
   */
60
  public function __construct(
61
    array $configuration,
62
    $pluginId,
63
    $pluginDefinition,
64
    LanguageManagerInterface $languageManager
65
  ) {
66
    parent::__construct($configuration, $pluginId, $pluginDefinition);
67
    $this->languageManager = $languageManager;
68
  }
69
70
  /**
71
   * {@inheritdoc}
72
   */
73
  public function resolveValues($value, array $args, ResolveInfo $info) {
74
    if ($value instanceof Url) {
0 ignored issues
show
Bug introduced by
The class Drupal\Core\Url does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
75
      $language =  $this->languageManager->getLanguage($args['language']);
76
      yield (clone $value)->setOption('language', $language);
77
    }
78
  }
79
80
}
81