Passed
Push — master ( 37395a...ba940f )
by Nate
01:20 queued 11s
created

getPropertyMetadataCollection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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
use Tebru\Gson\PropertyMetadata;
16
use Tebru\Gson\PropertyMetadataCollection;
17
18
/**
19
 * Class DefaultClassMetadata
20
 *
21
 * Represents a class an its annotations
22
 *
23
 * @author Nate Brunette <[email protected]>
24
 */
25
final class DefaultClassMetadata implements ClassMetadata
26
{
27
    /**
28
     * The class name
29
     *
30
     * @var string
31
     */
32
    private $name;
33
34
    /**
35
     * The class annotations
36
     *
37
     * @var AnnotationCollection
38
     */
39
    private $annotations;
40
41
    /**
42
     * @var PropertyCollection
43
     */
44
    private $properties;
45
46
    /**
47
     * @var bool
48
     */
49
    private $skipSerialize = false;
50
51
    /**
52
     * @var bool
53
     */
54
    private $skipDeserialize = false;
55
56
    /**
57
     * Constructor
58
     *
59
     * @param string $name
60
     * @param AnnotationCollection $annotations
61
     * @param PropertyCollection $properties
62
     */
63 9
    public function __construct(string $name, AnnotationCollection $annotations, PropertyCollection $properties)
64
    {
65 9
        $this->name = $name;
66 9
        $this->annotations = $annotations;
67 9
        $this->properties = $properties;
68 9
    }
69
70
    /**
71
     * Get the class name as a string
72
     *
73
     * @return string
74
     */
75 1
    public function getName(): string
76
    {
77 1
        return $this->name;
78
    }
79
80
    /**
81
     * Get all class annotations
82
     *
83
     * @return AnnotationCollection
84
     */
85 4
    public function getAnnotations(): AnnotationCollection
86
    {
87 4
        return $this->annotations;
88
    }
89
90
    /**
91
     * Get a specific annotation by class name, returns null if the annotation
92
     * doesn't exist.
93
     *
94
     * @param string $annotationClass
95
     * @return null|AbstractAnnotation
96
     */
97 5
    public function getAnnotation(string $annotationClass): ?AbstractAnnotation
98
    {
99 5
        return $this->annotations->get($annotationClass);
100
    }
101
102
    /**
103
     * Get the [@see PropertyMetadataCollection] for class
104
     *
105
     * @return PropertyMetadataCollection
106
     */
107 1
    public function getPropertyMetadataCollection(): PropertyMetadataCollection
108
    {
109 1
        return $this->properties;
110
    }
111
112
    /**
113
     * Get the [@see PropertyCollection] for class
114
     *
115
     * @return PropertyCollection
116
     */
117 3
    public function getPropertyCollection(): PropertyCollection
118
    {
119 3
        return $this->properties;
120
    }
121
122
    /**
123
     * Returns an array of [@see PropertyMetadata] objects
124
     *
125
     * @return PropertyMetadata[]
126
     */
127 1
    public function getPropertyMetadata(): array
128
    {
129 1
        return $this->properties->toArray();
130
    }
131
132
    /**
133
     * Get [@see PropertyMetadata] by property name
134
     *
135
     * @param string $propertyName
136
     * @return PropertyMetadata|null
137
     */
138 2
    public function getProperty(string $propertyName): ?PropertyMetadata
139
    {
140 2
        return $this->properties->getByName($propertyName);
141
    }
142
143
    /**
144
     * If the class should be skipped during serialization
145
     *
146
     * @return bool
147
     */
148 3
    public function skipSerialize(): bool
149
    {
150 3
        return $this->skipSerialize;
151
    }
152
153
    /**
154
     * Set if we should skip serialization
155
     *
156
     * @param bool $skipSerialize
157
     */
158 3
    public function setSkipSerialize(bool $skipSerialize): void
159
    {
160 3
        $this->skipSerialize = $skipSerialize;
161 3
    }
162
163
    /**
164
     * If the class should be skipped during deserialization
165
     *
166
     * @return bool
167
     */
168 3
    public function skipDeserialize(): bool
169
    {
170 3
        return $this->skipDeserialize;
171
    }
172
173
    /**
174
     * Set if we should skip deserialization
175
     *
176
     * @param bool $skipDeserialize
177
     */
178 3
    public function setSkipDeserialize(bool $skipDeserialize): void
179
    {
180 3
        $this->skipDeserialize = $skipDeserialize;
181 3
    }
182
}
183