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

ErrorDoc   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 103
ccs 0
cts 48
cp 0
rs 10
c 0
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getDataDoc() 0 3 1
A setDataDoc() 0 5 1
A setIdentifier() 0 12 1
A getCode() 0 3 1
A getIdentifier() 0 3 1
A getMessage() 0 3 1
A __construct() 0 12 1
A getTitle() 0 3 1
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 int */
14
    private $code;
15
    /** @var string|null */
16
    private $message;
17
    /** @var string */
18
    private $identifier;
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
        $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()
78
    {
79
        return $this->title;
80
    }
81
82
    /**
83
     * @return int
84
     */
85
    public function getCode()
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()
110
    {
111
        return $this->identifier;
112
    }
113
}
114