Skip to content

Commit 952a5fb

Browse files
committed
perform code style formatting
1 parent 917a25a commit 952a5fb

File tree

91 files changed

+273
-293
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+273
-293
lines changed

src/ApiInitializer.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
use Authorization\Policy\MapResolver;
2121
use Authorization\Policy\OrmResolver;
2222
use Authorization\Policy\ResolverCollection;
23-
use Cake\Http\ServerRequest;
2423
use Cake\Core\Configure;
24+
use Cake\Http\ServerRequest;
2525
use CakeDC\Api\Rbac\ApiRbac;
2626
use CakeDC\Auth\Policy\CollectionPolicy;
2727
use CakeDC\Auth\Policy\RbacPolicy;
@@ -34,7 +34,6 @@ class ApiInitializer implements AuthorizationServiceProviderInterface
3434
*/
3535
public function getAuthenticationService(): AuthenticationService
3636
{
37-
3837
$service = new AuthenticationService();
3938
$service->loadIdentifier('Authentication.JwtSubject', []);
4039

src/Exception/MethodNotAllowedException.php

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
namespace CakeDC\Api\Exception;
1515

16-
use Cake\Core\Exception\Exception;
17-
1816
/**
1917
* Class MethodNotAllowedException
2018
* Used to configure an exception for a service error.

src/Exception/ServiceException.php

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
namespace CakeDC\Api\Exception;
1515

16-
use Cake\Core\Exception\Exception;
17-
1816
/**
1917
* Class ServiceException
2018
* Used to configure an exception for a service error.

src/Exception/UnauthenticatedException.php

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
namespace CakeDC\Api\Exception;
1515

16-
use Cake\Core\Exception\Exception;
17-
1816
/**
1917
* Class UnauthenticatedException
2018
* Used to configure an exception for a service error.

src/Exception/UnauthorizedException.php

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
namespace CakeDC\Api\Exception;
1515

16-
use Cake\Core\Exception\Exception;
17-
1816
/**
1917
* Class UnauthorizedException
2018
*

src/Middleware/ApiMiddleware.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
/**
2828
* Applies routing rules to the request and creates the controller
2929
* instance if possible.
30+
*
3031
* @deprecated use ParseApiRequestMiddleware and ProcessApiRequestMiddleware instead
3132
*/
3233
class ApiMiddleware implements MiddlewareInterface
@@ -40,7 +41,6 @@ class ApiMiddleware implements MiddlewareInterface
4041
*
4142
* @param \Psr\Http\Message\ServerRequestInterface $request The request.
4243
* @param \Psr\Http\Server\RequestHandlerInterface $handler The request handler.
43-
*
4444
* @return \Psr\Http\Message\ResponseInterface A response.
4545
*/
4646
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface

src/Middleware/ParseApiRequestMiddleware.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
7171
}
7272

7373
/**
74-
* @param ServerRequestInterface $request
75-
* @param RequestHandlerInterface $handler
76-
* @param $matches
77-
* @return Response|ResponseInterface|null
74+
* @param \Psr\Http\Message\ServerRequestInterface $request Request object.
75+
* @param \Psr\Http\Server\RequestHandlerInterface $handler Request handler.
76+
* @param mixed $matches Matches definition.
77+
* @return \Cake\Http\Response|\Psr\Http\Message\ResponseInterface|null
7878
*/
7979
protected function _matchRequest(ServerRequestInterface $request, RequestHandlerInterface $handler, $matches)
8080
{

src/Middleware/ProcessApiRequestMiddleware.php

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class ProcessApiRequestMiddleware implements MiddlewareInterface
3434
*
3535
* @param \Psr\Http\Message\ServerRequestInterface $request The request.
3636
* @param \Psr\Http\Server\RequestHandlerInterface $handler The request handler.
37-
*
3837
* @return \Psr\Http\Message\ResponseInterface A response.
3938
*/
4039
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface

src/Middleware/RequestHandlerMiddleware.php

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
/**
1919
* Applies routing rules to the request and creates the controller
2020
* instance if possible.
21+
*
2122
* @deprecated
2223
*/
2324
class RequestHandlerMiddleware extends BodyParserMiddleware

src/Middleware/UnauthorizedHandler/ApiExceptionHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
class ApiExceptionHandler implements HandlerInterface
2626
{
2727
/**
28-
* {@inheritDoc}
28+
* @inheritDoc
2929
*/
3030
public function handle(Exception $exception, Request $request, array $options = []): Response
3131
{

src/Plugin.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
class Plugin extends BasePlugin
2323
{
2424
/**
25-
* {@inheritDoc}
25+
* @inheritDoc
2626
*/
2727
public function routes($routes): void
2828
{

src/Rbac/ApiRbac.php

+5-15
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ public function checkPermissions($user, ServerRequestInterface $request)
140140
* @param array|\ArrayAccess $user Current user data
141141
* @param string $role Effective user's role
142142
* @param \Psr\Http\Message\ServerRequestInterface $request Current request
143-
*
144143
* @return null|\CakeDC\Auth\Rbac\PermissionMatchResult Null if permission is discarded, PermissionMatchResult if a final
145144
* result is produced
146145
*/
@@ -225,29 +224,22 @@ protected function _matchPermission(array $permission, $user, $role, ServerReque
225224
* @param string|array|null $possibleValues Values that are accepted (from permission config)
226225
* @param string|mixed|null $value Value to check with. We'll check the 'dasherized' value too
227226
* @param bool $allowEmpty If true and $value is null, the rule will pass
228-
*
229227
* @return bool
230228
*/
231229
protected function _matchOrAsterisk($possibleValues, $value, $allowEmpty = false)
232230
{
233231
$possibleArray = (array)$possibleValues;
234232

235-
if (
236-
$possibleValues === '*' ||
237-
$value === $possibleValues ||
238-
in_array($value, $possibleArray) ||
239-
in_array($this->_camelizeByChars((string)$value), $possibleArray)
240-
) {
241-
return true;
242-
}
243-
244-
return false;
233+
return $possibleValues === '*' ||
234+
$value === $possibleValues ||
235+
in_array($value, $possibleArray) ||
236+
in_array($this->_camelizeByChars((string)$value), $possibleArray);
245237
}
246238

247239
/**
248240
* Camelize by breaking chars.
249241
*
250-
* @param string $value
242+
* @param string $value String to camelize.
251243
* @return string
252244
*/
253245
protected function _camelizeByChars(string $value)
@@ -264,10 +256,8 @@ protected function _camelizeByChars(string $value)
264256
* Checks if $haystack begins with $needle
265257
*
266258
* @see http://stackoverflow.com/a/7168986/2588539
267-
*
268259
* @param string $haystack The whole string
269260
* @param string $needle The beginning to check
270-
*
271261
* @return bool
272262
*/
273263
protected function _startsWith($haystack, $needle)

src/Rbac/Permissions/AbstractProvider.php

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ abstract class AbstractProvider
3232

3333
/**
3434
* AbstractProvider constructor.
35+
*
3536
* @param array $config config
3637
*/
3738
public function __construct($config = [])

src/Service/Action/Action.php

+7-15
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,8 @@ public function process()
245245
return $event->getResult();
246246
}
247247

248-
// thrown before execute action event (with stop on false)
249-
if (method_exists($this, 'action')) {
250-
$result = $this->_executeAction();
251-
} else {
252-
$result = $this->execute();
253-
}
254-
$this->dispatchEvent('Action.afterProcess', compact('result'));
248+
$result = method_exists($this, 'action') ? $this->_executeAction() : $this->execute();
249+
$this->dispatchEvent('Action.afterProcess', ['result' => $result]);
255250

256251
return $result;
257252
}
@@ -279,18 +274,15 @@ protected function _executeAction(string $methodName = 'action')
279274
} else {
280275
throw new Exception('Missing required param: ' . $paramName, 409);
281276
}
277+
} elseif ($params[$paramName] === '' && $param->isOptional()) {
278+
$arguments[] = $param->getDefaultValue();
282279
} else {
283-
if ($params[$paramName] === '' && $param->isOptional()) {
284-
$arguments[] = $param->getDefaultValue();
285-
} else {
286-
$value = $params[$paramName];
287-
$arguments[] = is_numeric($value) ? 0 + $value : $value;
288-
}
280+
$value = $params[$paramName];
281+
$arguments[] = is_numeric($value) ? 0 + $value : $value;
289282
}
290283
}
291-
$result = call_user_func_array([$this, $methodName], $arguments);
292284

293-
return $result;
285+
return call_user_func_array([$this, $methodName], $arguments);
294286
}
295287

296288
/**

src/Service/Action/Auth/JwtTokenTrait.php

+9-11
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@
1717
use Cake\ORM\TableRegistry;
1818
use Cake\Routing\Router;
1919
use Cake\Utility\Hash;
20-
2120
use DateInterval;
2221
use DateTimeImmutable;
2322
use Lcobucci\JWT\Configuration;
24-
use Lcobucci\JWT\Signer\Key\InMemory;
2523
use Lcobucci\JWT\Signer\Hmac\Sha256;
26-
use Lcobucci\JWT\Builder;
2724
use Lcobucci\JWT\Signer\Hmac\Sha512;
25+
use Lcobucci\JWT\Signer\Key\InMemory;
2826

2927
trait JwtTokenTrait
3028
{
@@ -50,7 +48,7 @@ public function generateTokenResponse($user)
5048
* Generates access token.
5149
*
5250
* @param \Cake\Datasource\EntityInterface|array $user User info.
53-
* @param DateTimeImmutable $timestamp Timestamp.
51+
* @param \DateTimeImmutable $timestamp Timestamp.
5452
* @return bool|string
5553
*/
5654
public function generateAccessToken($user, $timestamp)
@@ -82,7 +80,7 @@ public function generateAccessToken($user, $timestamp)
8280
* Generates refresh token.
8381
*
8482
* @param \Cake\Datasource\EntityInterface|array $user User info.
85-
* @param DateTimeImmutable $timestamp Timestamp.
83+
* @param \DateTimeImmutable $timestamp Timestamp.
8684
* @return bool|string
8785
*/
8886
public function generateRefreshToken($user, $timestamp)
@@ -138,26 +136,26 @@ public function generateRefreshToken($user, $timestamp)
138136
/**
139137
* Generates access token with life time.
140138
*
141-
* @param DateTimeImmutable $timestamp Timestamp.
142-
* @return DateTimeImmutable
139+
* @param \DateTimeImmutable $timestamp Timestamp.
140+
* @return \DateTimeImmutable
143141
*/
144142
private function accessTokenLifeTime(DateTimeImmutable $timestamp): DateTimeImmutable
145143
{
146144
$accessTokenLifeTime = Configure::read('Api.Jwt.AccessToken.lifetime');
147145

148-
return $timestamp->add(new DateInterval("PT" . $accessTokenLifeTime . "S"));
146+
return $timestamp->add(new DateInterval('PT' . $accessTokenLifeTime . 'S'));
149147
}
150148

151149
/**
152150
* Generates refresh token with life time.
153151
*
154-
* @param DateTimeImmutable $timestamp Timestamp.
155-
* @return DateTimeImmutable
152+
* @param \DateTimeImmutable $timestamp Timestamp.
153+
* @return \DateTimeImmutable
156154
*/
157155
private function refreshTokenLifeTime(DateTimeImmutable $timestamp): DateTimeImmutable
158156
{
159157
$refreshTokenLifeTime = Configure::read('Api.Jwt.RefreshToken.lifetime');
160158

161-
return $timestamp->add(new DateInterval("PT" . $refreshTokenLifeTime . "S"));
159+
return $timestamp->add(new DateInterval('PT' . $refreshTokenLifeTime . 'S'));
162160
}
163161
}

src/Service/Action/Auth/LoginAction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ protected function _afterIdentifyUser($user, $socialLogin = false)
108108
// $this->dispatchEvent(UsersAuthComponent::EVENT_AFTER_LOGIN, ['user' => $user]);
109109
}
110110

111-
$event = $this->dispatchEvent('Action.Auth.onLoginFormat', compact('user'));
111+
$event = $this->dispatchEvent('Action.Auth.onLoginFormat', ['user' => $user]);
112112
if ($event->getResult()) {
113113
$user = $event->getResult();
114114
}

src/Service/Action/Auth/RegisterAction.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,11 @@ protected function _registerOptions(): array
148148
$validateEmail = (bool)Configure::read('Users.Email.validate');
149149
$useTos = (bool)Configure::read('Users.Tos.required');
150150
$tokenExpiration = Configure::read('Users.Token.expiration');
151-
$options = [
151+
152+
return [
152153
'token_expiration' => $tokenExpiration,
153154
'validate_email' => $validateEmail,
154155
'use_tos' => $useTos,
155156
];
156-
157-
return $options;
158157
}
159158
}

src/Service/Action/Auth/ResetPasswordAction.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ public function execute()
8383
throw new Exception(__d('CakeDC/Api', 'Reset password token could not be validated'));
8484
}
8585
} catch (UserAlreadyActiveException $exception) {
86-
throw new Exception(__d('CakeDC/Api', 'User already active'), 500);
86+
throw new Exception(__d('CakeDC/Api', 'User already active'), 500, $exception);
8787
} catch (UserNotFoundException $ex) {
88-
throw new Exception(__d('CakeDC/Api', 'Invalid token or user account already validated'), 500);
88+
throw new Exception(__d('CakeDC/Api', 'Invalid token or user account already validated'), 500, $ex);
8989
} catch (TokenExpiredException $ex) {
90-
throw new Exception(__d('CakeDC/Api', 'Token already expired'), 500);
90+
throw new Exception(__d('CakeDC/Api', 'Token already expired'), 500, $ex);
9191
}
9292
}
9393

@@ -117,11 +117,11 @@ protected function _changePassword($userId)
117117
}
118118
}
119119
} catch (UserNotFoundException $exception) {
120-
throw new Exception(__d('CakeDC/Api', 'User was not found'), 404);
120+
throw new Exception(__d('CakeDC/Api', 'User was not found'), 404, $exception);
121121
} catch (WrongPasswordException $wpe) {
122-
throw new Exception(__d('CakeDC/Api', '{0}', $wpe->getMessage()), 500);
122+
throw new Exception(__d('CakeDC/Api', '{0}', $wpe->getMessage()), 500, $wpe);
123123
} catch (Exception $exception) {
124-
throw new Exception(__d('CakeDC/Api', 'Password could not be changed'), 500);
124+
throw new Exception(__d('CakeDC/Api', 'Password could not be changed'), 500, $exception);
125125
}
126126
}
127127

src/Service/Action/Auth/ResetPasswordRequestAction.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,17 @@ public function execute()
8282
'ensureActive' => Configure::read('Users.Registration.ensureActive'),
8383
]);
8484
if ($resetUser) {
85-
$message = __d('CakeDC/Api', 'Please check your email to continue with password reset process');
86-
87-
return $message;
85+
return __d('CakeDC/Api', 'Please check your email to continue with password reset process');
8886
} else {
8987
$message = __d('CakeDC/Api', 'The password token could not be generated. Please try again');
9088
throw new Exception($message, 500);
9189
}
9290
} catch (UserNotFoundException $exception) {
93-
throw new Exception(__d('CakeDC/Api', 'User {0} was not found', $reference), 404);
91+
throw new Exception(__d('CakeDC/Api', 'User {0} was not found', $reference), 404, $exception);
9492
} catch (UserNotActiveException $exception) {
95-
throw new Exception(__d('CakeDC/Api', 'The user is not active'), 404);
93+
throw new Exception(__d('CakeDC/Api', 'The user is not active'), 404, $exception);
9694
} catch (Exception $exception) {
97-
throw new Exception(__d('CakeDC/Api', 'Token could not be reset'), 500);
95+
throw new Exception(__d('CakeDC/Api', 'Token could not be reset'), 500, $exception);
9896
}
9997
}
10098

src/Service/Action/Auth/SocialLoginAction.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,17 @@ public function execute()
8787

8888
return $result;
8989
} catch (UserNotActiveException $ex) {
90-
throw new Exception(__d('CakeDC/Api', 'User account has not validated yet'), 501);
90+
throw new Exception(__d('CakeDC/Api', 'User account has not validated yet'), 501, $ex);
9191
} catch (UserAlreadyActiveException $ex) {
92-
throw new Exception($ex->getMessage(), 502);
92+
throw new Exception($ex->getMessage(), 502, $ex);
9393
} catch (UserNotFoundException $ex) {
94-
throw new Exception(__d('CakeDC/Api', 'Invalid token or user account already validated'), 503);
94+
throw new Exception(__d('CakeDC/Api', 'Invalid token or user account already validated'), 503, $ex);
9595
} catch (TokenExpiredException $ex) {
96-
throw new Exception($ex->getMessage(), 504);
96+
throw new Exception($ex->getMessage(), 504, $ex);
9797
} catch (MissingEmailException $ex) {
98-
throw new Exception($ex->getMessage(), 505);
98+
throw new Exception($ex->getMessage(), 505, $ex);
9999
} catch (\Exception $ex) {
100-
throw new Exception($ex->getMessage(), 500);
100+
throw new Exception($ex->getMessage(), 500, $ex);
101101
}
102102
}
103103

0 commit comments

Comments
 (0)