Completed
Push — 8.x-3.x ( e67c0e...2e01b0 )
by Philipp
02:27
created

ObjectType::applies()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 2
dl 0
loc 7
rs 9.4285
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
  public function getName() {
30
    return $this->getConfigValue('name');
31
  }
32
33
  /**
34
   * Checks whether this type applies to a given object.
35
   *
36
   * @param mixed $object
37
   *   The object to check against.
38
   * @param \Youshido\GraphQL\Execution\ResolveInfo|null $info
39
   *   The resolve info object.
40
   *
41
   * @return bool
42
   *   TRUE if this type applies to the given object, FALSE otherwise.
43
   */
44
  public function applies($object, ResolveInfo $info = NULL) {
45
    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 44 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...
46
      return $plugin->applies($object);
47
    }
48
49
    return FALSE;
50
  }
51
52
  /**
53
   * {@inheritdoc}
54
   */
55
  public function build($config) {
56
    // Nothing to do here.
57
  }
58
59
}
60