Skip to content

Commit

Permalink
CS
Browse files Browse the repository at this point in the history
  • Loading branch information
norkunas committed Sep 25, 2024
1 parent d17688c commit 71fa596
Show file tree
Hide file tree
Showing 18 changed files with 391 additions and 182 deletions.
15 changes: 10 additions & 5 deletions src/Contracts/DeleteTasksQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ class DeleteTasksQuery
{
use TasksQueryTrait;

private array $canceledBy;

public function setCanceledBy(array $canceledBy)
private ?array $canceledBy = null;

/**
* @param non-empty-array<int> $canceledBy
*
* @return $this
*/
public function setCanceledBy(array $canceledBy): self
{
$this->canceledBy = $canceledBy;

Expand All @@ -24,8 +29,8 @@ public function toArray(): array
return array_filter(
array_merge(
$this->baseArray(),
['canceledBy' => $this->formatArray($this->canceledBy ?? null)]
), function ($item) { return null != $item || is_numeric($item); }
['canceledBy' => $this->formatArray($this->canceledBy)]
), static function ($item) { return null !== $item; }
);
}
}
57 changes: 34 additions & 23 deletions src/Contracts/DocumentsQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,36 @@

class DocumentsQuery
{
private int $offset;
private int $limit;
private array $fields;
private array $filter;
private ?int $offset = null;
private ?int $limit = null;
private ?array $fields = null;
private ?array $filter = null;
private ?bool $retrieveVectors = null;

public function setOffset(int $offset): DocumentsQuery
/**
* @return $this
*/
public function setOffset(int $offset): self
{
$this->offset = $offset;

return $this;
}

public function setLimit(int $limit): DocumentsQuery
/**
* @return $this
*/
public function setLimit(int $limit): self
{
$this->limit = $limit;

return $this;
}

public function setFields(array $fields): DocumentsQuery
/**
* @return $this
*/
public function setFields(array $fields): self
{
$this->fields = $fields;

Expand All @@ -38,9 +47,9 @@ public function setFields(array $fields): DocumentsQuery
*
* @param list<non-empty-string|list<non-empty-string>> $filter a filter expression written as an array of strings
*
* @return DocumentsQuery the updated DocumentsQuery instance
* @return $this the updated DocumentsQuery instance
*/
public function setFilter(array $filter): DocumentsQuery
public function setFilter(array $filter): self
{
$this->filter = $filter;

Expand All @@ -49,8 +58,10 @@ public function setFilter(array $filter): DocumentsQuery

/**
* @param bool|null $retrieveVectors boolean value to show _vector details
*
* @return $this
*/
public function setRetrieveVectors(?bool $retrieveVectors): DocumentsQuery
public function setRetrieveVectors(?bool $retrieveVectors): self
{
$this->retrieveVectors = $retrieveVectors;

Expand All @@ -67,6 +78,17 @@ public function hasFilter(): bool
return isset($this->filter);
}

public function toArray(): array
{
return array_filter([
'offset' => $this->offset,
'limit' => $this->limit,
'filter' => $this->filter,
'fields' => $this->getFields(),
'retrieveVectors' => (null !== $this->retrieveVectors ? ($this->retrieveVectors ? 'true' : 'false') : null),
], static function ($item) { return null !== $item; });
}

/**
* Prepares fields for request
* Fix for 1.2 document/fetch.
Expand All @@ -75,27 +97,16 @@ public function hasFilter(): bool
*
* @return array|string|null
*/
private function fields()
private function getFields()
{
if (!isset($this->fields)) {
return null;
}

if ($this->hasFilter()) {
return $this->fields;
} else {
return implode(',', $this->fields);
}
}

public function toArray(): array
{
return array_filter([
'offset' => $this->offset ?? null,
'limit' => $this->limit ?? null,
'filter' => $this->filter ?? null,
'fields' => $this->fields(),
'retrieveVectors' => (null !== $this->retrieveVectors ? ($this->retrieveVectors ? 'true' : 'false') : null),
], function ($item) { return null !== $item; });
return implode(',', $this->fields);
}
}
27 changes: 21 additions & 6 deletions src/Contracts/FacetSearchQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,50 @@ class FacetSearchQuery
private ?string $facetQuery = null;
private ?string $facetName = null;

public function setQuery(string $q): FacetSearchQuery
/**
* @return $this
*/
public function setQuery(string $q): self
{
$this->q = $q;

return $this;
}

public function setMatchingStrategy(string $matchingStrategy): FacetSearchQuery
/**
* @return $this
*/
public function setMatchingStrategy(string $matchingStrategy): self
{
$this->matchingStrategy = $matchingStrategy;

return $this;
}

public function setFilter(array $filter): FacetSearchQuery
/**
* @return $this
*/
public function setFilter(array $filter): self
{
$this->filter = $filter;

return $this;
}

public function setFacetQuery(string $facetQuery): FacetSearchQuery
/**
* @return $this
*/
public function setFacetQuery(string $facetQuery): self
{
$this->facetQuery = $facetQuery;

return $this;
}

public function setFacetName(string $facetName): FacetSearchQuery
/**
* @return $this
*/
public function setFacetName(string $facetName): self
{
$this->facetName = $facetName;

Expand All @@ -55,6 +70,6 @@ public function toArray(): array
'filter' => $this->filter,
'facetQuery' => $this->facetQuery,
'facetName' => $this->facetName,
], function ($item) { return null !== $item; });
], static function ($item) { return null !== $item; });
}
}
5 changes: 4 additions & 1 deletion src/Contracts/FederationOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ class FederationOptions
{
private ?float $weight = null;

public function setWeight(float $weight): FederationOptions
/**
* @return $this
*/
public function setWeight(float $weight): self
{
$this->weight = $weight;

Expand Down
9 changes: 7 additions & 2 deletions src/Contracts/HybridSearchOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ class HybridSearchOptions
*/
private ?string $embedder = null;

public function setSemanticRatio(float $ratio): HybridSearchOptions
/**
* @return $this
*/
public function setSemanticRatio(float $ratio): self
{
$this->semanticRatio = $ratio;

Expand All @@ -22,8 +25,10 @@ public function setSemanticRatio(float $ratio): HybridSearchOptions

/**
* @param non-empty-string $embedder
*
* @return $this
*/
public function setEmbedder(string $embedder): HybridSearchOptions
public function setEmbedder(string $embedder): self
{
$this->embedder = $embedder;

Expand Down
20 changes: 13 additions & 7 deletions src/Contracts/IndexesQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@

class IndexesQuery
{
private int $offset;
private int $limit;
private ?int $offset = null;
private ?int $limit = null;

public function setOffset(int $offset): IndexesQuery
/**
* @return $this
*/
public function setOffset(int $offset): self
{
$this->offset = $offset;

return $this;
}

public function setLimit(int $limit): IndexesQuery
/**
* @return $this
*/
public function setLimit(int $limit): self
{
$this->limit = $limit;

Expand All @@ -26,8 +32,8 @@ public function setLimit(int $limit): IndexesQuery
public function toArray(): array
{
return array_filter([
'offset' => $this->offset ?? null,
'limit' => $this->limit ?? null,
], function ($item) { return null != $item || is_numeric($item); });
'offset' => $this->offset,
'limit' => $this->limit,
], static function ($item) { return null !== $item; });
}
}
20 changes: 13 additions & 7 deletions src/Contracts/KeysQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@

class KeysQuery
{
private int $offset;
private int $limit;
private ?int $offset = null;
private ?int $limit = null;

public function setOffset(int $offset): KeysQuery
/**
* @return $this
*/
public function setOffset(int $offset): self
{
$this->offset = $offset;

return $this;
}

public function setLimit(int $limit): KeysQuery
/**
* @return $this
*/
public function setLimit(int $limit): self
{
$this->limit = $limit;

Expand All @@ -26,8 +32,8 @@ public function setLimit(int $limit): KeysQuery
public function toArray(): array
{
return array_filter([
'offset' => $this->offset ?? null,
'limit' => $this->limit ?? null,
], function ($item) { return null != $item || is_numeric($item); });
'offset' => $this->offset,
'limit' => $this->limit,
], static function ($item) { return null !== $item; });
}
}
10 changes: 8 additions & 2 deletions src/Contracts/MultiSearchFederation.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ class MultiSearchFederation
private ?int $limit = null;
private ?int $offset = null;

public function setLimit(int $limit): MultiSearchFederation
/**
* @return $this
*/
public function setLimit(int $limit): self
{
$this->limit = $limit;

return $this;
}

public function setOffset(int $offset): MultiSearchFederation
/**
* @return $this
*/
public function setOffset(int $offset): self
{
$this->offset = $offset;

Expand Down
Loading

0 comments on commit 71fa596

Please sign in to comment.