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

Type::getClass()   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
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
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