Skip to content

Commit ba48083

Browse files
committed
code style fixes
1 parent 52a1923 commit ba48083

File tree

13 files changed

+51
-41
lines changed

13 files changed

+51
-41
lines changed

src/ApiInitializer.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php
22
declare(strict_types=1);
33

44
/**
@@ -15,24 +15,22 @@
1515

1616
use Authentication\AuthenticationService;
1717
use Authorization\AuthorizationService;
18-
use Authorization\AuthorizationServiceInterface;
18+
use Authorization\AuthorizationServiceInterface as ASI;
1919
use Authorization\AuthorizationServiceProviderInterface;
2020
use Authorization\Policy\MapResolver;
2121
use Authorization\Policy\OrmResolver;
2222
use Authorization\Policy\ResolverCollection;
23-
use Cake\Core\Configure;
2423
use Cake\Http\ServerRequest;
2524
use CakeDC\Api\Rbac\ApiRbac;
26-
use CakeDC\Auth\Rbac\Rbac;
2725
use CakeDC\Auth\Policy\CollectionPolicy;
2826
use CakeDC\Auth\Policy\RbacPolicy;
29-
use CakeDC\Auth\Policy\SuperuserPolicy;
30-
use Psr\Http\Message\ResponseInterface;
3127
use Psr\Http\Message\ServerRequestInterface;
3228

3329
class ApiInitializer implements AuthorizationServiceProviderInterface
3430
{
35-
31+
/**
32+
* @return \Authentication\AuthenticationService
33+
*/
3634
public function getAuthenticationService(): AuthenticationService
3735
{
3836
$service = new AuthenticationService();
@@ -50,11 +48,15 @@ public function getAuthenticationService(): AuthenticationService
5048
$service->loadAuthenticator('Authentication.Token', [
5149
'queryParam' => 'token',
5250
]);
53-
51+
5452
return $service;
5553
}
5654

57-
public function getAuthorizationService(ServerRequestInterface $request): AuthorizationServiceInterface
55+
/**
56+
* @param \Psr\Http\Message\ServerRequestInterface $request Request instance.
57+
* @return \Authorization\AuthorizationServiceInterface
58+
*/
59+
public function getAuthorizationService(ServerRequestInterface $request): ASI
5860
{
5961
$map = new MapResolver();
6062
$rbac = new ApiRbac();
@@ -63,19 +65,18 @@ public function getAuthorizationService(ServerRequestInterface $request): Author
6365
new CollectionPolicy([
6466
//SuperuserPolicy::class,
6567
new RbacPolicy([
66-
'adapter' => $rbac
67-
])
68+
'adapter' => $rbac,
69+
]),
6870
])
6971
);
7072

7173
$orm = new OrmResolver();
7274

7375
$resolver = new ResolverCollection([
7476
$map,
75-
$orm
77+
$orm,
7678
]);
7779

7880
return new AuthorizationService($resolver);
7981
}
80-
8182
}

src/Controller/ApiController.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,12 @@ protected function _process(array $options = []): ?Response
123123

124124
return $this->getResponse();
125125
}
126-
126+
127+
/**
128+
* Not found router fallback method.
129+
*
130+
* @return \Cake\Http\Response|null
131+
*/
127132
public function notFound()
128133
{
129134
return $this->getResponse()->withStatus(404);

src/Middleware/ParseApiRequestMiddleware.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Cake\Core\Configure;
1818
use Cake\Http\Response;
1919
use CakeDC\Api\Service\ConfigReader;
20-
use CakeDC\Api\Service\Result;
2120
use CakeDC\Api\Service\ServiceRegistry;
2221
use Exception;
2322
use Psr\Http\Message\ResponseInterface;

src/Middleware/UnauthorizedHandler/ApiExceptionHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
use Authorization\Exception\Exception;
1717
use Authorization\Exception\ForbiddenException;
1818
use Authorization\Middleware\UnauthorizedHandler\HandlerInterface;
19-
use Psr\Http\Message\ResponseInterface;
20-
use Psr\Http\Message\ServerRequestInterface;
19+
use Psr\Http\Message\ResponseInterface as Response;
20+
use Psr\Http\Message\ServerRequestInterface as Request;
2121

2222
/**
2323
* This handler rethrows an exception caught by the middleware.
@@ -27,7 +27,7 @@ class ApiExceptionHandler implements HandlerInterface
2727
/**
2828
* {@inheritDoc}
2929
*/
30-
public function handle(Exception $exception, ServerRequestInterface $request, array $options = []): ResponseInterface
30+
public function handle(Exception $exception, Request $request, array $options = []): Response
3131
{
3232
$service = $request->getAttribute('service');
3333
if ($service !== null) {

src/Plugin.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@
1313

1414
namespace CakeDC\Api;
1515

16-
use Authentication\AuthenticationService;
17-
use Authentication\Middleware\AuthenticationMiddleware;
18-
use Authorization\Middleware\AuthorizationMiddleware;
19-
use Authorization\Middleware\RequestAuthorizationMiddleware;
20-
use CakeDC\Api\Middleware\ParseApiRequestMiddleware;
21-
use CakeDC\Api\Middleware\ProcessApiRequestMiddleware;
2216
use Cake\Core\BasePlugin;
2317
use Cake\Core\Configure;
2418

@@ -27,7 +21,9 @@
2721
*/
2822
class Plugin extends BasePlugin
2923
{
30-
24+
/**
25+
* {@inheritDoc}
26+
*/
3127
public function routes($routes): void
3228
{
3329
$middlewares = Configure::read('Api.Middleware');
@@ -51,6 +47,5 @@ public function routes($routes): void
5147
}
5248

5349
parent::routes($routes);
54-
}
55-
50+
}
5651
}

src/Rbac/ApiRbac.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ protected function _matchOrAsterisk($possibleValues, $value, $allowEmpty = false
231231
{
232232
$possibleArray = (array)$possibleValues;
233233

234-
if ($possibleValues === '*' ||
234+
if (
235+
$possibleValues === '*' ||
235236
$value === $possibleValues ||
236237
in_array($value, $possibleArray) ||
237238
in_array(Inflector::camelize((string)$value, '-'), $possibleArray)

src/Service/Action/Auth/ValidateAccountRequestAction.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,14 @@ public function execute()
7474
$data = $this->getData();
7575
$reference = $data['reference'];
7676
try {
77-
if ($this->getUsersTable()->resetToken($reference, [
77+
if (
78+
$this->getUsersTable()->resetToken($reference, [
7879
'expiration' => Configure::read('Users.Token.expiration'),
7980
'checkActive' => true,
8081
'sendEmail' => true,
8182
'emailTemplate' => 'CakeDC/Users.validation',
82-
])) {
83+
])
84+
) {
8385
return __d('CakeDC/Api', 'Token has been reset successfully. Please check your email.');
8486
} else {
8587
throw new Exception(__d('CakeDC/Api', 'Token could not be reset'), 500);

src/Service/Action/CrudAction.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,10 @@ protected function _describe(): array
362362
];
363363

364364
$validators = [];
365-
foreach ($table->getValidator()
366-
->getIterator() as $name => $field) {
365+
foreach (
366+
$table->getValidator()
367+
->getIterator() as $name => $field
368+
) {
367369
/** @var \Cake\Validation\ValidationSet $field */
368370
$validators[$name] = [
369371
'validatePresence' => $field->isPresenceRequired(),

src/Service/Auth/Auth.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ public function authCheck(Event $event)
231231
throw new UnauthenticatedException();
232232
}
233233

234-
if (empty($this->_config['authorize']) ||
234+
if (
235+
empty($this->_config['authorize']) ||
235236
$this->isAuthorized($this->user())
236237
) {
237238
return null;

src/Service/Auth/Authorize/SimpleRbacAuthorize.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,12 @@ protected function _matchRule(array $permission, $user, string $role, ServerRequ
195195
$service = $this->_action->getService()->getName();
196196
$version = $this->_action->getService()->getVersion();
197197

198-
if ($this->_matchOrAsterisk($permission, 'role', $role) &&
198+
if (
199+
$this->_matchOrAsterisk($permission, 'role', $role) &&
199200
$this->_matchOrAsterisk($permission, 'version', $version, true) &&
200201
$this->_matchOrAsterisk($permission, 'service', $service) &&
201-
$this->_matchOrAsterisk($permission, 'action', $action)) {
202+
$this->_matchOrAsterisk($permission, 'action', $action)
203+
) {
202204
$allowed = Hash::get($permission, 'allowed');
203205

204206
if ($allowed === null) {
@@ -231,9 +233,11 @@ protected function _matchOrAsterisk(array $permission, string $key, $value, bool
231233
if ($allowEmpty && empty($possibleValues) && $value === null) {
232234
return true;
233235
}
234-
if (Hash::get($permission, $key) === '*' ||
236+
if (
237+
Hash::get($permission, $key) === '*' ||
235238
in_array($value, $possibleValues) ||
236-
in_array(Inflector::camelize($value, '-'), $possibleValues)) {
239+
in_array(Inflector::camelize($value, '-'), $possibleValues)
240+
) {
237241
return true;
238242
}
239243

tests/Fixture/ArticlesFixture.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ class ArticlesFixture extends TestFixture
5858
['id' => 15, 'author_id' => 1, 'title' => 'Article N15', 'body' => 'Article N15 Body', 'published' => 'Y'],
5959
];
6060

61-
public function insert(ConnectionInterface $db) {
61+
public function insert(ConnectionInterface $db)
62+
{
6263
parent::insert($db);
6364

6465
if ($db->getDriver() instanceof Postgres) {
65-
foreach (range(1,count($this->records)) as $i) {
66+
foreach (range(1, count($this->records)) as $i) {
6667
$db->execute('select nextval(\'articles_id_seq\'::regclass)');
6768
}
6869
}

tests/FixturesTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ trait FixturesTrait
3333
'plugin.CakeDC/Api.Tags',
3434
'plugin.CakeDC/Api.ArticlesTags',
3535
];
36-
36+
3737
public function mergeFixtures()
3838
{
3939
if (empty($this->fixtures)) {

tests/TestCase/Auth/Authorize/SimpleRbacAuthorizeTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
class SimpleRbacAuthorizeTest extends TestCase
2626
{
27-
2827
/**
2928
* @var Service
3029
*/

0 commit comments

Comments
 (0)