Skip to content

Commit 76781a5

Browse files
committed
qa: apply laminas-coding-standard v2 rules
Signed-off-by: Matthew Weier O'Phinney <[email protected]>
1 parent 6491ac6 commit 76781a5

28 files changed

+196
-374
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/.phpcs-cache
12
/clover.xml
23
/coveralls-upload.json
34
/phpunit.xml

config/module.config.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
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-
93
namespace Laminas\ApiTools\ApiProblem;
104

115
return [
12-
'service_manager' => [
6+
'service_manager' => [
137
'aliases' => [
148
ApiProblemListener::class => Listener\ApiProblemListener::class,
159
RenderErrorListener::class => Listener\RenderErrorListener::class,
@@ -37,13 +31,11 @@
3731
View\ApiProblemStrategy::class => Factory\ApiProblemStrategyFactory::class,
3832
],
3933
],
40-
41-
'view_manager' => [
34+
'view_manager' => [
4235
// Enable this in your application configuration in order to get full
4336
// exception stack traces in your API-Problem responses.
4437
'display_exceptions' => false,
4538
],
46-
4739
'api-tools-api-problem' => [
4840
// Accept types that should allow ApiProblem responses
4941
// 'accept_filters' => $stringOrArray,

src/ApiProblem.php

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
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-
93
namespace Laminas\ApiTools\ApiProblem;
104

115
use Exception;
126
use Laminas\ApiTools\ApiProblem\Exception\InvalidArgumentException;
137
use Laminas\ApiTools\ApiProblem\Exception\ProblemExceptionInterface;
148
use 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) {

src/ApiProblemResponse.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
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-
93
namespace Laminas\ApiTools\ApiProblem;
104

5+
use Laminas\Http\Headers;
116
use Laminas\Http\Response;
127

8+
use function json_encode;
9+
10+
use const JSON_PARTIAL_OUTPUT_ON_ERROR;
11+
use const JSON_UNESCAPED_SLASHES;
12+
1313
/**
1414
* Represents an ApiProblem response payload.
1515
*/
1616
class ApiProblemResponse extends Response
1717
{
18-
/**
19-
* @var ApiProblem
20-
*/
18+
/** @var ApiProblem */
2119
protected $apiProblem;
2220

2321
/**
@@ -27,9 +25,6 @@ class ApiProblemResponse extends Response
2725
*/
2826
protected $jsonFlags;
2927

30-
/**
31-
* @param ApiProblem $apiProblem
32-
*/
3328
public function __construct(ApiProblem $apiProblem)
3429
{
3530
$this->apiProblem = $apiProblem;
@@ -65,7 +60,7 @@ public function getContent()
6560
* Proxies to parent class, but then checks if we have an content-type
6661
* header; if not, sets it, with a value of "application/problem+json".
6762
*
68-
* @return \Laminas\Http\Headers
63+
* @return Headers
6964
*/
7065
public function getHeaders()
7166
{

src/Exception/DomainException.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,18 @@
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-
93
namespace Laminas\ApiTools\ApiProblem\Exception;
104

115
class DomainException extends \DomainException implements
126
ExceptionInterface,
137
ProblemExceptionInterface
148
{
15-
/**
16-
* @var string
17-
*/
9+
/** @var string */
1810
protected $type;
1911

20-
/**
21-
* @var array
22-
*/
12+
/** @var array */
2313
protected $details = [];
2414

25-
/**
26-
* @var string
27-
*/
15+
/** @var string */
2816
protected $title;
2917

3018
/**

src/Exception/ExceptionInterface.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
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-
93
namespace Laminas\ApiTools\ApiProblem\Exception;
104

115
/**

src/Exception/InvalidArgumentException.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
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-
93
namespace Laminas\ApiTools\ApiProblem\Exception;
104

115
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface

src/Exception/ProblemExceptionInterface.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
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-
93
namespace Laminas\ApiTools\ApiProblem\Exception;
104

5+
use Traversable;
6+
117
/**
128
* Interface for exceptions that can provide additional API Problem details.
139
*/
1410
interface ProblemExceptionInterface
1511
{
1612
/**
17-
* @return null|array|\Traversable
13+
* @return null|array|Traversable
1814
*/
1915
public function getAdditionalDetails();
2016

src/Factory/ApiProblemListenerFactory.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
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-
93
namespace Laminas\ApiTools\ApiProblem\Factory;
104

115
use Interop\Container\ContainerInterface;
@@ -14,13 +8,12 @@
148
class ApiProblemListenerFactory
159
{
1610
/**
17-
* @param ContainerInterface $container
1811
* @return ApiProblemListener
1912
*/
2013
public function __invoke(ContainerInterface $container)
2114
{
2215
$filters = null;
23-
$config = [];
16+
$config = [];
2417

2518
if ($container->has('config')) {
2619
$config = $container->get('config');

src/Factory/ApiProblemRendererFactory.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
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-
93
namespace Laminas\ApiTools\ApiProblem\Factory;
104

115
use Interop\Container\ContainerInterface;
@@ -14,12 +8,11 @@
148
class ApiProblemRendererFactory
159
{
1610
/**
17-
* @param ContainerInterface $container
1811
* @return ApiProblemRenderer
1912
*/
2013
public function __invoke(ContainerInterface $container)
2114
{
22-
$config = $container->get('config');
15+
$config = $container->get('config');
2316
$displayExceptions = isset($config['view_manager'])
2417
&& isset($config['view_manager']['display_exceptions'])
2518
&& $config['view_manager']['display_exceptions'];

0 commit comments

Comments
 (0)