Completed
Pull Request — 8.x-3.x (#550)
by Philipp
02:14
created

LanguageNegotiationGraphQL::getLangcode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Drupal\graphql\Plugin\LanguageNegotiation;
4
5
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
6
use Drupal\graphql\GraphQLLanguageContext;
7
use Drupal\language\LanguageNegotiationMethodBase;
8
use Symfony\Component\DependencyInjection\ContainerInterface;
9
use Symfony\Component\HttpFoundation\Request;
10
11
/**
12
 * Class for identifying language from a selected language.
13
 *
14
 * @LanguageNegotiation(
15
 *   id = Drupal\graphql\Plugin\LanguageNegotiation\LanguageNegotiationGraphQL::METHOD_ID,
16
 *   weight = 12,
17
 *   name = @Translation("GraphQL context"),
18
 *   description = @Translation("The current GraphQL language context. Only available while executing a query.")
19
 * )
20
 */
21
class LanguageNegotiationGraphQL extends LanguageNegotiationMethodBase implements ContainerFactoryPluginInterface {
22
23
  /**
24
   * The graphql language context.
25
   *
26
   * @var \Drupal\graphql\GraphQLLanguageContext
27
   */
28
  protected $languageContext;
29
30
  /**
31
   * {@inheritdoc}
32
   */
33
  public static function create(
34
    ContainerInterface $container,
35
    array $configuration,
36
    $plugin_id,
37
    $plugin_definition
38
  ) {
39
    return new static($container->get('graphql.language_context'));
40
  }
41
42
  /**
43
   * LanguageNegotiationGraphQL constructor.
44
   *
45
   * @param \Drupal\graphql\GraphQLLanguageContext $languageContext
46
   *   Instance of the GraphQL language context.
47
   */
48
  public function __construct(GraphQLLanguageContext $languageContext) {
49
    $this->languageContext = $languageContext;
50
  }
51
52
  /**
53
   * The language negotiation method id.
54
   */
55
  const METHOD_ID = 'language-graphql';
56
57
  /**
58
   * {@inheritdoc}
59
   */
60
  public function getLangcode(Request $request = NULL) {
61
    die('Hi Travis!');
0 ignored issues
show
Coding Style Compatibility introduced by
The method getLangcode() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
62
    return $this->languageContext->getCurrentLanguage();
0 ignored issues
show
Unused Code introduced by
return $this->languageCo...->getCurrentLanguage(); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
63
  }
64
65
}
66