11<?php
2+
23/**
34 * @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
45 * @copyright Copyright (c) 2014 Zend Technologies USA Inc. (http://www.zend.com)
78namespace ZF \ApiProblem ;
89
910/**
10- * Object describing an API-Problem payload
11+ * Object describing an API-Problem payload.
1112 */
1213class ApiProblem
1314{
1415 /**
15- * Additional details to include in report
16+ * Additional details to include in report.
1617 *
1718 * @var array
1819 */
1920 protected $ additionalDetails = [];
2021
2122 /**
22- * URL describing the problem type; defaults to HTTP status codes
23+ * URL describing the problem type; defaults to HTTP status codes.
24+ *
2325 * @var string
2426 */
2527 protected $ type = 'http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html ' ;
@@ -47,19 +49,19 @@ class ApiProblem
4749 protected $ status ;
4850
4951 /**
50- * Normalized property names for overloading
52+ * Normalized property names for overloading.
5153 *
5254 * @var array
5355 */
5456 protected $ normalizedProperties = [
55- 'type ' => 'type ' ,
57+ 'type ' => 'type ' ,
5658 'status ' => 'status ' ,
57- 'title ' => 'title ' ,
59+ 'title ' => 'title ' ,
5860 'detail ' => 'detail ' ,
5961 ];
6062
6163 /**
62- * Status titles for common problems
64+ * Status titles for common problems.
6365 *
6466 * @var array
6567 */
@@ -113,7 +115,7 @@ class ApiProblem
113115 protected $ title ;
114116
115117 /**
116- * Constructor
118+ * Constructor.
117119 *
118120 * Create an instance using the provided information. If nothing is
119121 * provided for the type field, the class default will be used;
@@ -141,7 +143,7 @@ public function __construct($status, $detail, $type = null, $title = null, array
141143 }
142144
143145 // Ensure a valid HTTP status
144- if (! is_numeric ($ status )
146+ if (!is_numeric ($ status )
145147 || ($ status < 100 )
146148 || ($ status > 599 )
147149 ) {
@@ -150,7 +152,7 @@ public function __construct($status, $detail, $type = null, $title = null, array
150152
151153 $ this ->status = $ status ;
152154 $ this ->detail = $ detail ;
153- $ this ->title = $ title ;
155+ $ this ->title = $ title ;
154156
155157 if (null !== $ type ) {
156158 $ this ->type = $ type ;
@@ -160,17 +162,20 @@ public function __construct($status, $detail, $type = null, $title = null, array
160162 }
161163
162164 /**
163- * Retrieve properties
165+ * Retrieve properties.
166+ *
167+ * @param string $name
164168 *
165- * @param string $name
166169 * @return mixed
170+ *
167171 * @throws Exception\InvalidArgumentException
168172 */
169173 public function __get ($ name )
170174 {
171175 $ normalized = strtolower ($ name );
172176 if (in_array ($ normalized , array_keys ($ this ->normalizedProperties ))) {
173177 $ prop = $ this ->normalizedProperties [$ normalized ];
178+
174179 return $ this ->{$ prop };
175180 }
176181
@@ -189,15 +194,15 @@ public function __get($name)
189194 }
190195
191196 /**
192- * Cast to an array
197+ * Cast to an array.
193198 *
194199 * @return array
195200 */
196201 public function toArray ()
197202 {
198203 $ problem = [
199- 'type ' => $ this ->type ,
200- 'title ' => $ this ->getTitle (),
204+ 'type ' => $ this ->type ,
205+ 'title ' => $ this ->getTitle (),
201206 'status ' => $ this ->getStatus (),
202207 'detail ' => $ this ->getDetail (),
203208 ];
@@ -209,17 +214,19 @@ public function toArray()
209214 * Set the flag indicating whether an exception detail should include a
210215 * stack trace and previous exception information.
211216 *
212- * @param bool $flag
217+ * @param bool $flag
218+ *
213219 * @return ApiProblem
214220 */
215221 public function setDetailIncludesStackTrace ($ flag )
216222 {
217223 $ this ->detailIncludesStackTrace = (bool ) $ flag ;
224+
218225 return $ this ;
219226 }
220227
221228 /**
222- * Retrieve the API-Problem detail
229+ * Retrieve the API-Problem detail.
223230 *
224231 * If an exception was provided, creates the detail message from it;
225232 * otherwise, detail as provided is used.
@@ -236,7 +243,7 @@ protected function getDetail()
236243 }
237244
238245 /**
239- * Retrieve the API-Problem HTTP status code
246+ * Retrieve the API-Problem HTTP status code.
240247 *
241248 * If an exception was provided, creates the status code from it;
242249 * otherwise, code as provided is used.
@@ -253,7 +260,7 @@ protected function getStatus()
253260 }
254261
255262 /**
256- * Retrieve the title
263+ * Retrieve the title.
257264 *
258265 * If the default $type is used, and the $status is found in
259266 * $problemStatusTitles, then use the matching title.
@@ -309,9 +316,9 @@ protected function createDetailFromException()
309316 $ e = $ e ->getPrevious ();
310317 while ($ e ) {
311318 $ previous [] = [
312- 'code ' => (int ) $ e ->getCode (),
319+ 'code ' => (int ) $ e ->getCode (),
313320 'message ' => trim ($ e ->getMessage ()),
314- 'trace ' => $ e ->getTrace (),
321+ 'trace ' => $ e ->getTrace (),
315322 ];
316323 $ e = $ e ->getPrevious ();
317324 }
@@ -329,7 +336,7 @@ protected function createDetailFromException()
329336 */
330337 protected function createStatusFromException ()
331338 {
332- $ e = $ this ->detail ;
339+ $ e = $ this ->detail ;
333340 $ status = $ e ->getCode ();
334341
335342 if (!empty ($ status )) {
0 commit comments