Completed
Push — master ( bc20b4...b7ce52 )
by Nate
03:15
created

Accessor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 51
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 9 3
A getter() 0 4 1
A setter() 0 4 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\Annotation;
8
9
use RuntimeException;
10
use Tebru\AnnotationReader\AbstractAnnotation;
11
12
/**
13
 * Class Accessor
14
 *
15
 * Use this annotation to explicitly define a getter/setter method mapping
16
 *
17
 * @author Nate Brunette <[email protected]>
18
 *
19
 * @Annotation
20
 * @Target({"PROPERTY"})
21
 */
22
class Accessor extends AbstractAnnotation
23
{
24
    /**
25
     * Method name representing getter
26
     *
27
     * @var string
28
     */
29
    private $get;
30
31
    /**
32
     * Method name representing setter
33
     *
34
     * @var string
35
     */
36
    private $set;
37
38
    /**
39
     * Constructor
40
     *
41
     * @throws \RuntimeException
42
     */
43 4
    protected function init(): void
44
    {
45 4
        $this->get = $this->data['get'] ?? null;
46 4
        $this->set = $this->data['set'] ?? null;
47
48 4
        if (null === $this->get && null === $this->set) {
49 1
            throw new RuntimeException('@Accessor annotation must specify either get or set key');
50
        }
51 3
    }
52
53
    /**
54
     * A method name representing the getter
55
     *
56
     * @return string
57
     */
58 2
    public function getter(): ?string
59
    {
60 2
        return $this->get;
61
    }
62
63
    /**
64
     * A method name representing the setter
65
     *
66
     * @return string
67
     */
68 2
    public function setter(): ?string
69
    {
70 2
        return $this->set;
71
    }
72
}
73