Completed
Push — 8.x-3.x ( 2e01b0...c986a7 )
by Sebastian
02:33
created

ObjectType::getConfigValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\graphql\GraphQL\Type;
4
5
use Drupal\graphql\GraphQL\CacheableEdgeInterface;
6
use Drupal\graphql\GraphQL\CacheableEdgeTrait;
7
use Drupal\graphql\Plugin\GraphQL\Types\TypePluginBase;
8
use Drupal\graphql\Plugin\GraphQL\TypeSystemPluginReferenceInterface;
9
use Drupal\graphql\Plugin\GraphQL\TypeSystemPluginReferenceTrait;
10
use Youshido\GraphQL\Config\Object\ObjectTypeConfig;
11
use Youshido\GraphQL\Execution\ResolveInfo;
12
use Youshido\GraphQL\Type\Object\AbstractObjectType;
13
14
class ObjectType extends AbstractObjectType implements TypeSystemPluginReferenceInterface, CacheableEdgeInterface  {
15
  use TypeSystemPluginReferenceTrait;
16
  use CacheableEdgeTrait;
17
18
  /**
19
   * {@inheritdoc}
20
   */
21
  public function __construct(TypePluginBase $plugin, array $config = []) {
22
    $this->plugin = $plugin;
23
    $this->config = new ObjectTypeConfig($config, $this, TRUE);
24
  }
25
26
  /**
27
   * {@inheritdoc}
28
   */
29
  protected function getConfigValue($key, $default = NULL) {
30
    return !empty($this->config) ? $this->config->get($key, $default) : $default;
31
  }
32
33
  /**
34
   * {@inheritdoc}
35
   */
36
  public function getName() {
37
    return $this->getConfigValue('name');
38
  }
39
40
  /**
41
   * Checks whether this type applies to a given object.
42
   *
43
   * @param mixed $object
44
   *   The object to check against.
45
   * @param \Youshido\GraphQL\Execution\ResolveInfo|null $info
46
   *   The resolve info object.
47
   *
48
   * @return bool
49
   *   TRUE if this type applies to the given object, FALSE otherwise.
50
   */
51
  public function applies($object, ResolveInfo $info = NULL) {
52
    if (($plugin = $this->getPluginFromResolveInfo($info)) && $plugin instanceof TypePluginBase) {
0 ignored issues
show
Bug introduced by
It seems like $info defined by parameter $info on line 51 can be null; however, Drupal\graphql\Plugin\Gr...PluginFromResolveInfo() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
53
      return $plugin->applies($object);
54
    }
55
56
    return FALSE;
57
  }
58
59
  /**
60
   * {@inheritdoc}
61
   */
62
  public function build($config) {
63
    // Nothing to do here.
64
  }
65
66
}
67