Skip to content

Commit

Permalink
Fix phpstan errors
Browse files Browse the repository at this point in the history
Signed-off-by: Kim Pepper <[email protected]>
  • Loading branch information
kimpepper committed Dec 16, 2024
1 parent ea70d0e commit 33f0169
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 35 deletions.
8 changes: 2 additions & 6 deletions src/OpenSearch/EndpointInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,12 @@ public function setId(int|string|null $docID): static;

/**
* Get the body of the request.
*
* @return array|string|null
*/
public function getBody(): array|string|null;
public function getBody(): string|iterable|null;

/**
* Set the body of the request.
*
* @param array<string,mixed> $body
*/
public function setBody(array $body): static;
public function setBody(string|iterable|null $body): static;

}
4 changes: 2 additions & 2 deletions src/OpenSearch/Endpoints/AbstractEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ public function setId(int|string|null $docID): static
return $this;
}

public function getBody(): array|string|null
public function getBody(): string|iterable|null
{
return $this->body;
}

public function setBody(array|string $body): static
public function setBody(string|iterable|null $body): static
{
$this->body = $body;

Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/AsyncSearch/Submit.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function getMethod(): string
return 'POST';
}

public function setBody($body): Submit
public function setBody($body): static
{
if (isset($body) !== true) {
return $this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function getMethod(): string
return 'POST';
}

public function setBody($body): PreviewTransform
public function setBody($body): static
{
if (isset($body) !== true) {
return $this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getMethod(): string
return 'PUT';
}

public function setBody($body): PutTransform
public function setBody($body): static
{
if (isset($body) !== true) {
return $this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getMethod(): string
return 'POST';
}

public function setBody($body): UpdateTransform
public function setBody($body): static
{
if (isset($body) !== true) {
return $this;
Expand All @@ -60,7 +60,7 @@ public function setBody($body): UpdateTransform
return $this;
}

public function setTransformId($transform_id): UpdateTransform
public function setTransformId($transform_id): static
{
if (isset($transform_id) !== true) {
return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSearch/Endpoints/Monitoring/Bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getMethod(): string
return 'POST';
}

public function setBody($body): Bulk
public function setBody($body): static
{
if (isset($body) !== true) {
return $this;
Expand Down
6 changes: 3 additions & 3 deletions src/OpenSearch/Endpoints/SearchableSnapshots/Mount.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function getMethod(): string
return 'POST';
}

public function setBody($body): Mount
public function setBody($body): static
{
if (isset($body) !== true) {
return $this;
Expand All @@ -64,7 +64,7 @@ public function setBody($body): Mount
return $this;
}

public function setRepository($repository): Mount
public function setRepository($repository): static
{
if (isset($repository) !== true) {
return $this;
Expand All @@ -74,7 +74,7 @@ public function setRepository($repository): Mount
return $this;
}

public function setSnapshot($snapshot): Mount
public function setSnapshot($snapshot): static
{
if (isset($snapshot) !== true) {
return $this;
Expand Down
10 changes: 4 additions & 6 deletions tests/Endpoints/AbstractEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,17 @@

namespace OpenSearch\Tests\Endpoints;

use OpenSearch\EndpointInterface;
use OpenSearch\Endpoints\AbstractEndpoint;
use OpenSearch\Endpoints\EndpointInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* @covers \OpenSearch\Endpoints\AbstractEndpoint
*/
class AbstractEndpointTest extends \PHPUnit\Framework\TestCase
class AbstractEndpointTest extends TestCase
{
/**
* @var EndpointInterface&MockObject
*/
private $endpoint;
private EndpointInterface|MockObject $endpoint;

protected function setUp(): void
{
Expand Down
24 changes: 13 additions & 11 deletions util/template/set-bulk-body
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@

public function setBody($body): static
public function setBody(string|iterable|null $body): static
{
if (isset($body) !== true) {
if (is_null($body)) {
return $this;
}
if (is_array($body) === true || $body instanceof Traversable) {
foreach ($body as $item) {
$this->body .= $this->serializer->serialize($item) . "\n";

if (is_string($body)) {
if (!str_ends_with($body, "\n")) {
$body .= "\n";
}
} elseif (is_string($body)) {
$this->body = $body;
if (substr($body, -1) != "\n") {
$this->body .= "\n";
}
} else {
throw new InvalidArgumentException("Body must be an array, traversable object or string");
return $this;
}

// Must be an iterable.
foreach ($body as $item) {
$this->body .= $this->serializer->serialize($item) . "\n";
}

return $this;
}
2 changes: 1 addition & 1 deletion util/template/set-part
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

public function set:Part($:part): static
{
if (isset($:part) !== true) {
if (is_null($:part)) {
return $this;
}
$this->:part = $:part;
Expand Down

0 comments on commit 33f0169

Please sign in to comment.