From 9be17b0e8b85c41c13d953f5a56dbf3e954e0568 Mon Sep 17 00:00:00 2001 From: Camille Simiand <camille.simiand@tetras-libre.fr> Date: Mon, 10 Jan 2022 11:57:16 +0100 Subject: [PATCH] Fix phpstan level 6 errors --- phpstan.neon | 3 ++- src/Builder/UserBuilder.php | 5 ++++- src/Controller/RegistrationController.php | 2 +- src/Controller/ResetPasswordController.php | 4 ++-- src/Curl/CurlHandle.php | 1 + src/Entity/User.php | 8 ++++++-- src/Helper/ContractHelper.php | 2 +- src/Repository/UserRepository.php | 2 +- src/Security/UserChecker.php | 4 ++-- 9 files changed, 20 insertions(+), 11 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 449e180..e56bade 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -5,4 +5,5 @@ parameters: symfony: container_xml_path: var/cache/dev/App_KernelDevDebugContainer.xml doctrine: - objectManagerLoader: tests/object-manager.php \ No newline at end of file + objectManagerLoader: tests/object-manager.php + checkGenericClassInNonGenericObjectType: false \ No newline at end of file diff --git a/src/Builder/UserBuilder.php b/src/Builder/UserBuilder.php index 86dd566..639effa 100644 --- a/src/Builder/UserBuilder.php +++ b/src/Builder/UserBuilder.php @@ -18,7 +18,7 @@ class UserBuilder private bool $hasRequiredRoles = false; private bool $hasRequiredIsVerified = false; - public function __construct($password_hasher) + public function __construct(UserPasswordHasherInterface $password_hasher) { $this->user = new User(); $this->password_hasher = $password_hasher; @@ -59,6 +59,9 @@ class UserBuilder return $this; } + /** + * @param array<string> $roles + */ public function withRoles(array $roles): UserBuilder { if (! in_array(['ROLE_USER'], $roles)) { diff --git a/src/Controller/RegistrationController.php b/src/Controller/RegistrationController.php index 4eedc13..e4f1245 100644 --- a/src/Controller/RegistrationController.php +++ b/src/Controller/RegistrationController.php @@ -122,7 +122,7 @@ class RegistrationController extends AbstractController /** * @Route("/register_mail_sent", name="app_register_mail_sent") */ - public function mailSentMessage(UserRepository $userRepository) + public function mailSentMessage(UserRepository $userRepository): Response { $userid = $this->requestStack->getSession()->get('userid'); $user = $userRepository->find($userid); diff --git a/src/Controller/ResetPasswordController.php b/src/Controller/ResetPasswordController.php index 1df4e65..4eb6d14 100644 --- a/src/Controller/ResetPasswordController.php +++ b/src/Controller/ResetPasswordController.php @@ -26,8 +26,8 @@ class ResetPasswordController extends AbstractController { use ResetPasswordControllerTrait; - private $resetPasswordHelper; - private $entityManager; + private ResetPasswordHelperInterface $resetPasswordHelper; + private EntityManagerInterface $entityManager; public function __construct( ResetPasswordHelperInterface $resetPasswordHelper, diff --git a/src/Curl/CurlHandle.php b/src/Curl/CurlHandle.php index f058c9c..23f57e1 100644 --- a/src/Curl/CurlHandle.php +++ b/src/Curl/CurlHandle.php @@ -20,6 +20,7 @@ class CurlHandle $this->curl_handler = $curl_init; } + /** @phpstan-ignore-next-line */ public function setOptions(array $options_array): void { curl_setopt_array($this->curl_handler, $options_array); diff --git a/src/Entity/User.php b/src/Entity/User.php index 2322bc6..1bbf9a3 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -63,7 +63,8 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface /** * @ORM\Column(type="json") */ - private $roles = []; + /** @phpstan-ignore-next-line */ + private array $roles = []; /** * @var string The hashed password @@ -130,6 +131,9 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface return array_unique($roles); } + /** + * @param array<string> $roles + */ public function setRoles(array $roles): self { $this->roles = $roles; @@ -166,7 +170,7 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface /** * @see UserInterface */ - public function eraseCredentials() + public function eraseCredentials(): void { // If you store any temporary, sensitive data on the user, clear it here // $this->plainPassword = null; diff --git a/src/Helper/ContractHelper.php b/src/Helper/ContractHelper.php index 0c3febc..2896df4 100644 --- a/src/Helper/ContractHelper.php +++ b/src/Helper/ContractHelper.php @@ -7,7 +7,7 @@ class ContractHelper /** * @throws \Exception if the predicate is not fulfilled an exception is thrown. */ - public static function requires(bool $predicate, string $errorMessage) + public static function requires(bool $predicate, string $errorMessage): void { if (! $predicate) { throw new \Exception($errorMessage); diff --git a/src/Repository/UserRepository.php b/src/Repository/UserRepository.php index 2104c06..d8d1231 100644 --- a/src/Repository/UserRepository.php +++ b/src/Repository/UserRepository.php @@ -38,7 +38,7 @@ class UserRepository extends ServiceEntityRepository implements PasswordUpgrader $this->_em->flush(); } - public function findOneByEmail($value): ?User + public function findOneByEmail(string $value): ?User { return $this->createQueryBuilder('u') ->andWhere('u.email = :val') diff --git a/src/Security/UserChecker.php b/src/Security/UserChecker.php index 36201e3..7e6f77c 100644 --- a/src/Security/UserChecker.php +++ b/src/Security/UserChecker.php @@ -18,11 +18,11 @@ class UserChecker implements UserCheckerInterface $this->translator = $translator; } - public function checkPreAuth(UserInterface $user) + public function checkPreAuth(UserInterface $user): void { } - public function checkPostAuth(UserInterface $user) + public function checkPostAuth(UserInterface $user): void { if (!$user instanceof User) { return; -- GitLab