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

Commit ee1ba4b

Browse files
committed
Small code cleanup
1 parent 730702d commit ee1ba4b

9 files changed

Lines changed: 108 additions & 109 deletions

File tree

src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function getConfigTreeBuilder()
3636
->scalarNode('api_host')->defaultValue('www.google.com')->end()
3737
->booleanNode('locale_from_request')->defaultFalse()->end()
3838
->integerNode('timeout')->min(0)->defaultNull()->end()
39-
->arrayNode('trusted_roles')->prototype('scalar')->treatNullLike(array())->end()
39+
->arrayNode('trusted_roles')->prototype('scalar')->treatNullLike(array())->end()
4040
->end()
4141
;
4242

src/DependencyInjection/EWZRecaptchaExtension.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace EWZ\Bundle\RecaptchaBundle\DependencyInjection;
44

5-
use Symfony\Component\DependencyInjection\ContainerBuilder;
65
use Symfony\Component\Config\FileLocator;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
7+
use Symfony\Component\DependencyInjection\Loader;
78
use Symfony\Component\DependencyInjection\Reference;
89
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
9-
use Symfony\Component\DependencyInjection\Loader;
1010

1111
/**
1212
* This is the class that loads and manages your bundle configuration.
@@ -68,8 +68,9 @@ protected function registerWidget(ContainerBuilder $container)
6868

6969
private function getTwigFormResources(ContainerBuilder $container)
7070
{
71-
if (!$container->hasParameter('twig.form.resources'))
71+
if (!$container->hasParameter('twig.form.resources')) {
7272
return [];
73+
}
7374

7475
return $container->getParameter('twig.form.resources');
7576
}

src/Extension/ReCaptcha/RequestMethod/ProxyPost.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ProxyPost implements RequestMethod
3737
private $cache;
3838

3939
/**
40-
* Constructor
40+
* Constructor.
4141
*
4242
* @param array $httpProxy
4343
* @param string $recaptchaVerifyServer

src/Form/Type/EWZRecaptchaType.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
namespace EWZ\Bundle\RecaptchaBundle\Form\Type;
44

55
use EWZ\Bundle\RecaptchaBundle\Locale\LocaleResolver;
6+
use Symfony\Component\Form\AbstractType;
67
use Symfony\Component\Form\Extension\Core\Type\TextType;
78
use Symfony\Component\Form\FormInterface;
89
use Symfony\Component\Form\FormView;
9-
use Symfony\Component\Form\AbstractType;
1010
use Symfony\Component\OptionsResolver\OptionsResolver;
1111

1212
/**
@@ -16,14 +16,14 @@ class EWZRecaptchaType extends AbstractType
1616
{
1717
/**
1818
* The reCAPTCHA server URL.
19-
*
19+
*
2020
* @var string
2121
*/
2222
protected $recaptchaApiServer;
23-
23+
2424
/**
2525
* The reCAPTCHA JS server URL.
26-
*
26+
*
2727
* @var string
2828
*/
2929
protected $recaptchaApiJsServer;
@@ -86,7 +86,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
8686
$view->vars = array_replace($view->vars, array(
8787
'ewz_recaptcha_enabled' => $this->enabled,
8888
'ewz_recaptcha_ajax' => $this->ajax,
89-
'ewz_recaptcha_apihost' => $this->apiHost
89+
'ewz_recaptcha_apihost' => $this->apiHost,
9090
));
9191

9292
if (!$this->enabled) {

src/Resources/views/Form/ewz_recaptcha_widget.html.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php if ($ewz_recaptcha_enabled): ?>
22
<?php if (!$ewz_recaptcha_ajax): ?>
3-
<?php if ($attr['options']['size'] == 'invisible' && !isset($attr['options']['callback'])): ?>
4-
<?php $attr['options']['callback'] = 'onReCaptchaSuccess' ?>
3+
<?php if ('invisible' == $attr['options']['size'] && !isset($attr['options']['callback'])): ?>
4+
<?php $attr['options']['callback'] = 'onReCaptchaSuccess'; ?>
55

66
<script>
77
var onReCaptchaSuccess = function() {
@@ -26,23 +26,23 @@
2626
}
2727
};
2828
</script>
29-
<?php endif ?>
29+
<?php endif; ?>
3030

31-
<script src="<?php echo $url_challenge ?>"
32-
<?php if (isset($attr['options']['defer']) && $attr['options']['defer']): ?> defer<?php endif ?>
33-
<?php if (isset($attr['options']['async']) && $attr['options']['async']): ?> async<?php endif ?>
31+
<script src="<?php echo $url_challenge; ?>"
32+
<?php if (isset($attr['options']['defer']) && $attr['options']['defer']): ?> defer<?php endif; ?>
33+
<?php if (isset($attr['options']['async']) && $attr['options']['async']): ?> async<?php endif; ?>
3434
></script>
35-
<div class="g-recaptcha" data-theme="<?php echo $attr['options']['theme'] ?>" data-size="<?php echo $attr['options']['size'] ?>" data-type="<?php echo $attr['options']['type'] ?>" data-sitekey="<?php echo $public_key ?>"
36-
<?php if (isset($attr['options']['callback'])): ?>data-callback="<?php echo $attr['options']['callback'] ?>"<?php endif ?>
37-
<?php if (isset($attr['options']['expiredCallback'])): ?>data-expired-callback="<?php echo $attr['options']['expiredCallback'] ?>"<?php endif ?>
38-
<?php if (isset($attr['options']['bind'])): ?>data-bind="<?php echo $attr['options']['bind'] ?>"<?php endif ?>
39-
<?php if (isset($attr['options']['badge'])): ?>data-badge="<?php echo $attr['options']['badge'] ?>"<?php endif ?>
35+
<div class="g-recaptcha" data-theme="<?php echo $attr['options']['theme']; ?>" data-size="<?php echo $attr['options']['size']; ?>" data-type="<?php echo $attr['options']['type']; ?>" data-sitekey="<?php echo $public_key; ?>"
36+
<?php if (isset($attr['options']['callback'])): ?>data-callback="<?php echo $attr['options']['callback']; ?>"<?php endif; ?>
37+
<?php if (isset($attr['options']['expiredCallback'])): ?>data-expired-callback="<?php echo $attr['options']['expiredCallback']; ?>"<?php endif; ?>
38+
<?php if (isset($attr['options']['bind'])): ?>data-bind="<?php echo $attr['options']['bind']; ?>"<?php endif; ?>
39+
<?php if (isset($attr['options']['badge'])): ?>data-badge="<?php echo $attr['options']['badge']; ?>"<?php endif; ?>
4040
></div>
4141
<noscript>
4242
<div style="width: 302px; height: 352px;">
4343
<div style="width: 302px; height: 352px; position: relative;">
4444
<div style="width: 302px; height: 352px; position: absolute;">
45-
<iframe src="https://<?php echo $ewz_recaptcha_apihost ?>/recaptcha/api/fallback?k=<?php echo $public_key ?>"
45+
<iframe src="https://<?php echo $ewz_recaptcha_apihost; ?>/recaptcha/api/fallback?k=<?php echo $public_key; ?>"
4646
style="width: 302px; height:352px; border-style: none; overflow: hidden;"
4747
>
4848
</iframe>
@@ -65,13 +65,13 @@ class="g-recaptcha-response"
6565
var script = document.createElement('script');
6666
script.type = 'text/javascript';
6767
script.onload = function() {
68-
Recaptcha.create('<?php echo $public_key ?>', 'ewz_recaptcha_div', <?php echo json_encode($attr['options']) ?>);
68+
Recaptcha.create('<?php echo $public_key; ?>', 'ewz_recaptcha_div', <?php echo json_encode($attr['options']); ?>);
6969
};
70-
script.src = '<?php echo $url_api ?>';
71-
<?php if (isset($attr['options']['defer']) && $attr['options']['defer']): ?>script.defer = true;<?php endif ?>
72-
<?php if (isset($attr['options']['async']) && $attr['options']['async']): ?>script.async = true;<?php endif ?>
70+
script.src = '<?php echo $url_api; ?>';
71+
<?php if (isset($attr['options']['defer']) && $attr['options']['defer']): ?>script.defer = true;<?php endif; ?>
72+
<?php if (isset($attr['options']['async']) && $attr['options']['async']): ?>script.async = true;<?php endif; ?>
7373
document.getElementsByTagName('head')[0].appendChild(script);
7474
})();
7575
</script>
76-
<?php endif ?>
77-
<?php endif ?>
76+
<?php endif; ?>
77+
<?php endif; ?>
Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,84 @@
11
{% block ewz_recaptcha_widget %}
22
{% apply spaceless %}
3-
{% if form.vars.ewz_recaptcha_enabled %}
4-
{% if not form.vars.ewz_recaptcha_ajax %}
5-
{% if attr.options.size == 'invisible' and attr.options.callback is not defined %}
6-
{% set options = attr.options|merge({'callback': 'onReCaptchaSuccess'}) %}
7-
{% set attr = attr|merge({'options': options}) %}
3+
{% if form.vars.ewz_recaptcha_enabled %}
4+
{% if not form.vars.ewz_recaptcha_ajax %}
5+
{% if attr.options.size == 'invisible' and attr.options.callback is not defined %}
6+
{% set options = attr.options|merge({'callback': 'onReCaptchaSuccess'}) %}
7+
{% set attr = attr|merge({'options': options}) %}
88

9-
<script>
10-
var onReCaptchaSuccess = function() {
11-
var errorDivs = document.getElementsByClassName('recaptcha-error');
12-
if (errorDivs.length) {
13-
errorDivs[0].className = '';
14-
}
9+
<script>
10+
var onReCaptchaSuccess = function() {
11+
var errorDivs = document.getElementsByClassName('recaptcha-error');
12+
if (errorDivs.length) {
13+
errorDivs[0].className = '';
14+
}
1515
16-
var errorMsgs = document.getElementsByClassName('recaptcha-error-message');
17-
if (errorMsgs.length) {
18-
errorMsgs[0].parentNode.removeChild(errorMsgs[0]);
19-
}
16+
var errorMsgs = document.getElementsByClassName('recaptcha-error-message');
17+
if (errorMsgs.length) {
18+
errorMsgs[0].parentNode.removeChild(errorMsgs[0]);
19+
}
2020
21-
var forms = document.getElementsByClassName('recaptcha-form');
22-
if (forms.length) {
23-
var recaptchaSubmitEvent = document.createEvent('Event');
24-
recaptchaSubmitEvent.initEvent('submit', true, true);
25-
forms[0].addEventListener('submit', function (e) {
26-
e.target.submit();
27-
}, false);
28-
forms[0].dispatchEvent(recaptchaSubmitEvent);
29-
}
30-
};
31-
</script>
32-
{% endif %}
21+
var forms = document.getElementsByClassName('recaptcha-form');
22+
if (forms.length) {
23+
var recaptchaSubmitEvent = document.createEvent('Event');
24+
recaptchaSubmitEvent.initEvent('submit', true, true);
25+
forms[0].addEventListener('submit', function (e) {
26+
e.target.submit();
27+
}, false);
28+
forms[0].dispatchEvent(recaptchaSubmitEvent);
29+
}
30+
};
31+
</script>
32+
{% endif %}
3333

34-
<script src="{{ form.vars.url_challenge }}"
35-
{%- if attr.options.defer is defined and attr.options.defer %} defer{% endif -%}
36-
{%- if attr.options.async is defined and attr.options.async %} async{% endif -%}
37-
></script>
38-
<div class="g-recaptcha" data-theme="{{ attr.options.theme }}" data-size="{{ attr.options.size }}" data-type="{{ attr.options.type }}" data-sitekey="{{ form.vars.public_key }}"
39-
{%- if attr.options.callback is defined %} data-callback="{{ attr.options.callback }}"{% endif -%}
40-
{%- if attr.options.errorCallback is defined %} data-error-callback="{{ attr.options.errorCallback }}"{% endif -%}
41-
{%- if attr.options.expiredCallback is defined %} data-expired-callback="{{ attr.options.expiredCallback }}"{% endif -%}
42-
{%- if attr.options.bind is defined %} data-bind="{{ attr.options.bind }}"{% endif -%}
43-
{%- if attr.options.badge is defined %} data-badge="{{ attr.options.badge }}"{% endif -%}
44-
></div>
45-
<noscript>
46-
<div style="width: 302px; height: 352px;">
47-
<div style="width: 302px; height: 352px; position: relative;">
48-
<div style="width: 302px; height: 352px; position: absolute;">
49-
<iframe src="https://{{ form.vars.ewz_recaptcha_apihost }}/recaptcha/api/fallback?k={{ form.vars.public_key }}"
50-
style="width: 302px; height:352px; border-style: none; overflow: hidden;"
51-
>
52-
</iframe>
53-
</div>
54-
<div style="width: 250px; height: 80px; position: absolute; border-style: none; bottom: 21px; left: 25px; margin: 0; padding: 0; right: 25px;">
55-
<textarea id="g-recaptcha-response" name="g-recaptcha-response"
56-
class="g-recaptcha-response"
57-
style="width: 250px; height: 80px; border: 1px solid #c1c1c1; margin: 0; padding: 0; resize: none;"
58-
>
59-
</textarea>
60-
</div>
61-
</div>
62-
</div>
63-
</noscript>
64-
{% else %}
65-
<div id="ewz_recaptcha_div"></div>
34+
<script src="{{ form.vars.url_challenge }}"
35+
{%- if attr.options.defer is defined and attr.options.defer %} defer{% endif -%}
36+
{%- if attr.options.async is defined and attr.options.async %} async{% endif -%}
37+
></script>
38+
<div class="g-recaptcha" data-theme="{{ attr.options.theme }}" data-size="{{ attr.options.size }}" data-type="{{ attr.options.type }}" data-sitekey="{{ form.vars.public_key }}"
39+
{%- if attr.options.callback is defined %} data-callback="{{ attr.options.callback }}"{% endif -%}
40+
{%- if attr.options.errorCallback is defined %} data-error-callback="{{ attr.options.errorCallback }}"{% endif -%}
41+
{%- if attr.options.expiredCallback is defined %} data-expired-callback="{{ attr.options.expiredCallback }}"{% endif -%}
42+
{%- if attr.options.bind is defined %} data-bind="{{ attr.options.bind }}"{% endif -%}
43+
{%- if attr.options.badge is defined %} data-badge="{{ attr.options.badge }}"{% endif -%}
44+
></div>
45+
<noscript>
46+
<div style="width: 302px; height: 352px;">
47+
<div style="width: 302px; height: 352px; position: relative;">
48+
<div style="width: 302px; height: 352px; position: absolute;">
49+
<iframe src="https://{{ form.vars.ewz_recaptcha_apihost }}/recaptcha/api/fallback?k={{ form.vars.public_key }}"
50+
style="width: 302px; height:352px; border-style: none; overflow: hidden;"
51+
>
52+
</iframe>
53+
</div>
54+
<div style="width: 250px; height: 80px; position: absolute; border-style: none; bottom: 21px; left: 25px; margin: 0; padding: 0; right: 25px;">
55+
<textarea id="g-recaptcha-response" name="g-recaptcha-response"
56+
class="g-recaptcha-response"
57+
style="width: 250px; height: 80px; border: 1px solid #c1c1c1; margin: 0; padding: 0; resize: none;"
58+
>
59+
</textarea>
60+
</div>
61+
</div>
62+
</div>
63+
</noscript>
64+
{% else %}
65+
<div id="ewz_recaptcha_div"></div>
6666

67-
<script>
68-
(function() {
69-
var script = document.createElement('script');
70-
script.type = 'text/javascript';
71-
script.onload = function() {
72-
Recaptcha.create('{{ form.vars.public_key }}', 'ewz_recaptcha_div', {{ attr.options|default({})|json_encode|raw }});
73-
};
74-
script.src = '{{ form.vars.url_api }}';
75-
{% if attr.options.defer is defined and attr.options.defer %}script.defer = true;{% endif %}
76-
{% if attr.options.async is defined and attr.options.async %}script.async = true;{% endif %}
77-
document.getElementsByTagName('head')[0].appendChild(script);
78-
})();
79-
</script>
80-
{% endif %}
67+
<script>
68+
(function() {
69+
var script = document.createElement('script');
70+
script.type = 'text/javascript';
71+
script.onload = function() {
72+
Recaptcha.create('{{ form.vars.public_key }}', 'ewz_recaptcha_div', {{ attr.options|default({})|json_encode|raw }});
73+
};
74+
script.src = '{{ form.vars.url_api }}';
75+
{% if attr.options.defer is defined and attr.options.defer %}script.defer = true;{% endif %}
76+
{% if attr.options.async is defined and attr.options.async %}script.async = true;{% endif %}
77+
document.getElementsByTagName('head')[0].appendChild(script);
78+
})();
79+
</script>
8180
{% endif %}
81+
{% endif %}
8282
{% endapply %}
8383
{% endblock ewz_recaptcha_widget %}
8484

src/Validator/Constraints/IsTrueValidator.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace EWZ\Bundle\RecaptchaBundle\Validator\Constraints;
44

5-
use EWZ\Bundle\RecaptchaBundle\Extension\ReCaptcha\RequestMethod\Post;
6-
use EWZ\Bundle\RecaptchaBundle\Extension\ReCaptcha\RequestMethod\ProxyPost;
75
use ReCaptcha\ReCaptcha;
86
use Symfony\Component\HttpFoundation\RequestStack;
97
use Symfony\Component\Security\Core\Authorization\AuthorizationChecker;
@@ -42,14 +40,14 @@ class IsTrueValidator extends ConstraintValidator
4240
protected $verifyHost;
4341

4442
/**
45-
* Authorization Checker
43+
* Authorization Checker.
4644
*
4745
* @var AuthorizationChecker
4846
*/
4947
protected $authorizationChecker;
5048

5149
/**
52-
* Trusted Roles
50+
* Trusted Roles.
5351
*
5452
* @var array
5553
*/

tests/DependencyInjection/EWZRecaptchaExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,6 @@ private function assertDefinitionHasReferenceArgument($id, $index, $expectedArgu
146146
$argumentValue = $definition->getArgument($index);
147147

148148
$this->assertInstanceOf(Reference::class, $argumentValue);
149-
$this->assertSame($expectedArgumentValue, (string)$argumentValue);
149+
$this->assertSame($expectedArgumentValue, (string) $argumentValue);
150150
}
151151
}

tests/bootstrap.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
date_default_timezone_set('UTC');
55

66
// Ensure that composer has installed all dependencies
7-
if (!file_exists(dirname(__DIR__) . '/composer.lock')) {
7+
if (!file_exists(dirname(__DIR__).'/composer.lock')) {
88
die("Dependencies must be installed using composer:\n\nphp composer.phar install\n\n"
9-
. "See http://getcomposer.org for help with installing composer\n");
9+
."See http://getcomposer.org for help with installing composer\n");
1010
}
1111

1212
// Include the composer autoloader
13-
$loader = require dirname(__DIR__) . '/vendor/autoload.php';
13+
$loader = require dirname(__DIR__).'/vendor/autoload.php';

0 commit comments

Comments
 (0)