Skip to content
This repository was archived by the owner on Dec 17, 2019. It is now read-only.

Commit 5ad660b

Browse files
author
Loek van der Linde
committed
Coding standards
1 parent c7f4b43 commit 5ad660b

File tree

5 files changed

+35
-18
lines changed

5 files changed

+35
-18
lines changed

src/AppBundle/Controller/TokenController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace AppBundle\Controller;
44

5+
use AppBundle\Exception\InvalidRequestArgumentException;
56
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
67
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
78
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
@@ -25,14 +26,14 @@ public function newTokenAction(Request $request)
2526
$user = $repository->findOneBy(['username' => $username]);
2627

2728
if (is_null($user)) {
28-
throw new BadCredentialsException();
29+
throw new InvalidRequestArgumentException('User not found', 401);
2930
}
3031

3132
$encoder = $this->get('security.password_encoder');
3233
$passwordValid = $encoder->isPasswordValid($user, $password);
3334

3435
if (!$passwordValid) {
35-
throw new BadCredentialsException();
36+
throw new InvalidRequestArgumentException('Password invalid', 401);
3637
}
3738

3839
$tokenEncoder = $this->get('lexik_jwt_authentication.encoder');

src/AppBundle/DataFixtures/ORM/LoadUserData.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class LoadUserData implements FixtureInterface, ContainerAwareInterface
2020
*
2121
* @param ObjectManager $manager
2222
*/
23-
public function load(ObjectManager $manager) {
23+
public function load(ObjectManager $manager)
24+
{
2425
$user = new User();
2526

2627
$plainPassword = 'unsafepassword';
@@ -39,7 +40,8 @@ public function load(ObjectManager $manager) {
3940
*
4041
* @param ContainerInterface|null $container A ContainerInterface instance or null
4142
*/
42-
public function setContainer(ContainerInterface $container = NULL) {
43+
public function setContainer(ContainerInterface $container = null)
44+
{
4345
$this->container = $container;
4446
}
4547
}

src/AppBundle/Entity/User.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ public function getPassword()
112112
*
113113
* @return (Role|string)[] The user roles
114114
*/
115-
public function getRoles() {
115+
public function getRoles()
116+
{
116117
return ['ROLE_USER'];
117118
}
118119

@@ -123,7 +124,8 @@ public function getRoles() {
123124
*
124125
* @return string|null The salt
125126
*/
126-
public function getSalt() {
127+
public function getSalt()
128+
{
127129
return null;
128130
}
129131

@@ -133,7 +135,8 @@ public function getSalt() {
133135
* This is important if, at any given point, sensitive information like
134136
* the plain-text password is stored on this object.
135137
*/
136-
public function eraseCredentials() {
138+
public function eraseCredentials()
139+
{
137140
}
138141

139142
/**
@@ -142,7 +145,8 @@ public function eraseCredentials() {
142145
* @return string the string representation of the object or null
143146
* @since 5.1.0
144147
*/
145-
public function serialize() {
148+
public function serialize()
149+
{
146150
return serialize([
147151
$this->id,
148152
$this->username,
@@ -159,12 +163,12 @@ public function serialize() {
159163
* @return void
160164
* @since 5.1.0
161165
*/
162-
public function unserialize($serialized) {
166+
public function unserialize($serialized)
167+
{
163168
list (
164169
$this->id,
165170
$this->username,
166171
$this->password
167172
) = unserialize($serialized);
168173
}
169174
}
170-

src/AppBundle/EventDispatcher/Listener/InvalidRequestArgumentListener.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ public function onInvalidRequestArgumentException(GetResponseForExceptionEvent $
2727
],
2828
];
2929

30+
$statusCode = $exception->getCode();
31+
3032
if ($responseData['error'][0]['code'] === 0) {
3133
$responseData['error'][0]['code'] = Response::HTTP_BAD_REQUEST;
34+
$statusCode = Response::HTTP_BAD_REQUEST;
3235
}
3336

34-
$event->setResponse(new JsonResponse($responseData, Response::HTTP_BAD_REQUEST));
37+
$event->setResponse(new JsonResponse($responseData, $statusCode));
3538
}
3639
}

src/AppBundle/Security/JwtTokenAuthenticator.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ public function __construct(JWTEncoderInterface $encoder, EntityManager $em)
5151
*
5252
* @return Response
5353
*/
54-
public function start(Request $request, AuthenticationException $authException = NULL) {
54+
public function start(Request $request, AuthenticationException $authException = null)
55+
{
5556
return new JsonResponse([
5657
'error' => 'Auth required'
5758
], 401);
@@ -83,7 +84,8 @@ public function start(Request $request, AuthenticationException $authException =
8384
*
8485
* @return mixed|null
8586
*/
86-
public function getCredentials(Request $request) {
87+
public function getCredentials(Request $request)
88+
{
8789
$tokenExctractor = new AuthorizationHeaderTokenExtractor(
8890
'Bearer',
8991
'Authorization'
@@ -113,7 +115,8 @@ public function getCredentials(Request $request) {
113115
*
114116
* @return UserInterface|null
115117
*/
116-
public function getUser($credentials, UserProviderInterface $userProvider) {
118+
public function getUser($credentials, UserProviderInterface $userProvider)
119+
{
117120
try {
118121
$data = $this->encoder->decode($credentials);
119122
} catch (JWTDecodeFailureException $e) {
@@ -143,7 +146,8 @@ public function getUser($credentials, UserProviderInterface $userProvider) {
143146
*
144147
* @throws AuthenticationException
145148
*/
146-
public function checkCredentials($credentials, UserInterface $user) {
149+
public function checkCredentials($credentials, UserInterface $user)
150+
{
147151
// We've done all stuff like password checking before, so nothing needs to happen here
148152
return true;
149153
}
@@ -162,7 +166,8 @@ public function checkCredentials($credentials, UserInterface $user) {
162166
*
163167
* @return Response|null
164168
*/
165-
public function onAuthenticationFailure(Request $request, AuthenticationException $exception) {
169+
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
170+
{
166171
// TODO: Implement onAuthenticationFailure() method.
167172
}
168173

@@ -181,7 +186,8 @@ public function onAuthenticationFailure(Request $request, AuthenticationExceptio
181186
*
182187
* @return Response|null
183188
*/
184-
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey) {
189+
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey)
190+
{
185191
return null;
186192
}
187193

@@ -198,7 +204,8 @@ public function onAuthenticationSuccess(Request $request, TokenInterface $token,
198204
*
199205
* @return bool
200206
*/
201-
public function supportsRememberMe() {
207+
public function supportsRememberMe()
208+
{
202209
return false;
203210
}
204211
}

0 commit comments

Comments
 (0)