Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ TITLE = [data-mapper]

unit-tests:
@/bin/echo "${TITLE} unit test suite started..." \
&& XDEBUG_MODE=off php5.6 ./vendor/bin/phpunit -c tests/unit/phpunit.xml --coverage-html tests/unit/coverage
&& XDEBUG_MODE=off php ./vendor/bin/phpunit -c tests/unit/phpunit.xml --coverage-html tests/unit/coverage

integration-tests:
@/bin/echo "${TITLE} starting virtual machine ..." \
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"g4/code-coverage" : "1.*"
},
"require": {
"php" : ">=7.3",
"php" : ">=8.2",
"ext-curl" : "*",
"ext-json" : "*",
"g4/factory" : "1.*",
Expand Down
15 changes: 6 additions & 9 deletions src/Collection/CollectionAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ abstract class CollectionAbstract implements \Iterator, \Countable

protected $_total = 0;

public function count()
public function count(): int
{
return $this->_total;
}

public function current()
public function current(): mixed
{
return $this->_getObject();
}
Expand All @@ -29,29 +29,26 @@ public function getRawData()
return $this->_rawData;
}

public function key()
public function key(): mixed
{
return $this->_pointer;
}

public function next()
public function next(): void
{
$row = $this->_getObject();

if (!empty($row)) {
$this->_incrementPointer();
}

return $row;
}

public function rewind()
public function rewind(): void
{
$this->_pointer = 0;
return $this;
}

public function valid()
public function valid(): bool
{
return !is_null($this->current());
}
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function getData()
/**
* @return int
*/
public function count()
public function count(): int
{
return count($this->data);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Common/RawData.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(array $data, $total)
$this->total = $total;
}

public function count()
public function count(): int
{
if ($this->count === null) {
$this->count = count($this->data);
Expand Down
2 changes: 1 addition & 1 deletion src/Common/SimpleRawData.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(array $data)
$this->data = $data;
}

public function count()
public function count(): int
{
if ($this->count === null) {
$this->count = count($this->data);
Expand Down
2 changes: 2 additions & 0 deletions src/Engine/Elasticsearch/ElasticsearchComparisonFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class ElasticsearchComparisonFormatter implements ComparisonFormatterInterface
const RANGE = 'range';
const TERMS = 'terms';

private ElasticsearchIdentity $identity;

public function __construct(ElasticsearchIdentity $identity)
{
$this->identity = $identity;
Expand Down
17 changes: 8 additions & 9 deletions src/Engine/Elasticsearch/ElasticsearchResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@ public function getHits()
*/
public function getTotal()
{
if (!is_array($this->decodedResponse)) {
return 0;
}
switch (true) {
case $this->hasError():
return 0;
case array_key_exists(self::KEY_RESPONSES_M_SEARCH, $this->decodedResponse):
return $this->getTotalFromMultiSearch();
case array_key_exists(self::KEY_HITS, $this->decodedResponse):
return (new TotalCount($this->decodedResponse[self::KEY_HITS]))->getValue();
case array_key_exists(self::KEY_COUNT, $this->decodedResponse):
return (new TotalCount($this->decodedResponse[self::KEY_COUNT]))->getValue();
case $this->hasError():
default:
return 0;
}
Expand All @@ -67,10 +69,10 @@ public function getTotal()
/**
* @return array
*/
private function getDecodedResponse()
private function getDecodedResponse(): ?array
{
if ($this->decodedResponse === null) {
$this->decodedResponse = json_decode($this->response, true);
$this->decodedResponse = is_string($this->response) ? json_decode($this->response, true) : null;
}
return $this->decodedResponse;
}
Expand All @@ -80,7 +82,7 @@ public function hasError()
return $this->decodedResponse === null || array_key_exists(self::KEY_ERROR, $this->decodedResponse);
}

public function getErrorMessage()
public function getErrorMessage(): string
{
if ($this->decodedResponse === null) {
return json_encode(['Error decoding response', $this->response]);
Expand Down Expand Up @@ -110,10 +112,7 @@ private function getHitsFromSearch()
: [];
}

/**
* @return int
*/
private function getTotalFromMultiSearch()
private function getTotalFromMultiSearch(): int
{
$multiSearchTotal = 0;
foreach ($this->decodedResponse[self::KEY_RESPONSES_M_SEARCH] as $singleHits) {
Expand Down
3 changes: 2 additions & 1 deletion src/Engine/Elasticsearch/ElasticsearchSelectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public function where()

foreach ($this->identity->getComparisons() as $oneComparison) {
if ($oneComparison instanceof Comparison && !$oneComparison->getValue()->isEmpty()) {
if (preg_match("/^-/", $oneComparison->getName())) {
$comparisonName = $oneComparison->getName() ?: '';
if (str_starts_with($comparisonName, '-')) {
$comparisons['must_not'][]= $oneComparison->getComparison($this->makeComparisonFormatter());
} else {
$comparisons['must'][]= $oneComparison->getComparison($this->makeComparisonFormatter());
Expand Down
9 changes: 3 additions & 6 deletions src/Engine/Elasticsearch/Operators/QueryStringOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@ public function __construct($name, SingleValue $value)
public function format()
{
return [
QueryConnector::NAME_QUERY_STRING_QUERY =>
QueryConnector::NAME_QUERY_STRING =>
[
QueryConnector::NAME_QUERY_STRING =>
[
QueryConnector::NAME_QUERY_STRING_QUERY => $this->value->getValue(),
QueryConnector::ANALYZE_WILDCARD => true,
],
QueryConnector::NAME_QUERY_STRING_QUERY => $this->value->getValue(),
QueryConnector::ANALYZE_WILDCARD => true,
],
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected function setUp(): void
public function tearDown(): void
{
$this->comparisonFormatter = null;
$this->operatorMock = null;
$this->operatorMock = null;
}

public function testEqual()
Expand All @@ -51,8 +51,8 @@ public function testEqualCI()
['match' => [
'email' => [
'query' => 'text@example.com',
'type' => 'phrase'
]
'type' => 'phrase',
],
]],
$this->comparisonFormatter->format('email', $this->operatorMock, new SingleValue('text@example.com'))
);
Expand All @@ -69,8 +69,8 @@ public function testEqualCIEsVersion7()
$this->assertEquals(
['match' => [
'email' => [
'query' => 'text@example.com'
]
'query' => 'text@example.com',
],
]],
$comparisonFormatter->format('email', $this->operatorMock, new SingleValue('text@example.com'))
);
Expand Down Expand Up @@ -157,10 +157,10 @@ public function testTimeFromInMinutes()
$this->assertEquals([
'range' => [
'online' => [
'gt' => strtotime("-15 minute", time()),
'gt' => strtotime("-15 minute", time()),
'format' => 'epoch_second',
]
]
],
],
], $this->comparisonFormatter->format('online', $this->operatorMock, new SingleValue(15)));
}

Expand Down Expand Up @@ -214,12 +214,10 @@ public function testQueryString()

$this->assertEquals(
[
'query' => [
'query_string' => [
'query' => 'username: *test* OR email: *test*',
'analyze_wildcard' => true,
],
]
'query_string' => [
'query' => 'username: *test* OR email: *test*',
'analyze_wildcard' => true,
],
],
$this->comparisonFormatter
->format('', $this->operatorMock, new SingleValue('username: *test* OR email: *test*'))
Expand All @@ -237,8 +235,8 @@ public function testQueryStringVersion7()
$this->assertEquals(
[
'query_string' => [
'query' => 'username: *test* OR email: *test*'
]
'query' => 'username: *test* OR email: *test*',
],
],
$comparisonFormatter->format('', $this->operatorMock, new SingleValue('username: *test* OR email: *test*'))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,16 @@ public function testGarbageResponse()

protected function setUp(): void
{
/**
* @codingStandardsIgnoreStart
*/
$this->dataWithHits = '{"took":16,"timed_out":false,"_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":1,"max_score":null,"hits":[1]}}';
$this->dataWithError = '{"error":{"root_cause":[{"type":"query_parsing_exception","reason":"field [location] is not a geo_point field","index":"profiles","line":1,"col":270}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query_fetch","grouped":true,"failed_shards":[{"shard":0,"index":"profiles","node":"75N9T595S-eqHYV8_o08ng","reason":{"type":"query_parsing_exception","reason":"field [location] is not a geo_point field","index":"profiles","line":1,"col":270}}]},"status":400}';

$this->errorMessage = '["search_phase_execution_exception",[{"type":"query_parsing_exception","reason":"field [location] is not a geo_point field","index":"profiles","line":1,"col":270}]]';
/**
* @codingStandardsIgnoreEnd
*/
}

protected function tearDown(): void
Expand Down