Completed
Push — master ( 924012...c1a650 )
by David
16s queued 10s
created

ID::__toString()   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 InvalidArgumentException;
6
use TheCodingMachine\GraphQL\Controllers\GraphQLException;
7
8
/**
9
 * A class that maps to the GraphQL ID type.
10
 */
11
class ID
12
{
13
    private $value;
14
15
    public function __construct($value)
16
    {
17
        if (! is_scalar($value) && (! is_object($value) || ! method_exists($value, '__toString'))) {
18
            throw new InvalidArgumentException('ID constructor cannot be passed a non scalar value.');
19
        }
20
        $this->value = $value;
21
    }
22
23
    /**
24
     * @return bool|float|int|string
25
     */
26
    public function val()
27
    {
28
        return $this->value;
29
    }
30
31
    public function __toString()
32
    {
33
        return (string) $this->value;
34
    }
35
}
36