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

ID   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 7
dl 0
loc 23
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 3 1
A __construct() 0 6 4
A val() 0 3 1
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