Completed
Pull Request — master (#24)
by David
01:44
created

Type   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 6
dl 0
loc 27
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getClass() 0 3 1
A __construct() 0 6 2
1
<?php
2
3
4
namespace TheCodingMachine\GraphQL\Controllers\Annotations;
5
6
use TheCodingMachine\GraphQL\Controllers\MissingAnnotationException;
7
8
/**
9
 * The Type annotation must be put in a GraphQL type class docblock and is used to map to the underlying PHP class
10
 * this is exposed via this type.
11
 *
12
 * @Annotation
13
 * @Target({"CLASS"})
14
 * @Attributes({
15
 *   @Attribute("class", type = "string"),
16
 * })
17
 */
18
class Type
19
{
20
    /**
21
     * @var string
22
     */
23
    private $className;
24
25
    /**
26
     * @param mixed[] $attributes
27
     */
28
    public function __construct(array $attributes = [])
29
    {
30
        if (!isset($attributes['class'])) {
31
            throw new MissingAnnotationException('In annotation @Type, missing compulsory parameter "class".');
32
        }
33
        $this->className = $attributes['class'];
34
    }
35
36
    /**
37
     * Returns the name of the GraphQL query/mutation/field.
38
     * If not specified, the name of the method should be used instead.
39
     *
40
     * @return string
41
     */
42
    public function getClass(): string
43
    {
44
        return $this->className;
45
    }
46
}
47