Completed
Push — split-exclusion-strategies ( e073a8 )
by Nate
03:36
created

DefaultClassMetadata::getProperty()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 * Copyright (c) Nate Brunette.
4
 * Distributed under the MIT License (http://opensource.org/licenses/MIT)
5
 */
6
7
declare(strict_types=1);
8
9
namespace Tebru\Gson\Internal;
10
11
use Tebru\AnnotationReader\AbstractAnnotation;
12
use Tebru\AnnotationReader\AnnotationCollection;
13
use Tebru\Gson\ClassMetadata;
14
use Tebru\Gson\Internal\Data\PropertyCollection;
15
16
/**
17
 * Class DefaultClassMetadata
18
 *
19
 * Represents a class an its annotations
20
 *
21
 * @author Nate Brunette <[email protected]>
22
 */
23
final class DefaultClassMetadata implements ClassMetadata
24
{
25
    /**
26
     * The class name
27
     *
28
     * @var string
29
     */
30
    private $name;
31
32
    /**
33
     * The class annotations
34
     *
35
     * @var AnnotationCollection
36
     */
37
    private $annotations;
38
39
    /**
40
     * @var PropertyCollection
41
     */
42
    private $properties;
43
44
    /**
45
     * @var bool
46
     */
47
    private $skipSerialize = false;
48
49
    /**
50
     * @var bool
51
     */
52
    private $skipDeserialize = false;
53
54
    /**
55
     * Constructor
56
     *
57
     * @param string $name
58
     * @param AnnotationCollection $annotations
59
     * @param PropertyCollection $properties
60
     */
61
    public function __construct(string $name, AnnotationCollection $annotations, PropertyCollection $properties)
62
    {
63
        $this->name = $name;
64
        $this->annotations = $annotations;
65
        $this->properties = $properties;
66
    }
67
68
    /**
69
     * Get the class name as a string
70
     *
71
     * @return string
72
     */
73
    public function getName(): string
74
    {
75
        return $this->name;
76
    }
77
78
    /**
79
     * Get all class annotations
80
     *
81
     * @return AnnotationCollection
82
     */
83
    public function getAnnotations(): AnnotationCollection
84
    {
85
        return $this->annotations;
86
    }
87
88
    /**
89
     * Get a specific annotation by class name, returns null if the annotation
90
     * doesn't exist.
91
     *
92
     * @param string $annotationClass
93
     * @return null|AbstractAnnotation
94
     */
95
    public function getAnnotation(string $annotationClass): ?AbstractAnnotation
96
    {
97
        return $this->annotations->get($annotationClass);
98
    }
99
100
    /**
101
     * Returns a [@see PropertyCollection] of all the class properties
102
     *
103
     * @return PropertyCollection
104
     */
105
    public function getProperties(): PropertyCollection
106
    {
107
        return $this->properties;
108
    }
109
110
    /**
111
     * If the class should be skipped during serialization
112
     *
113
     * @return bool
114
     */
115
    public function skipSerialize(): bool
116
    {
117
        return $this->skipSerialize;
118
    }
119
120
    /**
121
     * Set if we should skip serialization
122
     *
123
     * @param bool $skipSerialize
124
     */
125
    public function setSkipSerialize(bool $skipSerialize): void
126
    {
127
        $this->skipSerialize = $skipSerialize;
128
    }
129
130
    /**
131
     * If the class should be skipped during deserialization
132
     *
133
     * @return bool
134
     */
135
    public function skipDeserialize(): bool
136
    {
137
        return $this->skipDeserialize;
138
    }
139
140
    /**
141
     * Set if we should skip deserialization
142
     *
143
     * @param bool $skipDeserialize
144
     */
145
    public function setSkipDeserialize(bool $skipDeserialize): void
146
    {
147
        $this->skipDeserialize = $skipDeserialize;
148
    }
149
}
150