Accessor   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 49
ccs 10
cts 10
cp 1
rs 10
wmc 5

3 Methods

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