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

DefaultPropertyMetadata   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 184
Duplicated Lines 9.78 %

Coupling/Cohesion

Components 3
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 12
lcom 3
cbo 2
dl 18
loc 184
ccs 31
cts 31
cp 1
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 18 18 1
A getName() 0 4 1
A getSerializedName() 0 4 1
A getType() 0 4 1
A getTypeName() 0 4 1
A getModifiers() 0 4 1
A getDeclaringClassMetadata() 0 4 1
A getDeclaringClassName() 0 4 1
A getAnnotations() 0 4 1
A getAnnotation() 0 6 2
A isVirtual() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
use Tebru\Gson\PhpType;
12
use Tebru\Gson\PropertyMetadata;
13
14
/**
15
 * Class DefaultPropertyMetadata
16
 *
17
 * Represents a property and its annotations
18
 *
19
 * @author Nate Brunette <[email protected]>
20
 */
21
final class DefaultPropertyMetadata implements PropertyMetadata
22
{
23
    /**
24
     * The property name
25
     *
26
     * @var string
27
     */
28
    private $name;
29
30
    /**
31
     * The property's serialized name
32
     *
33
     * @var string
34
     */
35
    private $serializedName;
36
37
    /**
38
     * The property type
39
     *
40
     * @var PhpType
41
     */
42
    private $type;
43
44
    /**
45
     * The property modifiers (public, private, etc)
46
     *
47
     * @var int
48
     */
49
    private $modifiers;
50
51
    /**
52
     * The property declaring class metadata
53
     *
54
     * @var ClassMetadata
55
     */
56
    private $classMetadata;
57
58
    /**
59
     * The property's annotations
60
     *
61
     * @var AnnotationSet
62
     */
63
    private $annotations;
64
65
    /**
66
     * If the property is a virtual property
67
     *
68
     * @var bool
69
     */
70
    private $virtual;
71
72
    /**
73
     * Constructor
74
     *
75
     * @param string $name
76
     * @param string $serializedName
77
     * @param PhpType $type
78
     * @param int $modifiers
79
     * @param ClassMetadata $classMetadata
80
     * @param AnnotationSet $annotations
81
     * @param bool $virtual
82
     */
83 5 View Code Duplication
    public function __construct(
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
84
        string $name,
85
        string $serializedName,
86
        PhpType $type,
87
        int $modifiers,
88
        ClassMetadata $classMetadata,
89
        AnnotationSet $annotations,
90
        bool $virtual
91
    )
92
    {
93 5
        $this->name = $name;
94 5
        $this->serializedName = $serializedName;
95 5
        $this->type = $type;
96 5
        $this->modifiers = $modifiers;
97 5
        $this->classMetadata = $classMetadata;
98 5
        $this->annotations = $annotations;
99 5
        $this->virtual = $virtual;
100 5
    }
101
102
    /**
103
     * Get the property name
104
     *
105
     * @return string
106
     */
107 1
    public function getName(): string
108
    {
109 1
        return $this->name;
110
    }
111
112
    /**
113
     * Get the property serialized name
114
     *
115
     * @return string
116
     */
117 1
    public function getSerializedName(): string
118
    {
119 1
        return $this->serializedName;
120
    }
121
122
    /**
123
     * Get the full php type object
124
     *
125
     * @return PhpType
126
     */
127 1
    public function getType(): PhpType
128
    {
129 1
        return $this->type;
130
    }
131
132
    /**
133
     * Get the property type as a string
134
     *
135
     * @return string
136
     */
137 1
    public function getTypeName(): string
138
    {
139 1
        return (string) $this->type;
140
    }
141
142
    /**
143
     * Get the property modifiers as a bitmap of [@see \ReflectionProperty] constants
144
     *
145
     * @return int
146
     */
147 1
    public function getModifiers(): int
148
    {
149 1
        return $this->modifiers;
150
    }
151
152
    /**
153
     * Get full declaring class metadata
154
     *
155
     * @return ClassMetadata
156
     */
157 1
    public function getDeclaringClassMetadata(): ClassMetadata
158
    {
159 1
        return $this->classMetadata;
160
    }
161
162
    /**
163
     * Get the declaring class name
164
     *
165
     * @return string
166
     */
167 1
    public function getDeclaringClassName(): string
168
    {
169 1
        return $this->classMetadata->getName();
170
    }
171
172
    /**
173
     * Get property annotations
174
     *
175
     * @return AnnotationSet
176
     */
177 1
    public function getAnnotations(): AnnotationSet
178
    {
179 1
        return $this->annotations;
180
    }
181
182
    /**
183
     * Get a single annotation, returns null if the annotation doesn't exist
184
     *
185
     * @param string $annotationName
186
     * @return null|object
187
     */
188 4
    public function getAnnotation(string $annotationName)
189
    {
190 4
        return $this->virtual
191 2
            ? $this->annotations->getAnnotation($annotationName, AnnotationSet::TYPE_METHOD)
192 4
            : $this->annotations->getAnnotation($annotationName, AnnotationSet::TYPE_PROPERTY);
193
    }
194
195
    /**
196
     * Returns true if the property is virtual
197
     *
198
     * @return bool
199
     */
200 1
    public function isVirtual(): bool
201
    {
202 1
        return $this->virtual;
203
    }
204
}
205