31
31
namespace OC \OCS ;
32
32
33
33
class Result {
34
- /** @var array */
35
- protected $ data ;
34
+ protected array $ data ;
36
35
37
36
/** @var null|string */
38
- protected $ message ;
37
+ protected ? string $ message ;
39
38
40
39
/** @var int */
41
- protected $ statusCode ;
40
+ protected int $ statusCode ;
42
41
43
42
/** @var integer */
44
- protected $ items ;
43
+ protected int $ items ;
45
44
46
45
/** @var integer */
47
- protected $ perPage ;
46
+ protected int $ perPage ;
48
47
49
48
/** @var array */
50
- private $ headers = [];
49
+ private array $ headers = [];
51
50
52
51
/**
53
52
* create the OCS_Result object
54
- * @param mixed $data the data to return
53
+ *
54
+ * @param mixed|null $data the data to return
55
55
* @param int $code
56
- * @param null| string $message
56
+ * @param string|null $message
57
57
* @param array $headers
58
58
*/
59
- public function __construct ($ data = null , $ code = 100 , $ message = null , $ headers = []) {
59
+ public function __construct (mixed $ data = null , int $ code = 100 , string $ message = null , array $ headers = []) {
60
60
if ($ data === null ) {
61
61
$ this ->data = [];
62
62
} elseif (!is_array ($ data )) {
@@ -71,33 +71,35 @@ public function __construct($data = null, $code = 100, $message = null, $headers
71
71
72
72
/**
73
73
* optionally set the total number of items available
74
+ *
74
75
* @param int $items
75
76
*/
76
- public function setTotalItems ($ items ) {
77
+ public function setTotalItems (int $ items ): void {
77
78
$ this ->items = $ items ;
78
79
}
79
80
80
81
/**
81
- * optionally set the the number of items per page
82
+ * optionally set the number of items per page
83
+ *
82
84
* @param int $items
83
85
*/
84
- public function setItemsPerPage ($ items ) {
86
+ public function setItemsPerPage (int $ items ): void {
85
87
$ this ->perPage = $ items ;
86
88
}
87
89
88
90
/**
89
91
* get the status code
90
92
* @return int
91
93
*/
92
- public function getStatusCode () {
94
+ public function getStatusCode (): int {
93
95
return $ this ->statusCode ;
94
96
}
95
97
96
98
/**
97
99
* get the meta data for the result
98
100
* @return array
99
101
*/
100
- public function getMeta () {
102
+ public function getMeta (): array {
101
103
$ meta = [];
102
104
$ meta ['status ' ] = $ this ->succeeded () ? 'ok ' : 'failure ' ;
103
105
$ meta ['statuscode ' ] = $ this ->statusCode ;
@@ -115,25 +117,26 @@ public function getMeta() {
115
117
* get the result data
116
118
* @return array
117
119
*/
118
- public function getData () {
120
+ public function getData (): array {
119
121
return $ this ->data ;
120
122
}
121
123
122
124
/**
123
125
* return bool Whether the method succeeded
124
126
* @return bool
125
127
*/
126
- public function succeeded () {
128
+ public function succeeded (): bool {
127
129
return ($ this ->statusCode == 100 );
128
130
}
129
131
130
132
/**
131
133
* Adds a new header to the response
134
+ *
132
135
* @param string $name The name of the HTTP header
133
136
* @param string $value The value, null will delete it
134
137
* @return $this
135
138
*/
136
- public function addHeader ($ name , $ value ) {
139
+ public function addHeader (string $ name , string $ value ): static {
137
140
$ name = trim ($ name ); // always remove leading and trailing whitespace
138
141
// to be able to reliably check for security
139
142
// headers
@@ -151,7 +154,7 @@ public function addHeader($name, $value) {
151
154
* Returns the set headers
152
155
* @return array the headers
153
156
*/
154
- public function getHeaders () {
157
+ public function getHeaders (): array {
155
158
return $ this ->headers ;
156
159
}
157
160
}
0 commit comments