Test Failed
Push — master ( df5a90...e63dff )
by Jean-Christophe
06:33
created

RestError::getSource()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Ubiquity\controllers\rest;
4
5
class RestError {
6
	private $status;
7
	private $code;
8
	private $source;
9
	private $title;
10
	private $detail;
11
12
	public function __construct($code, $title, $detail = null, $source = null, $status = null) {
13
		$this->code = $code;
14
		$this->title = $title;
15
		$this->detail = $detail;
16
		$this->source = $source;
17
		$this->status = $status;
18
	}
19
20
	/**
21
	 *
22
	 * @return string
23
	 */
24
	public function getStatus() {
25
		return $this->status;
26
	}
27
28
	/**
29
	 *
30
	 * @return mixed
31
	 */
32
	public function getCode() {
33
		return $this->code;
34
	}
35
36
	/**
37
	 *
38
	 * @return string
39
	 */
40
	public function getSource() {
41
		return $this->source;
42
	}
43
44
	/**
45
	 *
46
	 * @return mixed
47
	 */
48
	public function getTitle() {
49
		return $this->title;
50
	}
51
52
	/**
53
	 *
54
	 * @return string
55
	 */
56
	public function getDetail() {
57
		return $this->detail;
58
	}
59
60
	/**
61
	 *
62
	 * @param string $status
63
	 */
64
	public function setStatus($status) {
65
		$this->status = $status;
66
	}
67
68
	/**
69
	 *
70
	 * @param mixed $code
71
	 */
72
	public function setCode($code) {
73
		$this->code = $code;
74
	}
75
76
	/**
77
	 *
78
	 * @param string $source
79
	 */
80
	public function setSource($source) {
81
		$this->source = $source;
82
	}
83
84
	/**
85
	 *
86
	 * @param mixed $title
87
	 */
88
	public function setTitle($title) {
89
		$this->title = $title;
90
	}
91
92
	/**
93
	 *
94
	 * @param string $detail
95
	 */
96
	public function setDetail($detail) {
97
		$this->detail = $detail;
98
	}
99
100
	public function asArray() {
101
		$r = [ ];
102
		if (isset ( $this->code )) {
103
			$r ['code'] = $this->code;
104
		}
105
		if (isset ( $this->status )) {
106
			$r ['status'] = $this->status;
107
		}
108
		if (isset ( $this->source )) {
109
			$r ['source'] = [ 'pointer' => $this->source ];
110
		}
111
		if (isset ( $this->title )) {
112
			$r ['title'] = $this->title;
113
		}
114
		if (isset ( $this->detail )) {
115
			$r ['detail'] = $this->detail;
116
		}
117
		return $r;
118
	}
119
	
120
	public static function notFound($keyValues,$source=null){
121
		return new RestError(404, "No result found","No result found for primary key(s): ".$keyValues,$source,404);
122
	}
123
}
124
125