From 80730c4f0e1163dbbabbbd5f44b240543ce948b8 Mon Sep 17 00:00:00 2001 From: Artem Lopata Date: Tue, 21 Dec 2021 22:46:40 +0100 Subject: [PATCH] Add types to classes that are not usually BC. --- src/DependencyInjection/Configuration.php | 2 +- src/DependencyInjection/EWZRecaptchaExtension.php | 10 +++++----- src/Form/Type/AbstractEWZRecaptchaType.php | 14 +++++++------- src/Form/Type/EWZRecaptchaType.php | 8 ++++---- src/Form/Type/EWZRecaptchaV3Type.php | 14 +++++++------- .../EWZRecaptchaExtensionTest.php | 14 +++++++------- tests/Form/Type/EWZRecaptchaTypeTest.php | 10 +++++----- tests/Form/Type/EWZRecaptchaV3TypeTest.php | 10 +++++----- tests/Locale/LocaleResolverTest.php | 4 ++-- 9 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index bfe3dfb..f5ecb03 100755 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -14,7 +14,7 @@ class Configuration implements ConfigurationInterface /** * {@inheritdoc} */ - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('ewz_recaptcha'); diff --git a/src/DependencyInjection/EWZRecaptchaExtension.php b/src/DependencyInjection/EWZRecaptchaExtension.php index 615e722..c1489ba 100755 --- a/src/DependencyInjection/EWZRecaptchaExtension.php +++ b/src/DependencyInjection/EWZRecaptchaExtension.php @@ -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); @@ -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 { @@ -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( @@ -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'; diff --git a/src/Form/Type/AbstractEWZRecaptchaType.php b/src/Form/Type/AbstractEWZRecaptchaType.php index db30945..c0ef48e 100755 --- a/src/Form/Type/AbstractEWZRecaptchaType.php +++ b/src/Form/Type/AbstractEWZRecaptchaType.php @@ -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; @@ -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, @@ -71,7 +71,7 @@ public function buildView(FormView $view, FormInterface $form, array $options) /** * {@inheritdoc} */ - public function getBlockPrefix() + public function getBlockPrefix(): string { return 'ewz_recaptcha'; } @@ -81,7 +81,7 @@ public function getBlockPrefix() * * @return string The javascript source URL */ - public function getPublicKey() + public function getPublicKey(): string { return $this->publicKey; } @@ -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; } diff --git a/src/Form/Type/EWZRecaptchaType.php b/src/Form/Type/EWZRecaptchaType.php index bfb4101..b5672d8 100755 --- a/src/Form/Type/EWZRecaptchaType.php +++ b/src/Form/Type/EWZRecaptchaType.php @@ -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); @@ -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, @@ -67,7 +67,7 @@ public function configureOptions(OptionsResolver $resolver) /** * {@inheritdoc} */ - public function getParent() + public function getParent(): string { return TextType::class; } @@ -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, diff --git a/src/Form/Type/EWZRecaptchaV3Type.php b/src/Form/Type/EWZRecaptchaV3Type.php index 39f109e..989a728 100755 --- a/src/Form/Type/EWZRecaptchaV3Type.php +++ b/src/Form/Type/EWZRecaptchaV3Type.php @@ -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); @@ -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, @@ -49,7 +49,7 @@ public function configureOptions(OptionsResolver $resolver) /** * {@inheritdoc} */ - public function getParent() + public function getParent(): string { return HiddenType::class; } @@ -57,12 +57,12 @@ public function getParent() /** * {@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'] ?? '', ]); } } diff --git a/tests/DependencyInjection/EWZRecaptchaExtensionTest.php b/tests/DependencyInjection/EWZRecaptchaExtensionTest.php index 049153f..b8be3ae 100755 --- a/tests/DependencyInjection/EWZRecaptchaExtensionTest.php +++ b/tests/DependencyInjection/EWZRecaptchaExtensionTest.php @@ -21,7 +21,7 @@ protected function tearDown(): void $this->configuration = null; } - public function testSimpleConfiguration() + public function testSimpleConfiguration(): void { $this->configuration = new ContainerBuilder(); $loader = new EWZRecaptchaExtension(); @@ -57,7 +57,7 @@ public function testSimpleConfiguration() ); } - public function testSimpleV3Configuration() + public function testSimpleV3Configuration(): void { $this->configuration = new ContainerBuilder(); $loader = new EWZRecaptchaExtension(); @@ -74,7 +74,7 @@ public function testSimpleV3Configuration() } - public function testFullConfiguration() + public function testFullConfiguration(): void { $this->configuration = new ContainerBuilder(); $loader = new EWZRecaptchaExtension(); @@ -145,22 +145,22 @@ private function getFullConfig() return $parser->parse($yaml); } - private function assertParameter($value, $key) + private function assertParameter($value, $key): void { $this->assertSame($value, $this->configuration->getParameter($key), sprintf('%s parameter is correct', $key)); } - private function assertHasDefinition($id) + private function assertHasDefinition($id): void { $this->assertTrue(($this->configuration->hasDefinition($id) ?: $this->configuration->hasAlias($id))); } - private function assertNotHasDefinition($id) + private function assertNotHasDefinition($id): void { $this->assertFalse(($this->configuration->hasDefinition($id) ?: $this->configuration->hasAlias($id))); } - private function assertDefinitionHasReferenceArgument($id, $index, $expectedArgumentValue) + private function assertDefinitionHasReferenceArgument($id, $index, $expectedArgumentValue): void { $definition = $this->configuration->getDefinition($id); $argumentValue = $definition->getArgument($index); diff --git a/tests/Form/Type/EWZRecaptchaTypeTest.php b/tests/Form/Type/EWZRecaptchaTypeTest.php index 894158b..30f4f2a 100644 --- a/tests/Form/Type/EWZRecaptchaTypeTest.php +++ b/tests/Form/Type/EWZRecaptchaTypeTest.php @@ -26,7 +26,7 @@ protected function setUp(): void /** * @test */ - public function buildView() + public function buildView(): void { $view = new FormView(); @@ -45,7 +45,7 @@ public function buildView() /** * @test */ - public function getParent() + public function getParent(): void { $this->assertSame(TextType::class, $this->type->getParent()); } @@ -53,7 +53,7 @@ public function getParent() /** * @test */ - public function getPublicKey() + public function getPublicKey(): void { $this->assertSame('key', $this->type->getPublicKey()); } @@ -61,7 +61,7 @@ public function getPublicKey() /** * @test */ - public function configureOptions() + public function configureOptions(): void { $optionsResolver = new OptionsResolver(); @@ -96,7 +96,7 @@ public function configureOptions() /** * @test */ - public function getBlockPrefix() + public function getBlockPrefix(): void { $this->assertEquals('ewz_recaptcha', $this->type->getBlockPrefix()); } diff --git a/tests/Form/Type/EWZRecaptchaV3TypeTest.php b/tests/Form/Type/EWZRecaptchaV3TypeTest.php index 8355d9b..20ac500 100755 --- a/tests/Form/Type/EWZRecaptchaV3TypeTest.php +++ b/tests/Form/Type/EWZRecaptchaV3TypeTest.php @@ -25,7 +25,7 @@ protected function setUp(): void /** * @test */ - public function buildView() + public function buildView(): void { $view = new FormView(); @@ -44,7 +44,7 @@ public function buildView() /** * @test */ - public function getParent() + public function getParent(): void { $this->assertSame(HiddenType::class, $this->type->getParent()); } @@ -52,7 +52,7 @@ public function getParent() /** * @test */ - public function getPublicKey() + public function getPublicKey(): void { $this->assertSame('key', $this->type->getPublicKey()); } @@ -60,7 +60,7 @@ public function getPublicKey() /** * @test */ - public function configureOptions() + public function configureOptions(): void { $optionsResolver = new OptionsResolver(); @@ -82,7 +82,7 @@ public function configureOptions() /** * @test */ - public function getBlockPrefix() + public function getBlockPrefix(): void { $this->assertEquals('ewz_recaptcha', $this->type->getBlockPrefix()); } diff --git a/tests/Locale/LocaleResolverTest.php b/tests/Locale/LocaleResolverTest.php index a8bbcf7..4f2b64b 100644 --- a/tests/Locale/LocaleResolverTest.php +++ b/tests/Locale/LocaleResolverTest.php @@ -12,7 +12,7 @@ class LocaleResolverTest extends TestCase /** * @test */ - public function resolveWithLocaleFromRequest() + public function resolveWithLocaleFromRequest(): void { $request = $this->createMock(Request::class); $request->expects($this->once())->method('getLocale'); @@ -30,7 +30,7 @@ public function resolveWithLocaleFromRequest() /** * @test */ - public function resolveWithDefaultLocale() + public function resolveWithDefaultLocale(): void { $requestStack = $this->createMock(RequestStack::class); $requestStack