Remove unused "AbstractSearcher" class

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
Henrique Moody 2024-02-14 00:11:12 +01:00
parent a45a0a26ab
commit 794739917a
No known key found for this signature in database
GPG key ID: 221E9281655813A6
3 changed files with 0 additions and 138 deletions

View file

@ -1,40 +0,0 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Helpers\CanValidateUndefined;
use function in_array;
use function is_scalar;
abstract class AbstractSearcher extends AbstractRule
{
use CanValidateUndefined;
/**
* @return mixed[]
*/
abstract protected function getDataSource(mixed $input = null): array;
public function validate(mixed $input): bool
{
$dataSource = $this->getDataSource($input);
if ($this->isUndefined($input) && empty($dataSource)) {
return true;
}
if (!is_scalar($input)) {
return false;
}
return in_array((string) $input, $dataSource, true);
}
}

View file

@ -1,35 +0,0 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Test\Rules;
use Respect\Validation\Rules\AbstractSearcher;
use function call_user_func;
final class SearcherStub extends AbstractSearcher
{
/**
* @var callable
*/
private $dataSourceCallable;
public function __construct(callable $dataSourceCallable)
{
$this->dataSourceCallable = $dataSourceCallable;
}
/**
* @return array<mixed, array<mixed>>
*/
protected function getDataSource(mixed $input = null): array
{
return call_user_func($this->dataSourceCallable, $input);
}
}

View file

@ -1,63 +0,0 @@
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Rules;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use Respect\Validation\Test\DataProvider\UndefinedProvider;
use Respect\Validation\Test\Rules\SearcherStub;
use Respect\Validation\Test\TestCase;
#[Group('core')]
#[CoversClass(AbstractSearcher::class)]
final class AbstractSearcherTest extends TestCase
{
use UndefinedProvider;
#[Test]
public function shouldValidateFromDataSource(): void
{
$input = 'BAZ';
$rule = new SearcherStub(static fn() => ['FOO', $input, 'BAZ']);
self::assertTrue($rule->validate($input));
}
#[Test]
public function shouldNotFindWhenNotIdentical(): void
{
$input = 2.0;
$rule = new SearcherStub(static fn() => [1, (int) $input, 3]);
self::assertFalse($rule->validate($input));
}
#[Test]
#[DataProvider('providerForUndefined')]
public function shouldValidateWhenValueIsUndefinedAndDataSourceIsEmpty(mixed $input): void
{
$rule = new SearcherStub(static fn() => []);
self::assertTrue($rule->validate($input));
}
#[Test]
#[DataProvider('providerForNotUndefined')]
public function shouldNotValidateWhenValueIsNotUndefinedAndDataSourceNotEmpty(mixed $input): void
{
$rule = new SearcherStub(static fn() => []);
self::assertFalse($rule->validate($input));
}
}