Skip to content

Commit

Permalink
Add types to classes that are BC.
Browse files Browse the repository at this point in the history
  • Loading branch information
biozshock committed Dec 22, 2021
1 parent 80730c4 commit afa0e1d
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/Extension/ReCaptcha/RequestMethod/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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])) {
Expand Down
4 changes: 2 additions & 2 deletions src/Extension/ReCaptcha/RequestMethod/ProxyPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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])) {
Expand Down
4 changes: 2 additions & 2 deletions src/Locale/LocaleResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/Validator/Constraints/IsTrue.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function getTargets()
/**
* {@inheritdoc}
*/
public function validatedBy()
public function validatedBy(): string
{
return 'ewz_recaptcha.true';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Validator/Constraints/IsTrueV3.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class IsTrueV3 extends IsTrue
/**
* {@inheritdoc}
*/
public function validatedBy()
public function validatedBy(): string
{
return 'ewz_recaptcha.v3.true';
}
Expand Down
8 changes: 4 additions & 4 deletions src/Validator/Constraints/IsTrueValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/Validator/Constraints/IsTrueValidatorV3.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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(),
[
Expand Down
5 changes: 3 additions & 2 deletions tests/Locale/LocaleResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,7 +25,7 @@ public function resolveWithLocaleFromRequest(): void
->willReturn($request);

$resolver = new LocaleResolver('foo', true, $requestStack);
$resolver->resolve();
self::assertSame($locale, $resolver->resolve());
}

/**
Expand Down

0 comments on commit afa0e1d

Please sign in to comment.