Skip to content

Commit

Permalink
Fix issues found after updating psalm
Browse files Browse the repository at this point in the history
  • Loading branch information
christeredvartsen committed Jan 23, 2023
1 parent 7ccd5a0 commit d59769e
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function addImageFromUrl(string $url): AddedImage
try {
$blob = $this->httpClient->get($url)->getBody()->getContents();
} catch (BadResponseException $e) {
throw new RuntimeException('Unable to fetch file at URL: ' . $url, (int) $e->getCode(), $e);
throw new RuntimeException('Unable to fetch file at URL: ' . $url, $e->getCode(), $e);
}

return $this->addImageFromString($blob);
Expand Down Expand Up @@ -381,7 +381,7 @@ public function getImageDataFromUrl(ImageUrl $url): string
try {
$blob = $this->httpClient->get($url)->getBody()->getContents();
} catch (BadResponseException $e) {
throw new RuntimeException('Unable to fetch file at URL: ' . $url, (int) $e->getCode(), $e);
throw new RuntimeException('Unable to fetch file at URL: ' . $url, $e->getCode(), $e);
}

return $blob;
Expand Down
3 changes: 3 additions & 0 deletions src/Response/AccessControlRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use Iterator;
use Psr\Http\Message\ResponseInterface;

/**
* @template-implements Iterator<int, AccessControlRule>
*/
class AccessControlRules extends ApiResponse implements Iterator, Countable
{
private int $iteratorIndex = 0;
Expand Down
5 changes: 4 additions & 1 deletion src/Response/ApiResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use ImboClient\Exception\RuntimeException;
use Psr\Http\Message\ResponseInterface;

/**
* @template-implements ArrayAccess<string, mixed>
*/
abstract class ApiResponse implements ArrayAccess
{
private ?ResponseInterface $response = null;
Expand Down Expand Up @@ -41,7 +44,7 @@ public function offsetExists($offset): bool
* @param string $offset
* @return mixed
*/
public function offsetGet($offset)
public function offsetGet($offset): mixed
{
$offsets = $this->getArrayOffsets();
return array_key_exists($offset, $offsets) ? $offsets[$offset]() : null;
Expand Down
3 changes: 3 additions & 0 deletions src/Response/Images.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use Iterator;
use Psr\Http\Message\ResponseInterface;

/**
* @template-implements Iterator<int, Image>
*/
class Images extends ApiResponse implements Iterator, Countable
{
private int $iteratorIndex = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/Response/ResourceGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Iterator;
use Psr\Http\Message\ResponseInterface;

/**
* @template-implements Iterator<int, ResourceGroup>
*/
class ResourceGroups extends ApiResponse implements Iterator, Countable
{
private int $iteratorIndex = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/Url/ImageUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public function convert(string $extension): self
$extensions = implode('|', $this->validExtensions);
$pathWithNoExtension = preg_replace('#(\.(' . $extensions . '))$#', '', $this->getPath());

/** @var static */
return $this->withPath(
$pathWithNoExtension . '.' . $extension,
);
Expand Down Expand Up @@ -477,6 +478,7 @@ public function withTransformation(string $transformation): self
}

$query['t'][] = $transformation;
/** @var static */
return $this->withQuery(http_build_query($query));
}

Expand All @@ -487,6 +489,7 @@ public function reset(): self
'',
$this->getPath(),
);
/** @var static */
return $this
->withPath($pathWithNoExtension)
->withQuery('');
Expand Down
2 changes: 1 addition & 1 deletion tests/Response/AccessControlRulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function testArrayAccess(): void
$this->assertArrayHasKey('rules', $accessControlRules);
$this->assertArrayNotHasKey('foobar', $accessControlRules);

/** @var array<AccessControlRule> */
/** @var array<int, AccessControlRule> */
$acrs = $accessControlRules['rules'];

$this->assertSame(2, count($acrs));
Expand Down
2 changes: 1 addition & 1 deletion tests/Response/ResourceGroupsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function testArrayAccess(): void
$this->assertArrayHasKey('groups', $groups);
$this->assertArrayNotHasKey('foobar', $groups);

/** @var array<ResourceGroup> */
/** @var array<int, ResourceGroup> */
$rg = $groups['groups'];

$this->assertSame(3, count($rg));
Expand Down

0 comments on commit d59769e

Please sign in to comment.