JsonObjectKeys::resolveValues()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 4
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\graphql_json\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
 * Retrieve the keys of a json object.
11
 *
12
 * @GraphQLField(
13
 *   id = "json_object_keys",
14
 *   secure = true,
15
 *   name = "keys",
16
 *   type = "String",
17
 *   multi = true,
18
 *   parents = {"JsonObject"}
19
 * )
20
 */
21
class JsonObjectKeys extends FieldPluginBase {
22
23
  /**
24
   * {@inheritdoc}
25
   */
26
  public function resolveValues($value, array $args, ResolveContext $context, ResolveInfo $info) {
27
    foreach (array_keys($value) as $key) {
28
      yield $key;
29
    }
30
  }
31
32
}
33