Skip to content

Commit 506bdae

Browse files
Refactor
1 parent 916644e commit 506bdae

File tree

2 files changed

+18
-23
lines changed

2 files changed

+18
-23
lines changed

src/Document/Document.php

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ public function __construct($id = null)
2323
$this->id = $id ?? uniqid(true);
2424
}
2525

26+
protected function addFieldsToProperties($properties): array
27+
{
28+
/** @var FieldInterface $field */
29+
foreach (get_object_vars($this) as $field) {
30+
if ($field instanceof FieldInterface && !is_null($field->getValue())) {
31+
$properties[] = $field->getName();
32+
$properties[] = $field->getValue();
33+
}
34+
}
35+
return $properties;
36+
}
37+
2638
public function getHashDefinition(array $prefixes = null): array
2739
{
2840
$id = $this->getId();
@@ -45,15 +57,7 @@ public function getHashDefinition(array $prefixes = null): array
4557
$properties[] = 'REPLACE';
4658
}
4759

48-
/** @var FieldInterface $field */
49-
foreach (get_object_vars($this) as $field) {
50-
if ($field instanceof FieldInterface && !is_null($field->getValue())) {
51-
$properties[] = $field->getName();
52-
$properties[] = $field->getValue();
53-
}
54-
}
55-
56-
return $properties;
60+
return $this->addFieldsToProperties($properties);
5761
}
5862

5963
public function getDefinition(): array
@@ -91,14 +95,7 @@ public function getDefinition(): array
9195

9296
$properties[] = 'FIELDS';
9397

94-
/** @var FieldInterface $field */
95-
foreach (get_object_vars($this) as $field) {
96-
if ($field instanceof FieldInterface && !is_null($field->getValue())) {
97-
$properties[] = $field->getName();
98-
$properties[] = $field->getValue();
99-
}
100-
}
101-
return $properties;
98+
return $this->addFieldsToProperties($properties);
10299
}
103100

104101
public function getId(): string

tests/RediSearch/IndexTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ public function testSetStopWordsOnCreateIndex()
733733
$this->assertEquals(1, $result->getCount());
734734
}
735735

736-
public function testWithPrefix()
736+
public function testShouldNotSearchEveryIndexWhenAPrefixIsSpecified()
737737
{
738738
$expectedFirstResult = 'Jack';
739739
$firstPrefix = 'Foo';
@@ -757,16 +757,14 @@ public function testWithPrefix()
757757
$this->assertEquals($expectedFirstResult, $firstResult->getDocuments()[0]->name);
758758
}
759759

760-
public function testWithoutPrefix()
760+
public function testShouldSearchEveryIndexWhenAPrefixIsNotSpecified()
761761
{
762762
$expectedDocuments = 1;
763763
$expectedName = 'Jack';
764-
$firstIndex = (new Index($this->redisClient, 'first'))
765-
->addTextField('name');
764+
$firstIndex = (new Index($this->redisClient, 'first'))->addTextField('name');
766765
$firstIndex->create();
767766
$firstIndex->add([new TextField('name', $expectedName)]);
768-
$secondIndex = (new Index($this->redisClient, 'second'))
769-
->addTextField('name');
767+
$secondIndex = (new Index($this->redisClient, 'second'))->addTextField('name');
770768
$secondIndex->create();
771769

772770
$firstResult = $firstIndex->search($expectedName);

0 commit comments

Comments
 (0)