AbstractUpdateEntityField   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 55
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 4 1
A getDescription() 0 3 1
A getEntityKey() 0 3 1
A resolve() 0 5 1
1
<?php
2
3
namespace Digia\Lumen\GraphQL\Fields;
4
5
use Digia\Lumen\GraphQL\Models\ResolveContext;
6
use Digia\Lumen\GraphQL\Traits\ResolvesNodesTrait;
7
use Youshido\GraphQL\Config\Field\FieldConfig;
8
use Youshido\GraphQL\Execution\ResolveInfo;
9
use Youshido\GraphQL\Field\AbstractField;
10
use Youshido\GraphQL\Type\InputObject\AbstractInputObjectType;
11
use Youshido\GraphQL\Type\NonNullType;
12
use Youshido\GraphQL\Type\Scalar\IdType;
13
14
/**
15
 * Class AbstractUpdateEntityField
16
 * @package Digia\Lumen\GraphQL\Fields
17
 */
18
abstract class AbstractUpdateEntityField extends AbstractField
19
{
20
21
    use ResolvesNodesTrait;
22
23
    /**
24
     * @return string
25
     */
26
    abstract protected function getEntityTypeName();
27
28
    /**
29
     * @return AbstractInputObjectType
30
     */
31
    abstract protected function getInputType();
32
33
    /**
34
     * @param ResolveContext $context
35
     * @return mixed
36
     */
37
    abstract protected function updateEntity(ResolveContext $context);
38
39
    /**
40
     * @inheritdoc
41
     */
42
    public function getDescription()
43
    {
44
        return 'Updates an existing entity.';
45
    }
46
47
    /**
48
     * @inheritdoc
49
     */
50
    public function build(FieldConfig $config)
51
    {
52
        $config->addArgument('id', new NonNullType(new IdType()));
53
        $config->addArgument($this->getEntityKey(), new NonNullType($this->getInputType()));
54
    }
55
56
    /**
57
     * @inheritdoc
58
     * @suppress PhanTypeMismatchArgument
59
     */
60
    public function resolve($value, array $args, ResolveInfo $info)
61
    {
62
        $context = new ResolveContext($value, $args, $info);
63
64
        return $this->updateEntity($context);
65
    }
66
67
    /**
68
     * @inheritdoc
69
     */
70
    protected function getEntityKey()
71
    {
72
        return camel_case($this->getEntityTypeName());
73
    }
74
}
75