diff --git a/src/Extension/ReCaptcha/RequestMethod/Post.php b/src/Extension/ReCaptcha/RequestMethod/Post.php index 1d40e5e..dae3aa5 100644 --- a/src/Extension/ReCaptcha/RequestMethod/Post.php +++ b/src/Extension/ReCaptcha/RequestMethod/Post.php @@ -33,7 +33,7 @@ class Post implements RequestMethod * @param string $recaptchaVerifyServer * @param int|null $timeout */ - public function __construct($recaptchaVerifyServer, $timeout) + public function __construct(string $recaptchaVerifyServer, ?int $timeout) { $this->recaptchaVerifyUrl = ($recaptchaVerifyServer ?: 'https://www.google.com').'/recaptcha/api/siteverify'; $this->timeout = $timeout; @@ -47,7 +47,7 @@ public function __construct($recaptchaVerifyServer, $timeout) * * @return string Body of the reCAPTCHA response */ - public function submit(RequestParameters $params) + public function submit(RequestParameters $params): string { $cacheKey = $params->toQueryString(); if (isset($this->cache[$cacheKey])) { diff --git a/src/Extension/ReCaptcha/RequestMethod/ProxyPost.php b/src/Extension/ReCaptcha/RequestMethod/ProxyPost.php index 4352105..9c6013a 100644 --- a/src/Extension/ReCaptcha/RequestMethod/ProxyPost.php +++ b/src/Extension/ReCaptcha/RequestMethod/ProxyPost.php @@ -41,7 +41,7 @@ class ProxyPost implements RequestMethod * @param string $recaptchaVerifyServer * @param int|null $timeout */ - public function __construct(array $httpProxy, $recaptchaVerifyServer, $timeout) + public function __construct(array $httpProxy, string $recaptchaVerifyServer, ?int $timeout) { $this->httpProxy = $httpProxy; $this->recaptchaVerifyUrl = ($recaptchaVerifyServer ?: 'https://www.google.com').'/recaptcha/api/siteverify'; @@ -56,7 +56,7 @@ public function __construct(array $httpProxy, $recaptchaVerifyServer, $timeout) * * @return string Body of the reCAPTCHA response */ - public function submit(RequestParameters $params) + public function submit(RequestParameters $params): string { $cacheKey = $params->toQueryString(); if (isset($this->cache[$cacheKey])) { diff --git a/src/Locale/LocaleResolver.php b/src/Locale/LocaleResolver.php index 1a2c929..ede7097 100644 --- a/src/Locale/LocaleResolver.php +++ b/src/Locale/LocaleResolver.php @@ -23,7 +23,7 @@ final class LocaleResolver * @param bool $useLocaleFromRequest * @param RequestStack $requestStack */ - public function __construct($defaultLocale, $useLocaleFromRequest, RequestStack $requestStack) + public function __construct(string $defaultLocale, bool $useLocaleFromRequest, RequestStack $requestStack) { $this->defaultLocale = $defaultLocale; $this->useLocaleFromRequest = $useLocaleFromRequest; @@ -33,7 +33,7 @@ public function __construct($defaultLocale, $useLocaleFromRequest, RequestStack /** * @return string The resolved locale key, depending on configuration */ - public function resolve() + public function resolve(): string { return $this->useLocaleFromRequest ? $this->requestStack->getCurrentRequest()->getLocale() diff --git a/src/Validator/Constraints/IsTrue.php b/src/Validator/Constraints/IsTrue.php index 8207d0a..a45510b 100644 --- a/src/Validator/Constraints/IsTrue.php +++ b/src/Validator/Constraints/IsTrue.php @@ -25,7 +25,7 @@ public function getTargets() /** * {@inheritdoc} */ - public function validatedBy() + public function validatedBy(): string { return 'ewz_recaptcha.true'; } diff --git a/src/Validator/Constraints/IsTrueV3.php b/src/Validator/Constraints/IsTrueV3.php index a48e778..ff38428 100755 --- a/src/Validator/Constraints/IsTrueV3.php +++ b/src/Validator/Constraints/IsTrueV3.php @@ -11,7 +11,7 @@ class IsTrueV3 extends IsTrue /** * {@inheritdoc} */ - public function validatedBy() + public function validatedBy(): string { return 'ewz_recaptcha.v3.true'; } diff --git a/src/Validator/Constraints/IsTrueValidator.php b/src/Validator/Constraints/IsTrueValidator.php index 416702c..963329a 100755 --- a/src/Validator/Constraints/IsTrueValidator.php +++ b/src/Validator/Constraints/IsTrueValidator.php @@ -62,11 +62,11 @@ class IsTrueValidator extends ConstraintValidator * @param array $trustedRoles */ public function __construct( - $enabled, + bool $enabled, ReCaptcha $recaptcha, RequestStack $requestStack, - $verifyHost, - AuthorizationCheckerInterface $authorizationChecker = null, + bool $verifyHost, + ?AuthorizationCheckerInterface $authorizationChecker = null, array $trustedRoles = array()) { $this->enabled = $enabled; @@ -80,7 +80,7 @@ public function __construct( /** * {@inheritdoc} */ - public function validate($value, Constraint $constraint) + public function validate($value, Constraint $constraint): void { // if recaptcha is disabled, always valid if (!$this->enabled) { diff --git a/src/Validator/Constraints/IsTrueValidatorV3.php b/src/Validator/Constraints/IsTrueValidatorV3.php index a095433..05f6c78 100755 --- a/src/Validator/Constraints/IsTrueValidatorV3.php +++ b/src/Validator/Constraints/IsTrueValidatorV3.php @@ -55,7 +55,7 @@ public function __construct( * @param mixed $value * @param Constraint $constraint */ - public function validate($value, Constraint $constraint) + public function validate($value, Constraint $constraint): void { if (!$this->enabled) { return; @@ -85,7 +85,7 @@ public function validate($value, Constraint $constraint) * * @return bool */ - private function isTokenValid($token) + private function isTokenValid(string $token): bool { try { $remoteIp = $this->requestStack->getCurrentRequest()->getClientIp(); @@ -99,7 +99,7 @@ private function isTokenValid($token) ->verify($token, $remoteIp); return $response->isSuccess(); - } catch (\Exception $exception) { + } catch (\Throwable $exception) { $this->logger->error( 'reCAPTCHA validator error: '.$exception->getMessage(), [ diff --git a/tests/Locale/LocaleResolverTest.php b/tests/Locale/LocaleResolverTest.php index 4f2b64b..341c5bf 100644 --- a/tests/Locale/LocaleResolverTest.php +++ b/tests/Locale/LocaleResolverTest.php @@ -14,8 +14,9 @@ class LocaleResolverTest extends TestCase */ public function resolveWithLocaleFromRequest(): void { + $locale = 'locale'; $request = $this->createMock(Request::class); - $request->expects($this->once())->method('getLocale'); + $request->expects($this->once())->method('getLocale')->willReturn($locale); $requestStack = $this->createMock(RequestStack::class); $requestStack @@ -24,7 +25,7 @@ public function resolveWithLocaleFromRequest(): void ->willReturn($request); $resolver = new LocaleResolver('foo', true, $requestStack); - $resolver->resolve(); + self::assertSame($locale, $resolver->resolve()); } /**