Skip to content

Commit 4383b46

Browse files
committed
Use constant instead of hardcoded version
1 parent c51d0d1 commit 4383b46

30 files changed

+36
-32
lines changed

src/Index.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use function count;
2525
use function is_array;
2626
use function is_string;
27+
use MacFJA\RediSearch\Redis\Command\AbstractCommand;
2728
use MacFJA\RediSearch\Redis\Command\AliasAdd;
2829
use MacFJA\RediSearch\Redis\Command\AliasDel;
2930
use MacFJA\RediSearch\Redis\Command\AliasUpdate;
@@ -54,7 +55,7 @@ public function __construct(string $index, ClientInterface $client)
5455
{
5556
$this->client = $client;
5657
$this->index = $index;
57-
$this->version = Initializer::getRediSearchVersion($client) ?? '2.0.0';
58+
$this->version = Initializer::getRediSearchVersion($client) ?? AbstractCommand::MIN_IMPLEMENTED_VERSION;
5859
$this->getInfo();
5960
}
6061

src/IndexBuilder.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use function is_float;
3030
use function is_int;
3131
use function is_string;
32+
use MacFJA\RediSearch\Redis\Command\AbstractCommand;
3233
use MacFJA\RediSearch\Redis\Command\AddFieldOptionTrait;
3334
use MacFJA\RediSearch\Redis\Command\Create;
3435
use MacFJA\RediSearch\Redis\Command\CreateCommand\CreateCommandFieldOption;
@@ -167,7 +168,7 @@ public function addField(CreateCommandFieldOption ...$option): self
167168
return $this;
168169
}
169170

170-
public function create(ClientInterface $client, string $rediSearchVersion = '2.0.0'): ResponseInterface
171+
public function create(ClientInterface $client, string $rediSearchVersion = AbstractCommand::MIN_IMPLEMENTED_VERSION): ResponseInterface
171172
{
172173
$command = $this->getCommand($rediSearchVersion);
173174

@@ -180,7 +181,7 @@ public function create(ClientInterface $client, string $rediSearchVersion = '2.0
180181
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
181182
* @SuppressWarnings(PHPMD.NPathComplexity)
182183
*/
183-
public function getCommand(string $rediSearchVersion = '2.0.0'): Create
184+
public function getCommand(string $rediSearchVersion = AbstractCommand::MIN_IMPLEMENTED_VERSION): Create
184185
{
185186
if (!is_string($this->index)) {
186187
throw new RuntimeException('The index name is missing');

src/Redis/Command/AbstractCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ abstract class AbstractCommand extends Command
4646
/**
4747
* @param array<array<CommandOption>|CommandOption|mixed> $options
4848
*/
49-
public function __construct(array $options, string $rediSearchVersion = '2.0.0')
49+
public function __construct(array $options, string $rediSearchVersion = self::MIN_IMPLEMENTED_VERSION)
5050
{
5151
$this->rediSearchVersion = $rediSearchVersion;
5252

src/Redis/Command/Aggregate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Aggregate extends AbstractCommand implements PaginatedCommand
4343
{
4444
use ArrayResponseTrait;
4545

46-
public function __construct(string $rediSearchVersion = '2.0.0')
46+
public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VERSION)
4747
{
4848
parent::__construct([
4949
'index' => new NamelessOption(null, '>=2.0.0'),

src/Redis/Command/AliasAdd.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*/
3030
class AliasAdd extends AbstractCommand
3131
{
32-
public function __construct(string $rediSearchVersion = '2.0.0')
32+
public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VERSION)
3333
{
3434
parent::__construct([
3535
'alias' => new NamelessOption(null, '>=2.0.0'),

src/Redis/Command/AliasDel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*/
3030
class AliasDel extends AbstractCommand
3131
{
32-
public function __construct(string $rediSearchVersion = '2.0.0')
32+
public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VERSION)
3333
{
3434
parent::__construct([
3535
'alias' => new NamelessOption(null, '>=2.0.0'),

src/Redis/Command/AliasUpdate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*/
3030
class AliasUpdate extends AbstractCommand
3131
{
32-
public function __construct(string $rediSearchVersion = '2.0.0')
32+
public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VERSION)
3333
{
3434
parent::__construct([
3535
'alias' => new NamelessOption(null, '>=2.0.0'),

src/Redis/Command/Alter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Alter extends AbstractCommand
3232
{
3333
use AddFieldOptionTrait;
3434

35-
public function __construct(string $rediSearchVersion = '2.0.0')
35+
public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VERSION)
3636
{
3737
parent::__construct([
3838
'index' => new NamelessOption(null, '>=2.0.0'),

src/Redis/Command/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*/
3030
class Config extends AbstractCommand
3131
{
32-
public function __construct(string $rediSearchVersion = '2.0.0')
32+
public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VERSION)
3333
{
3434
parent::__construct([
3535
'action' => CustomValidatorOption::allowedValues(new NamelessOption(null, '>=2.0.0'), ['GET', 'HELP']),

src/Redis/Command/ConfigSet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*/
3232
class ConfigSet extends AbstractCommand
3333
{
34-
public function __construct(string $rediSearchVersion = '2.0.0')
34+
public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VERSION)
3535
{
3636
parent::__construct([
3737
'action' => new FlagOption('SET', true, '>=2.0.0'),

src/Redis/Command/Create.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Create extends AbstractCommand
3737
use LanguageOptionTrait;
3838
use AddFieldOptionTrait;
3939

40-
public function __construct(string $rediSearchVersion = '2.0.0')
40+
public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VERSION)
4141
{
4242
parent::__construct([
4343
'index' => new NamelessOption(null, '>=2.0.0'),

src/Redis/Command/CursorDel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
*/
3131
class CursorDel extends AbstractCommand
3232
{
33-
public function __construct(string $rediSearchVersion = '2.0.0')
33+
public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VERSION)
3434
{
3535
parent::__construct([
3636
'type' => new FlagOption('DEL', true, '>=2.0.0'),

src/Redis/Command/CursorRead.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class CursorRead extends AbstractCommand
3939
{
4040
use ArrayResponseTrait;
4141

42-
public function __construct(string $rediSearchVersion = '2.0.0')
42+
public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VERSION)
4343
{
4444
parent::__construct([
4545
'type' => new FlagOption('READ', true, '>=2.0.0'),
@@ -85,7 +85,7 @@ public function getId()
8585
/**
8686
* @param array<array<mixed>|int> $data
8787
*/
88-
public static function transformResponse(array $data, ?int $count, string $index, string $rediSearchVersion = '2.0.0'): CursorResponse
88+
public static function transformResponse(array $data, ?int $count, string $index, string $rediSearchVersion = self::MIN_IMPLEMENTED_VERSION): CursorResponse
8989
{
9090
[$rawResult, $cursorId] = $data;
9191

src/Redis/Command/DictAdd.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
class DictAdd extends AbstractCommand
3030
{
31-
public function __construct(string $rediSearchVersion = '2.0.0')
31+
public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VERSION)
3232
{
3333
parent::__construct([
3434
'dict' => new NamelessOption(null, '>=2.0.0'),

src/Redis/Command/DictDel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
class DictDel extends AbstractCommand
3030
{
31-
public function __construct(string $rediSearchVersion = '2.0.0')
31+
public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VERSION)
3232
{
3333
parent::__construct([
3434
'dict' => new NamelessOption(null, '>=2.0.0'),

src/Redis/Command/DictDump.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
class DictDump extends AbstractCommand
3030
{
31-
public function __construct(string $rediSearchVersion = '2.0.0')
31+
public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VERSION)
3232
{
3333
parent::__construct([
3434
'dict' => new NamelessOption(null, '>=2.0.0'),

src/Redis/Command/DropIndex.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
*/
3131
class DropIndex extends AbstractCommand
3232
{
33-
public function __construct(string $rediSearchVersion = '2.0.0')
33+
public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VERSION)
3434
{
3535
parent::__construct([
3636
'index' => new NamelessOption(null, '>=2.0.0'),

src/Redis/Command/Explain.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
class Explain extends AbstractCommand
3030
{
31-
public function __construct(string $rediSearchVersion = '2.0.0')
31+
public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VERSION)
3232
{
3333
parent::__construct([
3434
'index' => new NamelessOption(null, '>=2.0.0'),

src/Redis/Command/Info.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*/
3030
class Info extends AbstractCommand
3131
{
32-
public function __construct(string $rediSearchVersion = '2.0.0')
32+
public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VERSION)
3333
{
3434
parent::__construct([
3535
'index' => new NamelessOption(null, '>=2.0.0'),

src/Redis/Command/Search.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class Search extends AbstractCommand implements PaginatedCommand
5050
use LanguageOptionTrait;
5151
use ArrayResponseTrait;
5252

53-
public function __construct(string $rediSearchVersion = '2.0.0')
53+
public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VERSION)
5454
{
5555
parent::__construct(
5656
[

src/Redis/Command/SpellCheck.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
*/
3535
class SpellCheck extends AbstractCommand
3636
{
37-
public function __construct(string $rediSearchVersion = '2.0.0')
37+
public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VERSION)
3838
{
3939
parent::__construct([
4040
'index' => new NamelessOption(null, '>=2.0.0'),

src/Redis/Command/SugAdd.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*/
3232
class SugAdd extends AbstractCommand
3333
{
34-
public function __construct(string $rediSearchVersion = '2.0.0')
34+
public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VERSION)
3535
{
3636
parent::__construct([
3737
'dictionary' => new NamelessOption(null, '>=2.0.0'),

src/Redis/Command/SugDel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
class SugDel extends AbstractCommand
3030
{
31-
public function __construct(string $rediSearchVersion = '2.0.0')
31+
public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VERSION)
3232
{
3333
parent::__construct([
3434
'dictionary' => new NamelessOption(null, '>=2.0.0'),

src/Redis/Command/SugGet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
*/
3636
class SugGet extends AbstractCommand
3737
{
38-
public function __construct(string $rediSearchVersion = '2.0.0')
38+
public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VERSION)
3939
{
4040
parent::__construct([
4141
'dictionary' => new NamelessOption(null, '>=2.0.0'),

src/Redis/Command/SugLen.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
class SugLen extends AbstractCommand
3030
{
31-
public function __construct(string $rediSearchVersion = '2.0.0')
31+
public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VERSION)
3232
{
3333
parent::__construct([
3434
'dictionary' => new NamelessOption(null, '>=2.0.0'),

src/Redis/Command/SynDump.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
class SynDump extends AbstractCommand
2727
{
28-
public function __construct(string $rediSearchVersion = '2.0.0')
28+
public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VERSION)
2929
{
3030
parent::__construct([
3131
'index' => new NamelessOption(null, '>=2.0.0'),

src/Redis/Command/SynUpdate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
class SynUpdate extends AbstractCommand
2828
{
29-
public function __construct(string $rediSearchVersion = '2.0.0')
29+
public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VERSION)
3030
{
3131
parent::__construct([
3232
'index' => new NamelessOption(null, '>=2.0.0'),

src/Redis/Command/TagVals.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
class TagVals extends AbstractCommand
3030
{
31-
public function __construct(string $rediSearchVersion = '2.0.0')
31+
public function __construct(string $rediSearchVersion = self::MIN_IMPLEMENTED_VERSION)
3232
{
3333
parent::__construct([
3434
'index' => new NamelessOption(null, '>=2.0.0'),

src/Redis/Response/CursorResponse.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
use function count;
2525
use Iterator;
26+
use MacFJA\RediSearch\Redis\Command\AbstractCommand;
2627
use MacFJA\RediSearch\Redis\Command\CursorRead;
2728
use Predis\ClientInterface;
2829
use Predis\Response\ResponseInterface;
@@ -54,7 +55,7 @@ class CursorResponse implements ResponseInterface, Iterator
5455
/**
5556
* @param array<AggregateResponseItem> $items
5657
*/
57-
public function __construct(int $cursorId, int $totalCount, array $items, int $size, string $index, string $redisVersion = '2.0.0')
58+
public function __construct(int $cursorId, int $totalCount, array $items, int $size, string $index, string $redisVersion = AbstractCommand::MIN_IMPLEMENTED_VERSION)
5859
{
5960
$this->totalCount = $totalCount;
6061
$this->items = $items;

src/Suggestions.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
use function is_int;
2525
use function is_string;
26+
use MacFJA\RediSearch\Redis\Command\AbstractCommand;
2627
use MacFJA\RediSearch\Redis\Command\SugAdd;
2728
use MacFJA\RediSearch\Redis\Command\SugDel;
2829
use MacFJA\RediSearch\Redis\Command\SugGet;
@@ -50,7 +51,7 @@ public function __construct(string $dictionary, ClientInterface $client)
5051
$this->dictionary = $dictionary;
5152
$this->client = $client;
5253
$this->length = $client->executeCommand((new SugLen())->setDictionary($dictionary));
53-
$this->version = Initializer::getRediSearchVersion($client) ?? '2.0.0';
54+
$this->version = Initializer::getRediSearchVersion($client) ?? AbstractCommand::MIN_IMPLEMENTED_VERSION;
5455
}
5556

5657
public function add(string $suggestion, float $score, bool $increment = false, ?string $payload = null): void

0 commit comments

Comments
 (0)