Skip to content

Commit b1f4d23

Browse files
authored
Merge pull request #118 from phansys/usermanager
[UserManager] Some minor improvements
2 parents 5df5c57 + b426fc2 commit b1f4d23

1 file changed

Lines changed: 14 additions & 15 deletions

File tree

Manager/UserManager.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,39 @@
22

33
namespace Hackzilla\Bundle\TicketBundle\Manager;
44

5-
use Doctrine\ORM\EntityRepository;
5+
use Doctrine\Common\Persistence\ObjectRepository;
66
use Hackzilla\Bundle\TicketBundle\Model\TicketInterface;
77
use Hackzilla\Bundle\TicketBundle\Model\UserInterface;
88
use Hackzilla\Bundle\TicketBundle\TicketRole;
9-
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
9+
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
10+
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
1011
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
1112

1213
class UserManager implements UserManagerInterface
1314
{
1415
/**
15-
* @var \Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface
16+
* @var TokenStorageInterface
1617
*/
1718
private $tokenStorage;
1819

1920
/**
20-
* @var \Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface
21+
* @var AuthorizationCheckerInterface
2122
*/
2223
private $authorizationChecker;
2324

2425
/**
25-
* @var \Doctrine\ORM\EntityRepository
26+
* @var ObjectRepository
2627
*/
2728
private $userRepository;
2829

2930
/**
30-
* @param TokenStorage $tokenStorage
31+
* @param TokenStorageInterface $tokenStorage
32+
* @param ObjectRepository $userRepository
3133
* @param AuthorizationCheckerInterface $authorizationChecker
32-
* @param EntityRepository $userRepository
3334
*/
3435
public function __construct(
35-
TokenStorage $tokenStorage,
36-
EntityRepository $userRepository,
36+
TokenStorageInterface $tokenStorage,
37+
ObjectRepository $userRepository,
3738
AuthorizationCheckerInterface $authorizationChecker
3839
) {
3940
$this->tokenStorage = $tokenStorage;
@@ -66,9 +67,7 @@ public function getUserById($userId)
6667
return;
6768
}
6869

69-
$user = $this->userRepository->find($userId);
70-
71-
return $user;
70+
return $this->userRepository->find($userId);
7271
}
7372

7473
/**
@@ -85,8 +84,8 @@ public function hasRole(UserInterface $user, $role)
8584
}
8685

8786
/**
88-
* @param \Hackzilla\Bundle\TicketBundle\Model\UserInterface|string $user
89-
* @param TicketInterface $ticket
87+
* @param UserInterface|string $user
88+
* @param TicketInterface $ticket
9089
*/
9190
public function hasPermission($user, TicketInterface $ticket)
9291
{
@@ -95,7 +94,7 @@ public function hasPermission($user, TicketInterface $ticket)
9594
TicketRole::ADMIN
9695
) && $ticket->getUserCreated() != $user->getId())
9796
) {
98-
throw new \Symfony\Component\HttpKernel\Exception\HttpException(403);
97+
throw new AccessDeniedHttpException();
9998
}
10099
}
101100
}

0 commit comments

Comments
 (0)