Skip to content

Commit f257157

Browse files
committed
CS fixes per phpcs
- long-form -> short-form array notation
1 parent 8840ce9 commit f257157

File tree

8 files changed

+71
-71
lines changed

8 files changed

+71
-71
lines changed

src/ApiProblem.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ApiProblem
1616
*
1717
* @var array
1818
*/
19-
protected $additionalDetails = array();
19+
protected $additionalDetails = [];
2020

2121
/**
2222
* URL describing the problem type; defaults to HTTP status codes
@@ -51,19 +51,19 @@ class ApiProblem
5151
*
5252
* @var array
5353
*/
54-
protected $normalizedProperties = array(
54+
protected $normalizedProperties = [
5555
'type' => 'type',
5656
'status' => 'status',
5757
'title' => 'title',
5858
'detail' => 'detail',
59-
);
59+
];
6060

6161
/**
6262
* Status titles for common problems
6363
*
6464
* @var array
6565
*/
66-
protected $problemStatusTitles = array(
66+
protected $problemStatusTitles = [
6767
// CLIENT ERROR
6868
400 => 'Bad Request',
6969
401 => 'Unauthorized',
@@ -103,7 +103,7 @@ class ApiProblem
103103
507 => 'Insufficient Storage',
104104
508 => 'Loop Detected',
105105
511 => 'Network Authentication Required',
106-
);
106+
];
107107

108108
/**
109109
* Title of the error.
@@ -126,7 +126,7 @@ class ApiProblem
126126
* @param string $title
127127
* @param array $additional
128128
*/
129-
public function __construct($status, $detail, $type = null, $title = null, array $additional = array())
129+
public function __construct($status, $detail, $type = null, $title = null, array $additional = [])
130130
{
131131
if ($detail instanceof Exception\ProblemExceptionInterface) {
132132
if (null === $type) {
@@ -195,12 +195,12 @@ public function __get($name)
195195
*/
196196
public function toArray()
197197
{
198-
$problem = array(
198+
$problem = [
199199
'type' => $this->type,
200200
'title' => $this->getTitle(),
201201
'status' => $this->getStatus(),
202202
'detail' => $this->getDetail(),
203-
);
203+
];
204204
// Required fields should always overwrite additional fields
205205
return array_merge($this->additionalDetails, $problem);
206206
}
@@ -305,14 +305,14 @@ protected function createDetailFromException()
305305
$message = trim($e->getMessage());
306306
$this->additionalDetails['trace'] = $e->getTrace();
307307

308-
$previous = array();
308+
$previous = [];
309309
$e = $e->getPrevious();
310310
while ($e) {
311-
$previous[] = array(
311+
$previous[] = [
312312
'code' => (int) $e->getCode(),
313313
'message' => trim($e->getMessage()),
314314
'trace' => $e->getTrace(),
315-
);
315+
];
316316
$e = $e->getPrevious();
317317
}
318318
if (count($previous)) {

src/Exception/DomainException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class DomainException extends \DomainException implements
1818
/**
1919
* @var array
2020
*/
21-
protected $details = array();
21+
protected $details = [];
2222

2323
/**
2424
* @var string

src/Factory/ApiProblemListenerFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ApiProblemListenerFactory implements FactoryInterface
1919
public function createService(ServiceLocatorInterface $serviceLocator)
2020
{
2121
$filters = null;
22-
$config = array();
22+
$config = [];
2323

2424
if ($serviceLocator->has('Config')) {
2525
$config = $serviceLocator->get('Config');

src/Listener/ApiProblemListener.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ class ApiProblemListener extends AbstractListenerAggregate
3232
*
3333
* @var array
3434
*/
35-
protected $acceptFilters = array(
35+
protected $acceptFilters = [
3636
'application/json',
3737
'application/*+json',
38-
);
38+
];
3939

4040
/**
4141
* Constructor
@@ -48,7 +48,7 @@ public function __construct($filters = null)
4848
{
4949
if (!empty($filters)) {
5050
if (is_string($filters)) {
51-
$this->acceptFilters = array($filters);
51+
$this->acceptFilters = [$filters];
5252
}
5353

5454
if (is_array($filters)) {
@@ -62,14 +62,14 @@ public function __construct($filters = null)
6262
*/
6363
public function attach(EventManagerInterface $events)
6464
{
65-
$this->listeners[] = $events->attach(MvcEvent::EVENT_RENDER, array($this, 'onRender'), 1000);
66-
$this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, array($this, 'onDispatchError'), 100);
65+
$this->listeners[] = $events->attach(MvcEvent::EVENT_RENDER, [$this, 'onRender'], 1000);
66+
$this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, [$this, 'onDispatchError'], 100);
6767

6868
$sharedEvents = $events->getSharedManager();
6969
$sharedEvents->attach(
7070
'Zend\Stdlib\DispatchableInterface',
7171
MvcEvent::EVENT_DISPATCH,
72-
array($this, 'onDispatch'),
72+
[$this, 'onDispatch'],
7373
100
7474
);
7575
}

src/Listener/RenderErrorListener.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class RenderErrorListener extends AbstractListenerAggregate
2828
*/
2929
public function attach(EventManagerInterface $events)
3030
{
31-
$this->listeners[] = $events->attach(MvcEvent::EVENT_RENDER_ERROR, array($this, 'onRenderError'), 100);
31+
$this->listeners[] = $events->attach(MvcEvent::EVENT_RENDER_ERROR, [$this, 'onRenderError'], 100);
3232
}
3333

3434
/**
@@ -72,19 +72,19 @@ public function onRenderError(MvcEvent $e)
7272
}
7373
$title = 'Unexpected error';
7474
$detail = $exception->getMessage();
75-
$details = array(
75+
$details = [
7676
'code' => $exception->getCode(),
7777
'message' => $exception->getMessage(),
7878
'trace' => $exception->getTraceAsString(),
79-
);
79+
];
8080
}
8181

82-
$payload = array(
82+
$payload = [
8383
'status' => $status,
8484
'title' => $title,
8585
'describedBy' => $describedBy,
8686
'detail' => $detail,
87-
);
87+
];
8888
if ($details && $this->displayExceptions) {
8989
$payload['details'] = $details;
9090
}

test/ApiProblemTest.php

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ class ApiProblemTest extends TestCase
1515
{
1616
public function statusCodes()
1717
{
18-
return array(
19-
'200' => array(200),
20-
'201' => array(201),
21-
'300' => array(300),
22-
'301' => array(301),
23-
'302' => array(302),
24-
'400' => array(400),
25-
'401' => array(401),
26-
'404' => array(404),
27-
'500' => array(500),
28-
);
18+
return [
19+
'200' => [200],
20+
'201' => [201],
21+
'300' => [300],
22+
'301' => [301],
23+
'302' => [302],
24+
'400' => [400],
25+
'401' => [401],
26+
'404' => [404],
27+
'500' => [500],
28+
];
2929
}
3030

3131
/**
@@ -86,13 +86,13 @@ public function testExceptionsCanTriggerInclusionOfNestedExceptions()
8686
$payload = $apiProblem->toArray();
8787
$this->assertArrayHasKey('exception_stack', $payload);
8888
$this->assertInternalType('array', $payload['exception_stack']);
89-
$expected = array(
90-
array(
89+
$expected = [
90+
[
9191
'code' => $exceptionChild->getCode(),
9292
'message' => $exceptionChild->getMessage(),
9393
'trace' => $exceptionChild->getTrace(),
94-
),
95-
);
94+
],
95+
];
9696
$this->assertEquals($expected, $payload['exception_stack']);
9797
}
9898

@@ -106,12 +106,12 @@ public function testTypeUrlIsUsedVerbatim()
106106

107107
public function knownStatusCodes()
108108
{
109-
return array(
110-
'404' => array(404),
111-
'409' => array(409),
112-
'422' => array(422),
113-
'500' => array(500),
114-
);
109+
return [
110+
'404' => [404],
111+
'409' => [409],
112+
'422' => [422],
113+
'500' => [500],
114+
];
115115
}
116116

117117
/**
@@ -153,7 +153,7 @@ public function testCanPassArbitraryDetailsToConstructor()
153153
'Invalid input',
154154
'http://example.com/api/problem/400',
155155
'Invalid entity',
156-
array('foo' => 'bar')
156+
['foo' => 'bar']
157157
);
158158
$this->assertEquals('bar', $problem->foo);
159159
}
@@ -165,7 +165,7 @@ public function testArraySerializationIncludesArbitraryDetails()
165165
'Invalid input',
166166
'http://example.com/api/problem/400',
167167
'Invalid entity',
168-
array('foo' => 'bar')
168+
['foo' => 'bar']
169169
);
170170
$array = $problem->toArray();
171171
$this->assertArrayHasKey('foo', $array);
@@ -179,7 +179,7 @@ public function testArbitraryDetailsShouldNotOverwriteRequiredFieldsInArraySeria
179179
'Invalid input',
180180
'http://example.com/api/problem/400',
181181
'Invalid entity',
182-
array('title' => 'SHOULD NOT GET THIS')
182+
['title' => 'SHOULD NOT GET THIS']
183183
);
184184
$array = $problem->toArray();
185185
$this->assertArrayHasKey('title', $array);
@@ -209,7 +209,7 @@ public function testUsesTypeFromExceptionWhenProvided()
209209
public function testUsesAdditionalDetailsFromExceptionWhenProvided()
210210
{
211211
$exception = new Exception\DomainException('exception message', 401);
212-
$exception->setAdditionalDetails(array('foo' => 'bar'));
212+
$exception->setAdditionalDetails(['foo' => 'bar']);
213213
$apiProblem = new ApiProblem('401', $exception);
214214
$payload = $apiProblem->toArray();
215215
$this->assertArrayHasKey('foo', $payload);
@@ -218,13 +218,13 @@ public function testUsesAdditionalDetailsFromExceptionWhenProvided()
218218

219219
public function invalidStatusCodes()
220220
{
221-
return array(
222-
'-1' => array(-1),
223-
'0' => array(0),
224-
'7' => array(7), // reported
225-
'14' => array(14), // observed
226-
'600' => array(600),
227-
);
221+
return [
222+
'-1' => [-1],
223+
'0' => [0],
224+
'7' => [7], // reported
225+
'14' => [14], // observed
226+
'600' => [600],
227+
];
228228
}
229229

230230
/**

test/View/ApiProblemRendererTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ public function testRendersApiProblemCorrectly()
2727
$model = new ApiProblemModel();
2828
$model->setApiProblem($apiProblem);
2929
$test = $this->renderer->render($model);
30-
$expected = array(
30+
$expected = [
3131
'status' => 401,
3232
'type' => 'http://status.dev/errors.md',
3333
'title' => 'Unauthorized',
3434
'detail' => 'login error',
35-
);
35+
];
3636
$this->assertEquals($expected, json_decode($test, true));
3737
}
3838

test/View/ApiProblemStrategyTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ public function setUp()
3333

3434
public function invalidViewModels()
3535
{
36-
return array(
37-
'null' => array(null),
38-
'generic' => array(new ViewModel()),
39-
'json' => array(new JsonModel()),
40-
);
36+
return [
37+
'null' => [null],
38+
'generic' => [new ViewModel()],
39+
'json' => [new JsonModel()],
40+
];
4141
}
4242

4343
/**
@@ -61,7 +61,7 @@ public function testSelectRendererReturnsRendererIfModelIsAnApiProblemModel()
6161
public function testInjectResponseDoesNotSetContentTypeHeaderIfResultIsNotString()
6262
{
6363
$this->event->setRenderer($this->renderer);
64-
$this->event->setResult(array('foo'));
64+
$this->event->setResult(['foo']);
6565
$this->strategy->injectResponse($this->event);
6666
$headers = $this->response->getHeaders();
6767
$this->assertFalse($headers->has('Content-Type'));
@@ -83,13 +83,13 @@ public function testInjectResponseSetsContentTypeHeaderToApiProblemForApiProblem
8383

8484
public function invalidStatusCodes()
8585
{
86-
return array(
87-
array(0),
88-
array(1),
89-
array(99),
90-
array(600),
91-
array(10081),
92-
);
86+
return [
87+
[0],
88+
[1],
89+
[99],
90+
[600],
91+
[10081],
92+
];
9393
}
9494

9595
/**

0 commit comments

Comments
 (0)