11<?php
22
3- /**
4- * @see https://github.com/laminas-api-tools/api-tools-api-problem for the canonical source repository
5- * @copyright https://github.com/laminas-api-tools/api-tools-api-problem/blob/master/COPYRIGHT.md
6- * @license https://github.com/laminas-api-tools/api-tools-api-problem/blob/master/LICENSE.md New BSD License
7- */
8-
93namespace Laminas \ApiTools \ApiProblem ;
104
115use Exception ;
126use Laminas \ApiTools \ApiProblem \Exception \InvalidArgumentException ;
137use Laminas \ApiTools \ApiProblem \Exception \ProblemExceptionInterface ;
148use Throwable ;
159
10+ use function array_key_exists ;
11+ use function array_keys ;
12+ use function array_merge ;
13+ use function count ;
14+ use function get_class ;
15+ use function in_array ;
16+ use function is_numeric ;
17+ use function sprintf ;
18+ use function strtolower ;
19+ use function trim ;
20+
1621/**
1722 * Object describing an API-Problem payload.
1823 */
@@ -21,7 +26,7 @@ class ApiProblem
2126 /**
2227 * Content type for api problem response
2328 */
24- const CONTENT_TYPE = 'application/problem+json ' ;
29+ public const CONTENT_TYPE = 'application/problem+json ' ;
2530
2631 /**
2732 * Additional details to include in report.
@@ -65,9 +70,9 @@ class ApiProblem
6570 * @var array
6671 */
6772 protected $ normalizedProperties = [
68- 'type ' => 'type ' ,
73+ 'type ' => 'type ' ,
6974 'status ' => 'status ' ,
70- 'title ' => 'title ' ,
75+ 'title ' => 'title ' ,
7176 'detail ' => 'detail ' ,
7277 ];
7378
@@ -126,8 +131,6 @@ class ApiProblem
126131 protected $ title ;
127132
128133 /**
129- * Constructor.
130- *
131134 * Create an instance using the provided information. If nothing is
132135 * provided for the type field, the class default will be used;
133136 * if the status matches any known, the title field will be selected
@@ -154,7 +157,8 @@ public function __construct($status, $detail, $type = null, $title = null, array
154157 }
155158
156159 // Ensure a valid HTTP status
157- if (! is_numeric ($ status )
160+ if (
161+ ! is_numeric ($ status )
158162 || ($ status < 100 )
159163 || ($ status > 599 )
160164 ) {
@@ -163,7 +167,7 @@ public function __construct($status, $detail, $type = null, $title = null, array
163167
164168 $ this ->status = $ status ;
165169 $ this ->detail = $ detail ;
166- $ this ->title = $ title ;
170+ $ this ->title = $ title ;
167171
168172 if (null !== $ type ) {
169173 $ this ->type = $ type ;
@@ -210,8 +214,8 @@ public function __get($name)
210214 public function toArray ()
211215 {
212216 $ problem = [
213- 'type ' => $ this ->type ,
214- 'title ' => $ this ->getTitle (),
217+ 'type ' => $ this ->type ,
218+ 'title ' => $ this ->getTitle (),
215219 'status ' => $ this ->getStatus (),
216220 'detail ' => $ this ->getDetail (),
217221 ];
@@ -286,8 +290,9 @@ protected function getTitle()
286290 return $ this ->title ;
287291 }
288292
289- if (null === $ this ->title
290- && $ this ->type == 'http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html '
293+ if (
294+ null === $ this ->title
295+ && $ this ->type === 'http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html '
291296 && array_key_exists ($ this ->getStatus (), $ this ->problemStatusTitles )
292297 ) {
293298 return $ this ->problemStatusTitles [$ this ->status ];
@@ -318,18 +323,18 @@ protected function createDetailFromException()
318323 return $ e ->getMessage ();
319324 }
320325
321- $ message = trim ($ e ->getMessage ());
326+ $ message = trim ($ e ->getMessage ());
322327 $ this ->additionalDetails ['trace ' ] = $ e ->getTrace ();
323328
324329 $ previous = [];
325- $ e = $ e ->getPrevious ();
330+ $ e = $ e ->getPrevious ();
326331 while ($ e ) {
327332 $ previous [] = [
328- 'code ' => (int ) $ e ->getCode (),
333+ 'code ' => (int ) $ e ->getCode (),
329334 'message ' => trim ($ e ->getMessage ()),
330- 'trace ' => $ e ->getTrace (),
335+ 'trace ' => $ e ->getTrace (),
331336 ];
332- $ e = $ e ->getPrevious ();
337+ $ e = $ e ->getPrevious ();
333338 }
334339 if (count ($ previous )) {
335340 $ this ->additionalDetails ['exception_stack ' ] = $ previous ;
@@ -346,7 +351,7 @@ protected function createDetailFromException()
346351 protected function createStatusFromException ()
347352 {
348353 /** @var Exception|Throwable $e */
349- $ e = $ this ->detail ;
354+ $ e = $ this ->detail ;
350355 $ status = $ e ->getCode ();
351356
352357 if ($ status ) {
0 commit comments