Completed
Push — master ( ac0b2b...25e509 )
by Nate
02:57
created

ClassMetadata::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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