Skip to content
This repository has been archived by the owner on Feb 18, 2021. It is now read-only.

Commit

Permalink
Merge pull request #69 from jonasdekeukelaere/php71
Browse files Browse the repository at this point in the history
Update code to php7
  • Loading branch information
StijnVrolijk authored Nov 27, 2017
2 parents da680bb + d44ffc9 commit 0969a63
Show file tree
Hide file tree
Showing 54 changed files with 313 additions and 600 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: php

matrix:
include:
- php: 7
- php: 7.1
- php: nightly

before_script:
Expand Down
8 changes: 1 addition & 7 deletions Command/AbstractUserHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,10 @@

abstract class AbstractUserHandler implements Handler
{
/**
* @param BaseUserRepositoryCollection $userRepositoryCollection
* @param User $user
*
* @return UserRepository
*/
protected function getUserRepositoryForUser(
BaseUserRepositoryCollection $userRepositoryCollection,
User $user
) {
): UserRepository {
return $userRepositoryCollection->findRepositoryByClassName(get_class($user));
}
}
6 changes: 1 addition & 5 deletions Command/CreateUserHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ final class CreateUserHandler extends AbstractUserHandler
/** @var EncoderFactoryInterface */
private $encoderFactory;

/**
* @param EncoderFactoryInterface $encoderFactory
* @param BaseUserRepositoryCollection $userRepositoryCollection
*/
public function __construct(
EncoderFactoryInterface $encoderFactory,
BaseUserRepositoryCollection $userRepositoryCollection
Expand All @@ -26,7 +22,7 @@ public function __construct(
$this->encoderFactory = $encoderFactory;
}

public function handle(UserDataTransferObject $userDataTransferObject)
public function handle(UserDataTransferObject $userDataTransferObject): void
{
$newUser = $userDataTransferObject->getEntity();

Expand Down
5 changes: 1 addition & 4 deletions Command/DeleteUserHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ final class DeleteUserHandler extends AbstractUserHandler
/** @var BaseUserRepositoryCollection */
private $userRepositoryCollection;

/**
* @param BaseUserRepositoryCollection $userRepositoryCollection
*/
public function __construct(BaseUserRepositoryCollection $userRepositoryCollection)
{
$this->userRepositoryCollection = $userRepositoryCollection;
}

public function handle(UserDataTransferObject $user)
public function handle(UserDataTransferObject $user): void
{
$userEntity = $user->getEntity();

Expand Down
5 changes: 1 addition & 4 deletions Command/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,5 @@

interface Handler
{
/**
* @param UserDataTransferObject $user
*/
public function handle(UserDataTransferObject $user);
public function handle(UserDataTransferObject $user): void;
}
19 changes: 2 additions & 17 deletions Command/RequestPasswordResetHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace SumoCoders\FrameworkMultiUserBundle\Command;

use Doctrine\ORM\EntityNotFoundException;
use SumoCoders\FrameworkMultiUserBundle\DataTransferObject\RequestPasswordDataTransferObject;
use SumoCoders\FrameworkMultiUserBundle\Event\PasswordResetTokenCreated;
use SumoCoders\FrameworkMultiUserBundle\User\Interfaces\User;
Expand All @@ -17,10 +16,6 @@ class RequestPasswordResetHandler
/** @var EventDispatcherInterface */
private $dispatcher;

/**
* @param BaseUserRepositoryCollection $userRepositoryCollection
* @param EventDispatcherInterface $dispatcher
*/
public function __construct(
BaseUserRepositoryCollection $userRepositoryCollection,
EventDispatcherInterface $dispatcher
Expand All @@ -29,12 +24,7 @@ public function __construct(
$this->dispatcher = $dispatcher;
}

/**
* Creates a password reset token and sends an email to the user.
*
* @param RequestPasswordDataTransferObject $dataTransferObject
*/
public function handle(RequestPasswordDataTransferObject $dataTransferObject)
public function handle(RequestPasswordDataTransferObject $dataTransferObject): void
{
$user = $this->userRepositoryCollection->findUserByUserName($dataTransferObject->userName);

Expand All @@ -45,12 +35,7 @@ public function handle(RequestPasswordDataTransferObject $dataTransferObject)
$this->sendPasswordResetToken($user);
}

/**
* Sends the password reset token to the user.
*
* @param User $user
*/
private function sendPasswordResetToken(User $user)
private function sendPasswordResetToken(User $user): void
{
$event = new PasswordResetTokenCreated($user);
$this->dispatcher->dispatch(PasswordResetTokenCreated::NAME, $event);
Expand Down
6 changes: 1 addition & 5 deletions Command/ResetPasswordHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ class ResetPasswordHandler
/** @var EncoderFactoryInterface */
private $encoderFactory;

/**
* @param BaseUserRepositoryCollection $userRepositoryCollection
* @param EncoderFactoryInterface $encoderFactory
*/
public function __construct(
BaseUserRepositoryCollection $userRepositoryCollection,
EncoderFactoryInterface $encoderFactory
Expand All @@ -32,7 +28,7 @@ public function __construct(
*
* @throws InvalidPasswordConfirmationException
*/
public function handle(ChangePasswordDataTransferObject $dataTransferObject)
public function handle(ChangePasswordDataTransferObject $dataTransferObject): void
{
$user = $dataTransferObject->user;
$user->setPassword($dataTransferObject->newPassword);
Expand Down
6 changes: 1 addition & 5 deletions Command/UpdateUserHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ final class UpdateUserHandler extends AbstractUserHandler
/** @var EncoderFactoryInterface */
private $encoderFactory;

/**
* @param EncoderFactoryInterface $encoderFactory
* @param BaseUserRepositoryCollection $userRepositoryCollection
*/
public function __construct(
EncoderFactoryInterface $encoderFactory,
BaseUserRepositoryCollection $userRepositoryCollection
Expand All @@ -26,7 +22,7 @@ public function __construct(
$this->encoderFactory = $encoderFactory;
}

public function handle(UserDataTransferObject $userDataTransferObject)
public function handle(UserDataTransferObject $userDataTransferObject): void
{
$userEntity = $userDataTransferObject->getEntity();

Expand Down
7 changes: 2 additions & 5 deletions Console/CreateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ final class CreateUserCommand extends Command
/** @var CreateUserHandler */
private $handler;

/**
* @param CreateUserHandler $handler
*/
public function __construct(CreateUserHandler $handler)
{
parent::__construct();
$this->handler = $handler;
}

protected function configure()
protected function configure(): void
{
$this
->setName('sumocoders:multiuser:create')
Expand Down Expand Up @@ -51,7 +48,7 @@ protected function configure()
;
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): void
{
$userTransferObject = new BaseUserDataTransferObject();
$userTransferObject->userName = $input->getArgument('username');
Expand Down
8 changes: 2 additions & 6 deletions Console/DeleteUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,14 @@ final class DeleteUserCommand extends Command
/** @var DeleteUserHandler */
private $handler;

/**
* @param UserRepository $userRepository
* @param DeleteUserHandler $handler
*/
public function __construct(UserRepository $userRepository, DeleteUserHandler $handler)
{
parent::__construct();
$this->userRepository = $userRepository;
$this->handler = $handler;
}

protected function configure()
protected function configure(): void
{
$this
->setName('sumocoders:multiuser:delete')
Expand All @@ -42,7 +38,7 @@ protected function configure()
;
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): void
{
$username = $input->getArgument('username');
$user = $this->userRepository->findByUsername($username);
Expand Down
16 changes: 2 additions & 14 deletions Controller/BlockController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,12 @@ final class BlockController
/** @var string */
private $redirectRoute;

/**
* @param UserRepository $userRepository
* @param FlashBagInterface $flashBag
* @param TranslatorInterface $translator
* @param Router $router
* @param string $redirectRoute
*/
public function __construct(
UserRepository $userRepository,
FlashBagInterface $flashBag,
TranslatorInterface $translator,
Router $router,
$redirectRoute
string $redirectRoute
) {
$this->userRepository = $userRepository;
$this->flashBag = $flashBag;
Expand All @@ -46,12 +39,7 @@ public function __construct(
$this->redirectRoute = $redirectRoute;
}

/**
* @param int $id
*
* @return RedirectResponse
*/
public function toggleAction($id)
public function toggleAction(int $id): RedirectResponse
{
$user = $this->userRepository->find($id);
$user->toggleBlock();
Expand Down
8 changes: 7 additions & 1 deletion Controller/DeleteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(
FlashBagInterface $flashBag,
TranslatorInterface $translator,
Router $router,
$redirectRoute
string $redirectRoute
) {
$this->formFactory = $formFactory;
$this->handler = $handler;
Expand All @@ -49,6 +49,12 @@ public function __construct(
$this->redirectRoute = $redirectRoute;
}

/**
* @param Request $request
* @param BaseUser $user
*
* @return array|RedirectResponse
*/
public function deleteAction(Request $request, BaseUser $user)
{
$userDataTransferObject = BaseUserDataTransferObject::fromUser($user);
Expand Down
26 changes: 6 additions & 20 deletions Controller/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use SumoCoders\FrameworkMultiUserBundle\User\Interfaces\User;
use Symfony\Bundle\FrameworkBundle\Translation\Translator;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
Expand All @@ -31,12 +32,6 @@ final class LoginController
/** @var Translator */
private $translator;

/**
* @param EngineInterface $templating
* @param AuthenticationUtils $authenticationUtils
* @param FormAuthenticator $formAuthenticator
* @param TokenStorage $tokenStorage
*/
public function __construct(
EngineInterface $templating,
AuthenticationUtils $authenticationUtils,
Expand All @@ -51,7 +46,7 @@ public function __construct(
$this->translator = $translator;
}

public function loginAction()
public function loginAction(): Response
{
if ($this->tokenStorage->getToken()->getUser() instanceof User) {
return new RedirectResponse(
Expand All @@ -69,13 +64,9 @@ public function loginAction()
);
}

/**
* @param AuthenticationException|null $exception
*
* @return null|string
*/
private function getTranslatedErrorMessageFromAuthenticationException(AuthenticationException $exception = null)
{
private function getTranslatedErrorMessageFromAuthenticationException(
?AuthenticationException $exception = null
): ?string {
if ($exception === null) {
return null;
}
Expand All @@ -92,12 +83,7 @@ private function getTranslatedErrorMessageFromAuthenticationException(Authentica
}
}

/**
* @param string $messageString
*
* @return string
*/
private function translateValidatorMessage($messageString)
private function translateValidatorMessage(string $messageString): string
{
return $this->translator->trans(
$messageString,
Expand Down
11 changes: 1 addition & 10 deletions Controller/PasswordResetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,6 @@ class PasswordResetController
/** @var FlashBagInterface */
private $flashBag;

/**
* @param BaseUserRepositoryCollection $userRepositoryCollection
* @param ResetPasswordHandler $resetPasswordHandler
* @param Router $router
* @param FormFactoryInterface $formFactory
* @param EngineInterface $templating
* @param Translator $translator
* @param FlashBagInterface $flashBag
*/
public function __construct(
BaseUserRepositoryCollection $userRepositoryCollection,
ResetPasswordHandler $resetPasswordHandler,
Expand All @@ -74,7 +65,7 @@ public function __construct(
*
* @return RedirectResponse
*/
public function resetAction(Request $request, PasswordResetToken $token)
public function resetAction(Request $request, PasswordResetToken $token): RedirectResponse
{
$user = $this->userRepositoryCollection->findUserByToken($token);

Expand Down
15 changes: 1 addition & 14 deletions Controller/RequestPasswordResetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ final class RequestPasswordResetController
/** @var FlashBagInterface */
private $flashBag;

/**
* @param EngineInterface $templating
* @param FormFactoryInterface $formFactory
* @param RequestPasswordResetHandler $requestPasswordResetHandler
* @param Router $router
* @param Translator $translator
* @param FlashBagInterface $flashBag
*/
public function __construct(
EngineInterface $templating,
FormFactoryInterface $formFactory,
Expand All @@ -58,12 +50,7 @@ public function __construct(
$this->flashBag = $flashBag;
}

/**
* @param Request $request
*
* @return array|RedirectResponse|Response
*/
public function requestAction(Request $request)
public function requestAction(Request $request): Response
{
$form = $this->formFactory->create(RequestPasswordType::class);

Expand Down
Loading

0 comments on commit 0969a63

Please sign in to comment.