Skip to content

Commit

Permalink
Add types to classes that are not usually BC.
Browse files Browse the repository at this point in the history
  • Loading branch information
biozshock committed Dec 22, 2021
1 parent 02d6e91 commit 80730c4
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
14 changes: 7 additions & 7 deletions src/Form/Type/AbstractEWZRecaptchaType.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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'] ?? '',
]);
}
}
14 changes: 7 additions & 7 deletions tests/DependencyInjection/EWZRecaptchaExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -57,7 +57,7 @@ public function testSimpleConfiguration()
);
}

public function testSimpleV3Configuration()
public function testSimpleV3Configuration(): void
{
$this->configuration = new ContainerBuilder();
$loader = new EWZRecaptchaExtension();
Expand All @@ -74,7 +74,7 @@ public function testSimpleV3Configuration()

}

public function testFullConfiguration()
public function testFullConfiguration(): void
{
$this->configuration = new ContainerBuilder();
$loader = new EWZRecaptchaExtension();
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions tests/Form/Type/EWZRecaptchaTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected function setUp(): void
/**
* @test
*/
public function buildView()
public function buildView(): void
{
$view = new FormView();

Expand All @@ -45,23 +45,23 @@ public function buildView()
/**
* @test
*/
public function getParent()
public function getParent(): void
{
$this->assertSame(TextType::class, $this->type->getParent());
}

/**
* @test
*/
public function getPublicKey()
public function getPublicKey(): void
{
$this->assertSame('key', $this->type->getPublicKey());
}

/**
* @test
*/
public function configureOptions()
public function configureOptions(): void
{
$optionsResolver = new OptionsResolver();

Expand Down Expand Up @@ -96,7 +96,7 @@ public function configureOptions()
/**
* @test
*/
public function getBlockPrefix()
public function getBlockPrefix(): void
{
$this->assertEquals('ewz_recaptcha', $this->type->getBlockPrefix());
}
Expand Down
10 changes: 5 additions & 5 deletions tests/Form/Type/EWZRecaptchaV3TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected function setUp(): void
/**
* @test
*/
public function buildView()
public function buildView(): void
{
$view = new FormView();

Expand All @@ -44,23 +44,23 @@ public function buildView()
/**
* @test
*/
public function getParent()
public function getParent(): void
{
$this->assertSame(HiddenType::class, $this->type->getParent());
}

/**
* @test
*/
public function getPublicKey()
public function getPublicKey(): void
{
$this->assertSame('key', $this->type->getPublicKey());
}

/**
* @test
*/
public function configureOptions()
public function configureOptions(): void
{
$optionsResolver = new OptionsResolver();

Expand All @@ -82,7 +82,7 @@ public function configureOptions()
/**
* @test
*/
public function getBlockPrefix()
public function getBlockPrefix(): void
{
$this->assertEquals('ewz_recaptcha', $this->type->getBlockPrefix());
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Locale/LocaleResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -30,7 +30,7 @@ public function resolveWithLocaleFromRequest()
/**
* @test
*/
public function resolveWithDefaultLocale()
public function resolveWithDefaultLocale(): void
{
$requestStack = $this->createMock(RequestStack::class);
$requestStack
Expand Down

0 comments on commit 80730c4

Please sign in to comment.