| Total Complexity | 8 |
| Total Lines | 104 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 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 = null; |
||
| 19 | /** @var TypeDoc|null */ |
||
| 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 | 12 | public function __construct( |
|
| 30 | string $title, |
||
| 31 | int $code, |
||
| 32 | string $message = null, |
||
| 33 | TypeDoc $dataDoc = null, |
||
| 34 | string $identifier = null |
||
| 35 | ) { |
||
| 36 | 12 | $this->title = $title; |
|
| 37 | 12 | $this->code = $code; |
|
| 38 | 12 | $this->message = $message; |
|
| 39 | 12 | $this->dataDoc = $dataDoc; |
|
| 40 | // Use title and code as id if not provided |
||
| 41 | 12 | $this->setIdentifier($identifier ?? $title.((string)$code)); |
|
| 42 | 12 | } |
|
| 43 | |||
| 44 | /** |
||
| 45 | * @param string $identifier |
||
| 46 | * |
||
| 47 | * @return ErrorDoc |
||
| 48 | */ |
||
| 49 | 12 | public function setIdentifier(string $identifier) : ErrorDoc |
|
| 50 | { |
||
| 51 | // Sanitize Identifier => remove space and slashes |
||
| 52 | 12 | $this->identifier = strtr( |
|
| 53 | 12 | ucwords(strtr( |
|
| 54 | 12 | $identifier, |
|
| 55 | 12 | ['_' => ' ', '/' => '-', '.' => '_ ', '\\' => '_ '] |
|
| 56 | )), |
||
| 57 | 12 | [' ' => ''] |
|
| 58 | ); |
||
| 59 | |||
| 60 | 12 | return $this; |
|
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @param TypeDoc $dataDoc |
||
| 65 | * |
||
| 66 | * @return ErrorDoc |
||
| 67 | */ |
||
| 68 | 1 | public function setDataDoc(TypeDoc $dataDoc) : ErrorDoc |
|
| 69 | { |
||
| 70 | 1 | $this->dataDoc = $dataDoc; |
|
| 71 | |||
| 72 | 1 | return $this; |
|
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @return string |
||
| 77 | */ |
||
| 78 | 1 | public function getTitle() : string |
|
| 81 | } |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @return int |
||
| 85 | */ |
||
| 86 | 1 | public function getCode() : int |
|
| 87 | { |
||
| 88 | 1 | return $this->code; |
|
| 89 | } |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @return string|null |
||
| 93 | */ |
||
| 94 | 2 | public function getMessage() |
|
| 95 | { |
||
| 96 | 2 | return $this->message; |
|
| 97 | } |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @return TypeDoc|null |
||
| 101 | */ |
||
| 102 | 3 | public function getDataDoc() |
|
| 105 | } |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @return string |
||
| 109 | */ |
||
| 110 | 7 | public function getIdentifier() : string |
|
| 113 | } |
||
| 114 | } |
||
| 115 |