Skip to content

Commit

Permalink
Merge pull request #281 from biozshock/symfony6
Browse files Browse the repository at this point in the history
Symfony6
  • Loading branch information
excelwebzone committed Jan 11, 2022
2 parents c7e375a + afa0e1d commit f5fbc9e
Show file tree
Hide file tree
Showing 20 changed files with 455 additions and 68 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/build.yml
Expand Up @@ -14,13 +14,21 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [7.1, 7.2, 7.3, 7.4, 8.0]
symfony: [2.8, 3.4, 4.4, 5.2]
php: [7.1, 7.2, 7.3, 7.4, 8.0, 8.1]
symfony: [2.8, 3.4, 4.4, 5.2, 6.0]
exclude:
- php: 7.1
symfony: 5.2
- php: 8.0
symfony: 3.4
- php: 7.1
symfony: 6.0
- php: 7.2
symfony: 6.0
- php: 7.3
symfony: 6.0
- php: 7.4
symfony: 6.0
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Expand Up @@ -17,15 +17,15 @@
"require": {
"php": "^7.1 || ^8.0",
"google/recaptcha": "^1.1",
"symfony/form": "^2.8 || ^3.0 || ^4.0 || ^5.0",
"symfony/framework-bundle": "^2.8 || ^3.0 || ^4.0 || ^5.0",
"symfony/security-bundle": "^2.8 || ^3.0 || ^4.0 || ^5.0",
"symfony/validator": "^2.8 || ^3.0 || ^4.0 || ^5.0",
"symfony/yaml": "^2.8 || ^3.0 || ^4.0 || ^5.0",
"symfony/form": "^2.8 || ^3.0 || ^4.0 || ^5.0 || ^6.0",
"symfony/framework-bundle": "^2.8 || ^3.0 || ^4.0 || ^5.0 || ^6.0",
"symfony/security-bundle": "^2.8 || ^3.0 || ^4.0 || ^5.0 || ^6.0",
"symfony/validator": "^2.8 || ^3.0 || ^4.0 || ^5.0 || ^6.0",
"symfony/yaml": "^2.8 || ^3.0 || ^4.0 || ^5.0 || ^6.0",
"twig/twig": "^1.40 || ^2.9 || ^3.0"
},
"require-dev": {
"phpunit/phpunit": "^7 || ^8"
"phpunit/phpunit": "^7 || ^8 || ^9.5"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Expand Up @@ -14,7 +14,7 @@ class Configuration implements ConfigurationInterface
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('ewz_recaptcha');

Expand Down
10 changes: 5 additions & 5 deletions src/DependencyInjection/EWZRecaptchaExtension.php
Expand Up @@ -19,7 +19,7 @@ class EWZRecaptchaExtension extends Extension
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
Expand All @@ -38,7 +38,7 @@ public function load(array $configs, ContainerBuilder $container)
$recaptchaService->replaceArgument(1, new Reference('ewz_recaptcha.extension.recaptcha.request_method.proxy_post'));
}

if (3 == $config['version']) {
if (3 === $config['version']) {
$container->register('ewz_recaptcha.form_builder_factory', EWZRecaptchaV3FormBuilderFactory::class)
->addArgument(new Reference('form.factory'));
} else {
Expand All @@ -61,13 +61,13 @@ public function load(array $configs, ContainerBuilder $container)
*
* @param ContainerBuilder $container
*/
protected function registerWidget(ContainerBuilder $container, $version = 2)
protected function registerWidget(ContainerBuilder $container, int $version = 2): void
{
$templatingEngines = $container->hasParameter('templating.engines')
? $container->getParameter('templating.engines')
: array('twig');

if (in_array('php', $templatingEngines)) {
if (in_array('php', $templatingEngines, true)) {
$formResource = 'EWZRecaptchaBundle:Form';

$container->setParameter('templating.helper.form.resources', array_merge(
Expand All @@ -76,7 +76,7 @@ protected function registerWidget(ContainerBuilder $container, $version = 2)
));
}

if (in_array('twig', $templatingEngines)) {
if (in_array('twig', $templatingEngines, true)) {
$formResource = '@EWZRecaptcha/Form/ewz_recaptcha_widget.html.twig';
if (3 === $version) {
$formResource = '@EWZRecaptcha/Form/v3/ewz_recaptcha_widget.html.twig';
Expand Down
4 changes: 2 additions & 2 deletions src/Extension/ReCaptcha/RequestMethod/Post.php
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
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
14 changes: 7 additions & 7 deletions src/Form/Type/AbstractEWZRecaptchaType.php
Expand Up @@ -38,10 +38,10 @@ abstract class AbstractEWZRecaptchaType extends AbstractType

/**
* @param string $publicKey Recaptcha public key
* @param bool $enabled Recaptcha status
* @param bool $enabled Recaptcha status
* @param string $apiHost Api host
*/
public function __construct($publicKey, $enabled, $apiHost = 'www.google.com')
public function __construct(string $publicKey, bool $enabled, string $apiHost = 'www.google.com')
{
$this->publicKey = $publicKey;
$this->enabled = $enabled;
Expand All @@ -52,7 +52,7 @@ public function __construct($publicKey, $enabled, $apiHost = 'www.google.com')
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options)
public function buildView(FormView $view, FormInterface $form, array $options): void
{
$view->vars = array_replace($view->vars, array(
'ewz_recaptcha_enabled' => $this->enabled,
Expand All @@ -71,7 +71,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
public function getBlockPrefix(): string
{
return 'ewz_recaptcha';
}
Expand All @@ -81,7 +81,7 @@ public function getBlockPrefix()
*
* @return string The javascript source URL
*/
public function getPublicKey()
public function getPublicKey(): string
{
return $this->publicKey;
}
Expand All @@ -91,10 +91,10 @@ public function getPublicKey()
*
* @return string The hostname for API
*/
public function getApiHost()
public function getApiHost(): string
{
return $this->apiHost;
}

abstract protected function addCustomVars(FormView $view, FormInterface $form, array $options);
abstract protected function addCustomVars(FormView $view, FormInterface $form, array $options): void;
}
8 changes: 4 additions & 4 deletions src/Form/Type/EWZRecaptchaType.php
Expand Up @@ -29,7 +29,7 @@ class EWZRecaptchaType extends AbstractEWZRecaptchaType
* @param bool $ajax Ajax status
* @param LocaleResolver $localeResolver
*/
public function __construct($publicKey, $enabled, $ajax, LocaleResolver $localeResolver, $apiHost = 'www.google.com')
public function __construct(string $publicKey, bool $enabled, bool $ajax, LocaleResolver $localeResolver, string $apiHost = 'www.google.com')
{
parent::__construct($publicKey, $enabled, $apiHost);

Expand All @@ -40,7 +40,7 @@ public function __construct($publicKey, $enabled, $ajax, LocaleResolver $localeR
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults(array(
'compound' => false,
Expand All @@ -67,7 +67,7 @@ public function configureOptions(OptionsResolver $resolver)
/**
* {@inheritdoc}
*/
public function getParent()
public function getParent(): string
{
return TextType::class;
}
Expand All @@ -87,7 +87,7 @@ public function getScriptURL($key)
/**
* {@inheritdoc}
*/
protected function addCustomVars(FormView $view, FormInterface $form, array $options)
protected function addCustomVars(FormView $view, FormInterface $form, array $options): void
{
$view->vars = array_replace($view->vars, array(
'ewz_recaptcha_ajax' => $this->ajax,
Expand Down
14 changes: 7 additions & 7 deletions src/Form/Type/EWZRecaptchaV3Type.php
Expand Up @@ -18,11 +18,11 @@ class EWZRecaptchaV3Type extends AbstractEWZRecaptchaType
* EWZRecaptchaV3Type constructor.
*
* @param string $publicKey
* @param bool $enabled
* @param bool $enabled
* @param bool $hideBadge
* @param string $apiHost
*/
public function __construct($publicKey, $enabled, $hideBadge, $apiHost = 'www.google.com')
public function __construct(string $publicKey, bool $enabled, bool $hideBadge, string $apiHost = 'www.google.com')
{
parent::__construct($publicKey, $enabled, $apiHost);

Expand All @@ -32,7 +32,7 @@ public function __construct($publicKey, $enabled, $hideBadge, $apiHost = 'www.go
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'label' => false,
Expand All @@ -49,20 +49,20 @@ public function configureOptions(OptionsResolver $resolver)
/**
* {@inheritdoc}
*/
public function getParent()
public function getParent(): string
{
return HiddenType::class;
}

/**
* {@inheritdoc}
*/
protected function addCustomVars(FormView $view, FormInterface $form, array $options)
protected function addCustomVars(FormView $view, FormInterface $form, array $options): void
{
$view->vars = array_replace($view->vars, [
'ewz_recaptcha_hide_badge' => $this->hideBadge,
'script_nonce_csp' => isset($options['script_nonce_csp']) ? $options['script_nonce_csp'] : '',
'action_name' => isset($options['action_name']) ? $options['action_name'] : '',
'script_nonce_csp' => $options['script_nonce_csp'] ?? '',
'action_name' => $options['action_name'] ?? '',
]);
}
}
4 changes: 2 additions & 2 deletions src/Locale/LocaleResolver.php
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
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
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
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
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

0 comments on commit f5fbc9e

Please sign in to comment.