Skip to content

Commit

Permalink
Code: apple codesniffer
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Jan 2, 2024
1 parent 7b8b9af commit dbfd4e9
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 49 deletions.
8 changes: 8 additions & 0 deletions ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
</properties>
</rule>

<rule ref="Squiz.Classes.ClassFileName.NoMatch">
<exclude-pattern>tests</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName.NoMatchBetweenTypeNameAndFileName">
<exclude-pattern>tests</exclude-pattern>
</rule>

<!-- Excludes -->
<exclude-pattern>/tests/tmp</exclude-pattern>
</ruleset>
1 change: 0 additions & 1 deletion src/Forms/InvisibleReCaptchaField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions src/ReCaptchaProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions tests/Cases/DI/ReCaptchaExtension.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -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' => [
Expand Down
17 changes: 5 additions & 12 deletions tests/Cases/Forms/InvisibleReCaptchField.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

namespace Tests\Cases\Forms;

/**
* Test: ReCaptchaField
*/

use Contributte\ReCaptcha\Forms\InvisibleReCaptchaField;
use Contributte\ReCaptcha\ReCaptchaProvider;
use Contributte\Tester\Toolkit;
Expand All @@ -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());

Expand All @@ -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';
Expand All @@ -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';
Expand All @@ -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';
Expand Down
6 changes: 3 additions & 3 deletions tests/Cases/Forms/InvisibleReCaptchaBinding.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand Down
13 changes: 5 additions & 8 deletions tests/Cases/Forms/ReCaptchField.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -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';
Expand All @@ -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';
Expand All @@ -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';
Expand Down
12 changes: 4 additions & 8 deletions tests/Cases/Forms/ReCaptchaBinding.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

namespace Tests\Cases\Forms;

/**
* Test: ReCaptchaBinding
*/

use Contributte\ReCaptcha\Forms\ReCaptchaBinding;
use Contributte\ReCaptcha\Forms\ReCaptchaField;
use Contributte\ReCaptcha\ReCaptchaProvider;
Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions tests/Cases/ReCaptchResponse.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
11 changes: 4 additions & 7 deletions tests/Cases/ReCaptchaProvider.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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');

Expand Down

0 comments on commit dbfd4e9

Please sign in to comment.