Failed Conditions
Pull Request — feature/init (#3)
by Yo
01:46
created

ErrorDoc::getTitle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Yoanm\JsonRpcServerDoc\Model;
3
4
use Yoanm\JsonRpcServerDoc\Model\Type\TypeDoc;
5
6
/**
7
 * Class ErrorDoc
8
 */
9
class ErrorDoc
10
{
11
    /** @var string */
12
    private $title;
13
    /** @var string */
14
    private $identifier;
15
    /** @var int */
16
    private $code;
17
    /** @var string|null */
18
    private $message;
19
    /** @var null|TypeDoc */
20
    private $dataDoc = null;
21
22
    /**
23
     * @param string       $title
24
     * @param int          $code
25
     * @param string|null  $message
26
     * @param TypeDoc|null $dataDoc
27
     * @param string|null  $identifier
28
     */
29
    public function __construct(
30
        string $title,
31
        int $code,
32
        string $message = null,
33
        TypeDoc $dataDoc = null,
34
        string $identifier = null
35
    ) {
36
        $this->title = $title;
37
        $this->code = $code;
38
        $this->message = $message;
39
        $this->dataDoc = $dataDoc;
40
        $this->setIdentifier($identifier ?? $title.((string)$code));
41
    }
42
43
    /**
44
     * @param string $identifier
45
     *
46
     * @return ErrorDoc
47
     */
48
    public function setIdentifier(string $identifier) : ErrorDoc
49
    {
50
        // Sanitize Identifier => remove space and slashes
51
        $this->identifier = strtr(
52
            ucwords(strtr(
53
                $identifier,
54
                ['_' => ' ', '/' => ' ', '.' => '_ ', '\\' => '_ ']
55
            )),
56
            [' ' => '']
57
        );
58
59
        return $this;
60
    }
61
62
    /**
63
     * @param TypeDoc $dataDoc
64
     *
65
     * @return ErrorDoc
66
     */
67
    public function setDataDoc(TypeDoc $dataDoc) : ErrorDoc
68
    {
69
        $this->dataDoc = $dataDoc;
70
71
        return $this;
72
    }
73
74
    /**
75
     * @return string
76
     */
77
    public function getTitle() : string
78
    {
79
        return $this->title;
80
    }
81
82
    /**
83
     * @return int
84
     */
85
    public function getCode() : int
86
    {
87
        return $this->code;
88
    }
89
90
    /**
91
     * @return null|string
92
     */
93
    public function getMessage()
94
    {
95
        return $this->message;
96
    }
97
98
    /**
99
     * @return TypeDoc|null
100
     */
101
    public function getDataDoc()
102
    {
103
        return $this->dataDoc;
104
    }
105
106
    /**
107
     * @return string
108
     */
109
    public function getIdentifier() : string
110
    {
111
        return $this->identifier;
112
    }
113
}
114