Completed
Push — master ( 1f9c9a...dbd6f1 )
by Nate
04:38
created

DefaultClassMetadata::getAnnotations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/*
3
 * Copyright (c) Nate Brunette.
4
 * Distributed under the MIT License (http://opensource.org/licenses/MIT)
5
 */
6
7
namespace Tebru\Gson\Internal;
8
9
use Tebru\Gson\ClassMetadata;
10
use Tebru\Gson\Internal\Data\AnnotationSet;
11
12
/**
13
 * Class DefaultClassMetadata
14
 *
15
 * Represents a class an its annotations
16
 *
17
 * @author Nate Brunette <[email protected]>
18
 */
19
final class DefaultClassMetadata implements ClassMetadata
20
{
21
    /**
22
     * The class name
23
     *
24
     * @var string
25
     */
26
    private $name;
27
28
    /**
29
     * The class annotations
30
     *
31
     * @var AnnotationSet
32
     */
33
    private $annotations;
34
35
    /**
36
     * Constructor
37
     *
38
     * @param string $name
39
     * @param AnnotationSet $annotations
40
     */
41 8
    public function __construct(string $name, AnnotationSet $annotations)
42
    {
43 8
        $this->name = $name;
44 8
        $this->annotations = $annotations;
45 8
    }
46
47
    /**
48
     * Get the class name as a string
49
     *
50
     * @return string
51
     */
52 2
    public function getName(): string
53
    {
54 2
        return $this->name;
55
    }
56
57
    /**
58
     * Get all class annotations
59
     *
60
     * @return AnnotationSet
61
     */
62 1
    public function getAnnotations(): AnnotationSet
63
    {
64 1
        return $this->annotations;
65
    }
66
67
    /**
68
     * Get a specific annotation by class name, returns null if the annotation
69
     * doesn't exist.
70
     *
71
     * @param string $annotationClass
72
     * @return null|object
73
     */
74 2
    public function getAnnotation(string $annotationClass)
75
    {
76 2
        return $this->annotations->getAnnotation($annotationClass, AnnotationSet::TYPE_CLASS);
77
    }
78
}
79