XMLXPath   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 15
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A resolveValues() 0 8 3
1
<?php
2
3
namespace Drupal\graphql_xml\Plugin\GraphQL\Fields;
4
5
use Drupal\graphql\GraphQL\Execution\ResolveContext;
6
use Drupal\graphql\Plugin\GraphQL\Fields\FieldPluginBase;
7
use GraphQL\Type\Definition\ResolveInfo;
8
9
/**
10
 * Evaluate a XPath query on the current element.
11
 *
12
 * @GraphQLField(
13
 *   id = "xml_xpath",
14
 *   secure = true,
15
 *   type = "XMLElement",
16
 *   multi = true,
17
 *   arguments = {
18
 *     "query" = "String"
19
 *   },
20
 *   name = "xpath",
21
 *   parents = { "XMLElement" }
22
 * )
23
 */
24
class XMLXPath extends FieldPluginBase {
25
26
  /**
27
   * {@inheritdoc}
28
   */
29
  protected function resolveValues($value, array $args, ResolveContext $context, ResolveInfo $info) {
30
    if ($value instanceof \DOMElement) {
31
      $xpath = new \DOMXPath($value->ownerDocument);
32
      foreach ($xpath->query($args['query'], $value) as $item) {
33
        yield $item;
34
      }
35
    }
36
  }
37
38
}
39