diff --git a/ruleset.xml b/ruleset.xml index dee22c1..5d4b6d4 100644 --- a/ruleset.xml +++ b/ruleset.xml @@ -17,6 +17,14 @@ + + tests + + + + tests + + /tests/tmp diff --git a/src/Forms/InvisibleReCaptchaField.php b/src/Forms/InvisibleReCaptchaField.php index 66d1652..84fba52 100644 --- a/src/Forms/InvisibleReCaptchaField.php +++ b/src/Forms/InvisibleReCaptchaField.php @@ -2,7 +2,6 @@ namespace Contributte\ReCaptcha\Forms; -use Contributte\ReCaptcha\Exceptions\InvalidScoreException; use Contributte\ReCaptcha\ReCaptchaProvider; use Nette\Forms\Controls\HiddenField; use Nette\Forms\Form; diff --git a/src/ReCaptchaProvider.php b/src/ReCaptchaProvider.php index fc9c973..ba2d44b 100644 --- a/src/ReCaptchaProvider.php +++ b/src/ReCaptchaProvider.php @@ -28,10 +28,12 @@ class ReCaptchaProvider private string $secretKey; - // Range 0..1 (1.0 is very likely a good interaction, 0.0 is very likely a bot) + /** + * Range 0..1 (1.0 is very likely a good interaction, 0.0 is very likely a bot) + */ private float $minimalScore; - public function __construct(string $siteKey, string $secretKey, float $minimalScore) + public function __construct(string $siteKey, string $secretKey, float $minimalScore = 0) { $this->siteKey = $siteKey; $this->secretKey = $secretKey; diff --git a/tests/Cases/DI/ReCaptchaExtension.phpt b/tests/Cases/DI/ReCaptchaExtension.phpt index 2a788d5..2075855 100644 --- a/tests/Cases/DI/ReCaptchaExtension.phpt +++ b/tests/Cases/DI/ReCaptchaExtension.phpt @@ -13,9 +13,9 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; -Toolkit::test(function () { +Toolkit::test(function (): void { $loader = new ContainerLoader(Environment::getTestDir()); - $class = $loader->load(function (Compiler $compiler) { + $class = $loader->load(function (Compiler $compiler): void { $compiler->addExtension('captcha', new ReCaptchaExtension()); $compiler->addConfig([ @@ -31,10 +31,10 @@ Toolkit::test(function () { Assert::equal('foobar', $container->getByType(ReCaptchaProvider::class)->getSiteKey()); }); -Toolkit::test(function () { - Assert::exception(function () { +Toolkit::test(function (): void { + Assert::exception(function (): void { $loader = new ContainerLoader(Environment::getTestDir()); - $loader->load(function (Compiler $compiler) { + $loader->load(function (Compiler $compiler): void { $compiler->addExtension('captcha', new ReCaptchaExtension()); $compiler->addConfig([ 'captcha' => [ diff --git a/tests/Cases/Forms/InvisibleReCaptchField.phpt b/tests/Cases/Forms/InvisibleReCaptchField.phpt index 9962acf..6bffe7b 100644 --- a/tests/Cases/Forms/InvisibleReCaptchField.phpt +++ b/tests/Cases/Forms/InvisibleReCaptchField.phpt @@ -2,10 +2,6 @@ namespace Tests\Cases\Forms; -/** - * Test: ReCaptchaField - */ - use Contributte\ReCaptcha\Forms\InvisibleReCaptchaField; use Contributte\ReCaptcha\ReCaptchaProvider; use Contributte\Tester\Toolkit; @@ -19,17 +15,14 @@ require __DIR__ . '/../../bootstrap.php'; final class FormMock extends Form { - /** - * @return mixed - */ - public function getHttpData(?int $type = null, ?string $htmlName = null) + public function getHttpData(?int $type = null, ?string $htmlName = null): mixed { return $htmlName; } } -Toolkit::test(function () { +Toolkit::test(function (): void { $field = new InvisibleReCaptchaField(new ReCaptchaProvider('foobar', 'secret')); Assert::equal(['g-recaptcha' => true], $field->getControlPrototype()->getClass()); @@ -40,7 +33,7 @@ Toolkit::test(function () { Assert::equal('foobar', $field->getControlPrototype()->getClass()); }); -Toolkit::test(function () { +Toolkit::test(function (): void { $form = new FormMock('form'); $fieldName = 'captcha'; @@ -51,7 +44,7 @@ Toolkit::test(function () { Assert::equal(sprintf(BaseControl::$idMask, $form->getName() . '-' . $fieldName), $field->getHtmlId()); }); -Toolkit::test(function () { +Toolkit::test(function (): void { $form = new FormMock('form'); $fieldName = 'captcha'; @@ -62,7 +55,7 @@ Toolkit::test(function () { Assert::equal($key, $field->getControl()->{'data-sitekey'}); }); -Toolkit::test(function () { +Toolkit::test(function (): void { $form = new FormMock('form'); $fieldName = 'captcha'; diff --git a/tests/Cases/Forms/InvisibleReCaptchaBinding.phpt b/tests/Cases/Forms/InvisibleReCaptchaBinding.phpt index 2e6dd52..b275766 100644 --- a/tests/Cases/Forms/InvisibleReCaptchaBinding.phpt +++ b/tests/Cases/Forms/InvisibleReCaptchaBinding.phpt @@ -11,7 +11,7 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; -Toolkit::test(function () { +Toolkit::test(function (): void { $provider = new ReCaptchaProvider('foo', 'bar'); InvisibleReCaptchaBinding::bind($provider); @@ -24,7 +24,7 @@ Toolkit::test(function () { Assert::same('foo', $recaptcha->getControl()->{'data-sitekey'}); }); -Toolkit::test(function () { +Toolkit::test(function (): void { $provider = new ReCaptchaProvider('foo', 'bar'); InvisibleReCaptchaBinding::bind($provider); @@ -33,7 +33,7 @@ Toolkit::test(function () { Assert::false($recaptcha->isRequired()); }); -Toolkit::test(function () { +Toolkit::test(function (): void { $provider = new ReCaptchaProvider('foo', 'bar'); InvisibleReCaptchaBinding::bind($provider); diff --git a/tests/Cases/Forms/ReCaptchField.phpt b/tests/Cases/Forms/ReCaptchField.phpt index 11b2cea..c1ccd2b 100644 --- a/tests/Cases/Forms/ReCaptchField.phpt +++ b/tests/Cases/Forms/ReCaptchField.phpt @@ -15,17 +15,14 @@ require __DIR__ . '/../../bootstrap.php'; final class FormMock extends Form { - /** - * @return mixed - */ - public function getHttpData(?int $type = null, ?string $htmlName = null) + public function getHttpData(?int $type = null, ?string $htmlName = null): mixed { return $htmlName; } } -Toolkit::test(function () { +Toolkit::test(function (): void { $field = new ReCaptchaField(new ReCaptchaProvider('foobar', 'secret')); Assert::equal(['g-recaptcha' => true], $field->getControlPrototype()->getClass()); @@ -36,7 +33,7 @@ Toolkit::test(function () { Assert::equal('foobar', $field->getControlPrototype()->getClass()); }); -Toolkit::test(function () { +Toolkit::test(function (): void { $form = new FormMock('form'); $fieldName = 'captcha'; @@ -48,7 +45,7 @@ Toolkit::test(function () { Assert::equal(sprintf(BaseControl::$idMask, $form->getName() . '-' . $fieldName), $field->getHtmlId()); }); -Toolkit::test(function () { +Toolkit::test(function (): void { $form = new FormMock('form'); $fieldName = 'captcha'; @@ -59,7 +56,7 @@ Toolkit::test(function () { Assert::equal($key, $field->getControl()->{'data-sitekey'}); }); -Toolkit::test(function () { +Toolkit::test(function (): void { $form = new FormMock('form'); $fieldName = 'captcha'; diff --git a/tests/Cases/Forms/ReCaptchaBinding.phpt b/tests/Cases/Forms/ReCaptchaBinding.phpt index 44a878e..c14fe46 100644 --- a/tests/Cases/Forms/ReCaptchaBinding.phpt +++ b/tests/Cases/Forms/ReCaptchaBinding.phpt @@ -2,10 +2,6 @@ namespace Tests\Cases\Forms; -/** - * Test: ReCaptchaBinding - */ - use Contributte\ReCaptcha\Forms\ReCaptchaBinding; use Contributte\ReCaptcha\Forms\ReCaptchaField; use Contributte\ReCaptcha\ReCaptchaProvider; @@ -15,7 +11,7 @@ use Tester\Assert; require __DIR__ . '/../../bootstrap.php'; -Toolkit::test(function () { +Toolkit::test(function (): void { $provider = new ReCaptchaProvider('foo', 'bar'); ReCaptchaBinding::bind($provider); @@ -29,7 +25,7 @@ Toolkit::test(function () { Assert::same('foo', $recaptcha->getControl()->{'data-sitekey'}); }); -Toolkit::test(function () { +Toolkit::test(function (): void { $provider = new ReCaptchaProvider('foo', 'bar'); ReCaptchaBinding::bind($provider); @@ -38,7 +34,7 @@ Toolkit::test(function () { Assert::same('My label', $recaptcha->getLabel()->getText()); }); -Toolkit::test(function () { +Toolkit::test(function (): void { $provider = new ReCaptchaProvider('foo', 'bar'); ReCaptchaBinding::bind($provider); @@ -47,7 +43,7 @@ Toolkit::test(function () { Assert::false($recaptcha->isRequired()); }); -Toolkit::test(function () { +Toolkit::test(function (): void { $provider = new ReCaptchaProvider('foo', 'bar'); ReCaptchaBinding::bind($provider); diff --git a/tests/Cases/ReCaptchResponse.phpt b/tests/Cases/ReCaptchResponse.phpt index 9ac5d4d..f554c23 100644 --- a/tests/Cases/ReCaptchResponse.phpt +++ b/tests/Cases/ReCaptchResponse.phpt @@ -8,17 +8,17 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -Toolkit::test(function () { +Toolkit::test(function (): void { $response = new ReCaptchaResponse(true); Assert::true($response->isSuccess()); }); -Toolkit::test(function () { +Toolkit::test(function (): void { $response = new ReCaptchaResponse(true); Assert::equal('1', (string) $response); }); -Toolkit::test(function () { +Toolkit::test(function (): void { $error = 'Some error'; $response = new ReCaptchaResponse(false, $error); Assert::false($response->isSuccess()); diff --git a/tests/Cases/ReCaptchaProvider.phpt b/tests/Cases/ReCaptchaProvider.phpt index a988012..148faba 100644 --- a/tests/Cases/ReCaptchaProvider.phpt +++ b/tests/Cases/ReCaptchaProvider.phpt @@ -13,17 +13,14 @@ require __DIR__ . '/../bootstrap.php'; final class ControlMock extends BaseControl { - /** - * @return string - */ - public function getValue() + public function getValue(): string { return 'test'; } } -Toolkit::test(function () { +Toolkit::test(function (): void { $key = 'key'; $validator = new ReCaptchaProvider($key, 'secret'); @@ -34,14 +31,14 @@ Toolkit::test(function () { Assert::notEqual(null, $response->getError()); }); -Toolkit::test(function () { +Toolkit::test(function (): void { $key = 'key'; $validator = new ReCaptchaProvider($key, 'secret'); Assert::false($validator->validateControl(new ControlMock())); }); -Toolkit::test(function () { +Toolkit::test(function (): void { $key = 'key'; $validator = new ReCaptchaProvider($key, 'secret');