Skip to content
This repository was archived by the owner on Feb 25, 2026. It is now read-only.

Commit afa0e1d

Browse files
committed
Add types to classes that are BC.
1 parent 80730c4 commit afa0e1d

8 files changed

Lines changed: 18 additions & 17 deletions

File tree

src/Extension/ReCaptcha/RequestMethod/Post.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Post implements RequestMethod
3333
* @param string $recaptchaVerifyServer
3434
* @param int|null $timeout
3535
*/
36-
public function __construct($recaptchaVerifyServer, $timeout)
36+
public function __construct(string $recaptchaVerifyServer, ?int $timeout)
3737
{
3838
$this->recaptchaVerifyUrl = ($recaptchaVerifyServer ?: 'https://www.google.com').'/recaptcha/api/siteverify';
3939
$this->timeout = $timeout;
@@ -47,7 +47,7 @@ public function __construct($recaptchaVerifyServer, $timeout)
4747
*
4848
* @return string Body of the reCAPTCHA response
4949
*/
50-
public function submit(RequestParameters $params)
50+
public function submit(RequestParameters $params): string
5151
{
5252
$cacheKey = $params->toQueryString();
5353
if (isset($this->cache[$cacheKey])) {

src/Extension/ReCaptcha/RequestMethod/ProxyPost.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ProxyPost implements RequestMethod
4141
* @param string $recaptchaVerifyServer
4242
* @param int|null $timeout
4343
*/
44-
public function __construct(array $httpProxy, $recaptchaVerifyServer, $timeout)
44+
public function __construct(array $httpProxy, string $recaptchaVerifyServer, ?int $timeout)
4545
{
4646
$this->httpProxy = $httpProxy;
4747
$this->recaptchaVerifyUrl = ($recaptchaVerifyServer ?: 'https://www.google.com').'/recaptcha/api/siteverify';
@@ -56,7 +56,7 @@ public function __construct(array $httpProxy, $recaptchaVerifyServer, $timeout)
5656
*
5757
* @return string Body of the reCAPTCHA response
5858
*/
59-
public function submit(RequestParameters $params)
59+
public function submit(RequestParameters $params): string
6060
{
6161
$cacheKey = $params->toQueryString();
6262
if (isset($this->cache[$cacheKey])) {

src/Locale/LocaleResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class LocaleResolver
2323
* @param bool $useLocaleFromRequest
2424
* @param RequestStack $requestStack
2525
*/
26-
public function __construct($defaultLocale, $useLocaleFromRequest, RequestStack $requestStack)
26+
public function __construct(string $defaultLocale, bool $useLocaleFromRequest, RequestStack $requestStack)
2727
{
2828
$this->defaultLocale = $defaultLocale;
2929
$this->useLocaleFromRequest = $useLocaleFromRequest;
@@ -33,7 +33,7 @@ public function __construct($defaultLocale, $useLocaleFromRequest, RequestStack
3333
/**
3434
* @return string The resolved locale key, depending on configuration
3535
*/
36-
public function resolve()
36+
public function resolve(): string
3737
{
3838
return $this->useLocaleFromRequest
3939
? $this->requestStack->getCurrentRequest()->getLocale()

src/Validator/Constraints/IsTrue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function getTargets()
2525
/**
2626
* {@inheritdoc}
2727
*/
28-
public function validatedBy()
28+
public function validatedBy(): string
2929
{
3030
return 'ewz_recaptcha.true';
3131
}

src/Validator/Constraints/IsTrueV3.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class IsTrueV3 extends IsTrue
1111
/**
1212
* {@inheritdoc}
1313
*/
14-
public function validatedBy()
14+
public function validatedBy(): string
1515
{
1616
return 'ewz_recaptcha.v3.true';
1717
}

src/Validator/Constraints/IsTrueValidator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ class IsTrueValidator extends ConstraintValidator
6262
* @param array $trustedRoles
6363
*/
6464
public function __construct(
65-
$enabled,
65+
bool $enabled,
6666
ReCaptcha $recaptcha,
6767
RequestStack $requestStack,
68-
$verifyHost,
69-
AuthorizationCheckerInterface $authorizationChecker = null,
68+
bool $verifyHost,
69+
?AuthorizationCheckerInterface $authorizationChecker = null,
7070
array $trustedRoles = array())
7171
{
7272
$this->enabled = $enabled;
@@ -80,7 +80,7 @@ public function __construct(
8080
/**
8181
* {@inheritdoc}
8282
*/
83-
public function validate($value, Constraint $constraint)
83+
public function validate($value, Constraint $constraint): void
8484
{
8585
// if recaptcha is disabled, always valid
8686
if (!$this->enabled) {

src/Validator/Constraints/IsTrueValidatorV3.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function __construct(
5555
* @param mixed $value
5656
* @param Constraint $constraint
5757
*/
58-
public function validate($value, Constraint $constraint)
58+
public function validate($value, Constraint $constraint): void
5959
{
6060
if (!$this->enabled) {
6161
return;
@@ -85,7 +85,7 @@ public function validate($value, Constraint $constraint)
8585
*
8686
* @return bool
8787
*/
88-
private function isTokenValid($token)
88+
private function isTokenValid(string $token): bool
8989
{
9090
try {
9191
$remoteIp = $this->requestStack->getCurrentRequest()->getClientIp();
@@ -99,7 +99,7 @@ private function isTokenValid($token)
9999
->verify($token, $remoteIp);
100100

101101
return $response->isSuccess();
102-
} catch (\Exception $exception) {
102+
} catch (\Throwable $exception) {
103103
$this->logger->error(
104104
'reCAPTCHA validator error: '.$exception->getMessage(),
105105
[

tests/Locale/LocaleResolverTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ class LocaleResolverTest extends TestCase
1414
*/
1515
public function resolveWithLocaleFromRequest(): void
1616
{
17+
$locale = 'locale';
1718
$request = $this->createMock(Request::class);
18-
$request->expects($this->once())->method('getLocale');
19+
$request->expects($this->once())->method('getLocale')->willReturn($locale);
1920

2021
$requestStack = $this->createMock(RequestStack::class);
2122
$requestStack
@@ -24,7 +25,7 @@ public function resolveWithLocaleFromRequest(): void
2425
->willReturn($request);
2526

2627
$resolver = new LocaleResolver('foo', true, $requestStack);
27-
$resolver->resolve();
28+
self::assertSame($locale, $resolver->resolve());
2829
}
2930

3031
/**

0 commit comments

Comments
 (0)