RegistrationRequest::parseValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 8
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\GraphQL\Type;
6
7
use Andi\GraphQL\Definition\Field\TypeAwareInterface;
8
use Andi\GraphQL\Definition\Type\ParseValueAwareInterface;
9
use Andi\GraphQL\Type\AbstractInputObjectType;
10
use GraphQL\Type\Definition\StringType;
11
12
final class RegistrationRequest extends AbstractInputObjectType implements ParseValueAwareInterface
13
{
14
    protected string $name = 'RegistrationRequest';
15
16
    protected iterable $fields = [
17
        'lastname' => 'String',
18
        'firstname' => [
19
            'type' => StringType::class,
20
            'mode' => TypeAwareInterface::IS_REQUIRED,
21
        ],
22
        'middlename' => [
23
            'type' => 'String',
24
            'defaultValue' => null,
25
        ],
26
    ];
27
28
    public static function parseValue(array $values): object
29
    {
30
        $object = new \stdClass();
31
        $object->lastname = $values['lastname'] ?? 'Smith';
32
        $object->firstname = $values['firstname'];
33
        $object->middlename = $values['middlename'] ?? 'junior';
34
35
        return $object;
36
    }
37
}
38