Passed
Pull Request — master (#87)
by David
02:38
created

ID::val()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace TheCodingMachine\GraphQL\Controllers\Types;
3
4
5
use TheCodingMachine\GraphQL\Controllers\GraphQLException;
6
7
/**
8
 * A class that maps to the GraphQL ID type.
9
 */
10
class ID
11
{
12
    private $value;
13
14
    public function __construct($value)
15
    {
16
        if (! is_scalar($value) && (! is_object($value) || ! method_exists($value, '__toString'))) {
17
            throw new GraphQLException('ID constructor cannot be passed a non scalar value.');
18
        }
19
        $this->value = $value;
20
    }
21
22
    /**
23
     * @return bool|float|int|string
24
     */
25
    public function val()
26
    {
27
        return $this->value;
28
    }
29
30
    public function __toString()
31
    {
32
        return (string) $this->value;
33
    }
34
}
35