Completed
Branch release/1.0.0 (faa89b)
by Yo
01:45
created

MethodDoc::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Yoanm\JsonRpcServerDoc\Domain\Model;
3
4
use Yoanm\JsonRpcServerDoc\Domain\Model\Type\TypeDoc;
5
6
/**
7
 * Class MethodDoc
8
 */
9
class MethodDoc
10
{
11
    /** @var string */
12
    private $methodName;
13
    /** @var string */
14
    private $identifier;
15
    /** @var TypeDoc|null */
16
    private $paramsDoc = null;
17
    /** @var TypeDoc|null */
18
    private $resultDoc = null;
19
    /** @var string|null */
20
    private $description = null;
21
    /** @var string[] */
22
    private $tagList = [];
23
    /** @var ErrorDoc[] */
24
    private $customErrorList = [];
25
    /** @var string[] */
26
    private $globalErrorRefList = [];
27
28
    /**
29
     * @param string      $methodName
30
     * @param string|null $identifier
31
     */
32 15
    public function __construct(string $methodName, string $identifier = null)
33
    {
34 15
        $this->methodName = $methodName;
35 15
        $this->setIdentifier($identifier ?? $methodName)
36
        ;
37 15
    }
38
39
    /**
40
     * @param string $identifier
41
     *
42
     * @return MethodDoc
43
     */
44 15
    public function setIdentifier(string $identifier) : MethodDoc
45
    {
46
        // Sanitize Identifier => remove space and slashes
47 15
        $this->identifier = strtr(
48 15
            ucwords(strtr(
49 15
                $identifier,
50 15
                ['_' => ' ', '/' => '-', '.' => '_ ', '\\' => '_ ']
51
            )),
52 15
            [' ' => '']
53
        );
54
55 15
        return $this;
56
    }
57
58
    /**
59
     * @param TypeDoc $paramsDoc
60
     *
61
     * @return MethodDoc
62
     */
63 1
    public function setParamsDoc(TypeDoc $paramsDoc) : MethodDoc
64
    {
65 1
        $this->paramsDoc = $paramsDoc;
66
67 1
        return $this;
68
    }
69
70
    /**
71
     * @param TypeDoc $resultDoc
72
     *
73
     * @return MethodDoc
74
     */
75 1
    public function setResultDoc(TypeDoc $resultDoc) : MethodDoc
76
    {
77 1
        $this->resultDoc = $resultDoc;
78
79 1
        return $this;
80
    }
81
82
    /**
83
     * @param string $description
84
     *
85
     * @return MethodDoc
86
     */
87 1
    public function setDescription(string $description) : MethodDoc
88
    {
89 1
        $this->description = $description;
90
91 1
        return $this;
92
    }
93
94
    /**
95
     * @param string $tag
96
     *
97
     * @return MethodDoc
98
     */
99 1
    public function addTag(string $tag) : MethodDoc
100
    {
101 1
        $this->tagList[] = $tag;
102
103 1
        return $this;
104
    }
105
106
    /**
107
     * @param ErrorDoc $customError
108
     *
109
     * @return MethodDoc
110
     */
111 1
    public function addCustomError(ErrorDoc $customError) : MethodDoc
112
    {
113 1
        $this->customErrorList[] = $customError;
114
115 1
        return $this;
116
    }
117
118
    /**
119
     * @param string $errorIdentifier
120
     *
121
     * @return MethodDoc
122
     */
123 1
    public function addGlobalErrorRef(string $errorIdentifier) : MethodDoc
124
    {
125 1
        $this->globalErrorRefList[] = $errorIdentifier;
126
127 1
        return $this;
128
    }
129
130
    /**
131
     * @return string
132
     */
133 1
    public function getMethodName() : string
134
    {
135 1
        return $this->methodName;
136
    }
137
138
    /**
139
     * @return TypeDoc|null
140
     */
141 1
    public function getParamsDoc()
142
    {
143 1
        return $this->paramsDoc;
144
    }
145
146
    /**
147
     * @return TypeDoc|null
148
     */
149 1
    public function getResultDoc()
150
    {
151 1
        return $this->resultDoc;
152
    }
153
154
    /**
155
     * @return string
156
     */
157 8
    public function getIdentifier() : string
158
    {
159 8
        return $this->identifier;
160
    }
161
162
    /**
163
     * @return string|null
164
     */
165 1
    public function getDescription()
166
    {
167 1
        return $this->description;
168
    }
169
170
    /**
171
     * @return string[]
172
     */
173 1
    public function getTagList() : array
174
    {
175 1
        return $this->tagList;
176
    }
177
178
    /**
179
     * @return ErrorDoc[]
180
     */
181 1
    public function getCustomErrorList() : array
182
    {
183 1
        return $this->customErrorList;
184
    }
185
186
    /**
187
     * @return string[]
188
     */
189 1
    public function getGlobalErrorRefList() : array
190
    {
191 1
        return $this->globalErrorRefList;
192
    }
193
}
194