Passed
Pull Request — master (#45)
by Andrey
13:21
created

Money   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 33
rs 10
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getDescription() 0 3 1
A serialize() 0 5 2
A parseValue() 0 5 2
A parseLiteral() 0 7 2
A getName() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\GraphQL\Type;
6
7
use Andi\GraphQL\Definition\Type\ScalarTypeInterface;
8
use GraphQL\Error\Error;
9
use GraphQL\Error\SerializationError;
10
use GraphQL\Language\AST\IntValueNode;
11
use GraphQL\Language\AST\Node;
12
13
final class Money implements ScalarTypeInterface
14
{
15
    public function getName(): string
16
    {
17
        return 'Money';
18
    }
19
20
    public function getDescription(): ?string
21
    {
22
        return null;
23
    }
24
25
    public function serialize(mixed $value): int
26
    {
27
        return is_int($value)
28
            ? $value
29
            : throw new SerializationError("Int cannot represent non-integer value");
30
    }
31
32
    public function parseValue(mixed $value): int
33
    {
34
        return is_int($value)
35
            ? $value
36
            : throw new Error("Int cannot represent non-integer value");
37
    }
38
39
    public function parseLiteral(Node $valueNode, ?array $variables = null): int
40
    {
41
        if ($valueNode instanceof IntValueNode) {
42
            return (int) $valueNode->value;
43
        }
44
45
        throw new Error("Int cannot represent non-integer value", $valueNode);
0 ignored issues
show
Bug introduced by
$valueNode of type GraphQL\Language\AST\Node is incompatible with the type iterable expected by parameter $nodes of GraphQL\Error\Error::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
        throw new Error("Int cannot represent non-integer value", /** @scrutinizer ignore-type */ $valueNode);
Loading history...
46
    }
47
}
48