Skip to content

Commit 6e31e6e

Browse files
committed
Code cleanup with php-cs-fixer + some contrib fixer.
1 parent d155720 commit 6e31e6e

38 files changed

+184
-177
lines changed

.php-cs-fixer.php

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
<?php
22

3-
$fixers = array(
4-
'-psr0',
3+
$fixers = [
54
'-no_empty_lines_after_phpdocs',
6-
);
5+
'-psr0',
6+
'ordered_use',
7+
'php_unit_construct',
8+
'php_unit_strict',
9+
'phpdoc_order',
10+
'short_array_syntax',
11+
];
712

813
$finder = Symfony\CS\Finder\DefaultFinder::create()
914
->exclude('app/cache')
1015
->exclude('app/log')
1116
->exclude('build')
1217
->exclude('vendor')
18+
->ignoreDotFiles(false)
19+
->ignoreVCS(true)
1320
->in(__DIR__)
1421
->notName('*.phar')
1522
->notName('LICENSE')

app/autoload.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

3-
use Doctrine\Common\Annotations\AnnotationRegistry;
43
use Composer\Autoload\ClassLoader;
4+
use Doctrine\Common\Annotations\AnnotationRegistry;
55

66
/*
77
* @var ClassLoader
88
*/
99
$loader = require __DIR__.'/../vendor/autoload.php';
1010

11-
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
11+
AnnotationRegistry::registerLoader([$loader, 'loadClass']);
1212

1313
return $loader;

app/config/config.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111
$app['monolog.logfile'] = __DIR__.'/../logs/'.$app['env'].'.log';
1212

1313
// Define SQLite DB path.
14-
$app['db.options'] = array(
14+
$app['db.options'] = [
1515
'driver' => 'pdo_sqlite',
1616
'path' => __DIR__.'/../cache/'.$app['env'].'/.ht.sqlite',
17-
);
17+
];
1818

1919
// Return an instance of Doctrine ORM entity manager.
2020
$app['doctrine.orm.entity_manager'] = $app->share(function ($app) {
2121
$conn = $app['dbs']['default'];
2222
$em = $app['dbs.event_manager']['default'];
2323

24-
$driver = new AnnotationDriver(new AnnotationReader(), array(__DIR__.'/../../tests/TestBundle/Entity'));
24+
$driver = new AnnotationDriver(new AnnotationReader(), [__DIR__.'/../../tests/TestBundle/Entity']);
2525
$cache = new FilesystemCache(__DIR__.'/../cache/'.$app['env']);
2626

2727
$config = Setup::createConfiguration(false);
@@ -33,11 +33,11 @@
3333
});
3434

3535
// Return entity classes for model manager.
36-
$app['authbucket_push.model'] = array(
36+
$app['authbucket_push.model'] = [
3737
'device' => 'AuthBucket\\Push\\Tests\\TestBundle\\Entity\\Device',
3838
'message' => 'AuthBucket\\Push\\Tests\\TestBundle\\Entity\\Message',
3939
'service' => 'AuthBucket\\Push\\Tests\\TestBundle\\Entity\\Service',
40-
);
40+
];
4141

4242
// Add model managers from ORM.
4343
$app['authbucket_push.model_manager.factory'] = $app->share(function ($app) {
@@ -52,6 +52,6 @@
5252

5353
$app['debug'] = true;
5454

55-
$app['twig.path'] = array(
55+
$app['twig.path'] = [
5656
__DIR__.'/../../tests/TestBundle/Resources/views',
57-
);
57+
];

app/config/security.php

+14-14
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44
return new Symfony\Component\Security\Core\Encoder\PlaintextPasswordEncoder();
55
});
66

7-
$app['security.user_provider.admin'] = $app['security.user_provider.inmemory._proto'](array(
8-
'admin' => array('ROLE_ADMIN', 'secrete'),
9-
));
7+
$app['security.user_provider.admin'] = $app['security.user_provider.inmemory._proto']([
8+
'admin' => ['ROLE_ADMIN', 'secrete'],
9+
]);
1010

11-
$app['security.firewalls'] = array(
12-
'admin' => array(
11+
$app['security.firewalls'] = [
12+
'admin' => [
1313
'pattern' => '^/admin',
1414
'http' => true,
1515
'users' => $app['security.user_provider.admin'],
16-
),
17-
'api' => array(
16+
],
17+
'api' => [
1818
'pattern' => '^/api',
19-
'oauth2_resource' => array(
19+
'oauth2_resource' => [
2020
'resource_type' => 'debug_endpoint',
21-
'scope' => array(),
22-
'options' => array(
21+
'scope' => [],
22+
'options' => [
2323
'debug_endpoint' => 'http://oauth2-php.authbucket.com/api/oauth2/debug',
2424
'cache' => false,
25-
),
26-
),
27-
),
28-
);
25+
],
26+
],
27+
],
28+
];

src/Controller/PushController.php

+34-34
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ public function registerAction(Request $request)
6767
// Recreate record with new supplied values.
6868
$parameters = $this->createDeviceToken($deviceToken, $serviceId, $username, $scope);
6969

70-
return JsonResponse::create($parameters, 200, array(
70+
return JsonResponse::create($parameters, 200, [
7171
'Cache-Control' => 'no-store',
7272
'Pragma' => 'no-cache',
73-
));
73+
]);
7474
}
7575

7676
public function unregisterAction(Request $request)
@@ -86,10 +86,10 @@ public function unregisterAction(Request $request)
8686
// Remove all legacy record for this device_token.
8787
$parameters = $this->deleteDeviceToken($deviceToken, $serviceId, $username);
8888

89-
return JsonResponse::create($parameters, 200, array(
89+
return JsonResponse::create($parameters, 200, [
9090
'Cache-Control' => 'no-store',
9191
'Pragma' => 'no-cache',
92-
));
92+
]);
9393
}
9494

9595
public function sendAction(Request $request)
@@ -115,37 +115,37 @@ public function sendAction(Request $request)
115115

116116
// Send out message per service_id.
117117
$serviceManager = $this->modelManagerFactory->getModelManager('service');
118-
$services = $serviceManager->readModelBy(array(
118+
$services = $serviceManager->readModelBy([
119119
'clientId' => $clientId,
120-
));
120+
]);
121121
foreach ($services as $service) {
122122
$this->serviceTypeHandlerFactory
123123
->getServiceTypeHandler($service->getServiceType())
124124
->send($service, $message);
125125
}
126126

127127
// Prepare parameters for JSON response.
128-
$parameters = array(
128+
$parameters = [
129129
'message_id' => $message->getMessageId(),
130130
'client_id' => $message->getClientId(),
131131
'username' => $message->getUsername(),
132132
'scope' => implode(' ', (array) $message->getScope()),
133133
'payload' => $message->getPayload(),
134-
);
134+
];
135135

136-
return JsonResponse::create($parameters, 200, array(
136+
return JsonResponse::create($parameters, 200, [
137137
'Cache-Control' => 'no-store',
138138
'Pragma' => 'no-cache',
139-
));
139+
]);
140140
}
141141

142142
protected function checkClientId()
143143
{
144144
$token = $this->securityContext->getToken();
145145
if ($token === null || !$token instanceof AccessTokenToken) {
146-
throw new ServerErrorException(array(
146+
throw new ServerErrorException([
147147
'error_description' => 'The authorization server encountered an unexpected condition that prevented it from fulfilling the request.',
148-
));
148+
]);
149149
}
150150

151151
return $token->getClientId();
@@ -155,9 +155,9 @@ protected function checkUsername()
155155
{
156156
$token = $this->securityContext->getToken();
157157
if ($token === null || !$token instanceof AccessTokenToken) {
158-
throw new ServerErrorException(array(
158+
throw new ServerErrorException([
159159
'error_description' => 'The authorization server encountered an unexpected condition that prevented it from fulfilling the request.',
160-
));
160+
]);
161161
}
162162

163163
return $token->getUsername();
@@ -167,9 +167,9 @@ protected function checkScope()
167167
{
168168
$token = $this->securityContext->getToken();
169169
if ($token === null || !$token instanceof AccessTokenToken) {
170-
throw new ServerErrorException(array(
170+
throw new ServerErrorException([
171171
'error_description' => 'The authorization server encountered an unexpected condition that prevented it from fulfilling the request.',
172-
));
172+
]);
173173
}
174174

175175
return $token->getScope();
@@ -179,14 +179,14 @@ protected function checkDeviceToken(Request $request)
179179
{
180180
// device_token is required and in valid format.
181181
$deviceToken = $request->request->get('device_token');
182-
$errors = $this->validator->validateValue($deviceToken, array(
182+
$errors = $this->validator->validateValue($deviceToken, [
183183
new NotBlank(),
184184
new DeviceToken(),
185-
));
185+
]);
186186
if (count($errors) > 0) {
187-
throw new InvalidRequestException(array(
187+
throw new InvalidRequestException([
188188
'error_description' => 'The request includes an invalid parameter value.',
189-
));
189+
]);
190190
}
191191

192192
return $deviceToken;
@@ -196,26 +196,26 @@ protected function checkServiceId(Request $request, $clientId)
196196
{
197197
// service_id is required and in valid format.
198198
$serviceId = $request->request->get('service_id');
199-
$errors = $this->validator->validateValue($serviceId, array(
199+
$errors = $this->validator->validateValue($serviceId, [
200200
new NotBlank(),
201201
new ServiceId(),
202-
));
202+
]);
203203
if (count($errors) > 0) {
204-
throw new InvalidRequestException(array(
204+
throw new InvalidRequestException([
205205
'error_description' => 'The request includes an invalid parameter value.',
206-
));
206+
]);
207207
}
208208

209209
// Check if service_id belongs to corresponding client_id.
210210
$serviceManager = $this->modelManagerFactory->getModelManager('service');
211-
$service = $serviceManager->readModelOneBy(array(
211+
$service = $serviceManager->readModelOneBy([
212212
'clientId' => $clientId,
213213
'serviceId' => $serviceId,
214-
));
214+
]);
215215
if ($service === null) {
216-
throw new InvalidRequestException(array(
216+
throw new InvalidRequestException([
217217
'error_description' => 'The request includes an invalid parameter value.',
218-
));
218+
]);
219219
}
220220

221221
return $serviceId;
@@ -241,12 +241,12 @@ protected function createDeviceToken($deviceToken, $serviceId, $username, $scope
241241
$device = $deviceManager->createModel($device);
242242

243243
// Prepare parameters for JSON response.
244-
$parameters = array(
244+
$parameters = [
245245
'device_token' => $device->getDeviceToken(),
246246
'service_id' => $device->getServiceId(),
247247
'username' => $device->getUsername(),
248248
'scope' => implode(' ', (array) $device->getScope()),
249-
);
249+
];
250250

251251
return $parameters;
252252
}
@@ -255,23 +255,23 @@ protected function deleteDeviceToken($deviceToken, $serviceId, $username)
255255
{
256256
// Fetch the legacy records for this device_token.
257257
$deviceManager = $this->modelManagerFactory->getModelManager('device');
258-
$devices = $deviceManager->readModelBy(array(
258+
$devices = $deviceManager->readModelBy([
259259
'deviceToken' => $deviceToken,
260260
'serviceId' => $serviceId,
261261
'username' => $username,
262-
));
262+
]);
263263

264264
// Delete the legacy records.
265265
foreach ($devices as $device) {
266266
$deviceManager->deleteModel($device);
267267
}
268268

269269
// Prepare parameters for JSON response.
270-
$parameters = array(
270+
$parameters = [
271271
'device_token' => $deviceToken,
272272
'service_id' => $serviceId,
273273
'username' => $username,
274-
);
274+
];
275275

276276
return $parameters;
277277
}

src/EventListener/ExceptionListener.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ private function handleException(
5959
);
6060

6161
if ($exception->getCode() < 500) {
62-
$this->logger->error($message, array('exception' => $exception));
62+
$this->logger->error($message, ['exception' => $exception]);
6363
} else {
64-
$this->logger->critical($message, array('exception' => $exception));
64+
$this->logger->critical($message, ['exception' => $exception]);
6565
}
6666
}
6767

@@ -76,24 +76,24 @@ private function handleException(
7676
} else {
7777
$code = $exception->getCode();
7878

79-
$response = JsonResponse::create($message, $code, array(
79+
$response = JsonResponse::create($message, $code, [
8080
'Cache-Control' => 'no-store',
8181
'Pragma' => 'no-cache',
82-
));
82+
]);
8383
}
8484

8585
$event->setResponse($response);
8686
}
8787

8888
public static function getSubscribedEvents()
8989
{
90-
return array(
90+
return [
9191
/*
9292
* Priority -2 is used to come after those from SecurityServiceProvider (0)
9393
* but before the error handlers added with Silex\EventListener\LogListener (-4)
9494
* and Silex\Application::error (defaults to -8)
9595
*/
96-
KernelEvents::EXCEPTION => array('onKernelException', -2),
97-
);
96+
KernelEvents::EXCEPTION => ['onKernelException', -2],
97+
];
9898
}
9999
}

src/Exception/AccessDeniedException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
class AccessDeniedException extends \LogicException implements ExceptionInterface
2020
{
21-
public function __construct($message = array(), $code = 403, Exception $previous = null)
21+
public function __construct($message = [], $code = 403, Exception $previous = null)
2222
{
2323
$message['error'] = 'access_denied';
2424
parent::__construct(serialize($message), $code, $previous);

src/Exception/InvalidRequestException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
class InvalidRequestException extends \InvalidArgumentException implements ExceptionInterface
2020
{
21-
public function __construct($message = array(), $code = 400, Exception $previous = null)
21+
public function __construct($message = [], $code = 400, Exception $previous = null)
2222
{
2323
$message['error'] = 'invalid_request';
2424
parent::__construct(serialize($message), $code, $previous);

src/Exception/ServerErrorException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
class ServerErrorException extends \LogicException implements ExceptionInterface
2020
{
21-
public function __construct($message = array(), $code = 500, Exception $previous = null)
21+
public function __construct($message = [], $code = 500, Exception $previous = null)
2222
{
2323
$message['error'] = 'server_error';
2424
parent::__construct(serialize($message), $code, $previous);

src/Exception/TemporarilyUnavailableException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
class TemporarilyUnavailableException extends \LogicException implements ExceptionInterface
2020
{
21-
public function __construct($message = array(), $code = 503, Exception $previous = null)
21+
public function __construct($message = [], $code = 503, Exception $previous = null)
2222
{
2323
$message['error'] = 'temporarily_unavailable';
2424
parent::__construct(serialize($message), $code, $previous);

0 commit comments

Comments
 (0)