Skip to content

Commit

Permalink
Cleanup, tweaks to comply with PSR-12
Browse files Browse the repository at this point in the history
  • Loading branch information
olssonm committed Jan 8, 2024
1 parent d3c5fd6 commit cedcba3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
23 changes: 18 additions & 5 deletions src/Api/AbstractResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,27 @@ public function __construct(ClientInterface $client)

/**
* Retrieve resource
*
* @param $transaction
* @return mixed
*/
abstract public function get($transaction);
abstract public function get($transaction); // @phpstan-ignore-line

/**
* Create resource
*
* @param $transaction
* @return mixed
*/
abstract public function create($transaction);
abstract public function create($transaction); // @phpstan-ignore-line

/**
* Cancel transaction
*
* @param $transaction
* @return mixed
*/
abstract public function cancel($transaction);
abstract public function cancel($transaction); // @phpstan-ignore-line

/**
* Main API caller
Expand All @@ -44,8 +53,12 @@ abstract public function cancel($transaction);
* @return ResponseInterface
* @throws ClientException|ServerException|ValidationException
*/
protected function request(string $verb, string $uri, array $headers = [], string|null $payload = null) : ResponseInterface
{
protected function request(
string $verb,
string $uri,
array $headers = [],
string|null $payload = null
): ResponseInterface {
$request = new Psr7Request(
$verb,
$uri,
Expand Down
7 changes: 6 additions & 1 deletion src/Api/Payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ public function get($payment): Payment
*/
public function create($payment): PaymentResult
{
$response = $this->request('PUT', sprintf('v2/paymentrequests/%s', $payment->id), [], (string) json_encode($payment));
$response = $this->request(
'PUT',
sprintf('v2/paymentrequests/%s', $payment->id),
[],
(string) json_encode($payment)
);

$location = $response->getHeaderLine('Location');
$token = $response->getHeaderLine('PaymentRequestToken');
Expand Down
6 changes: 3 additions & 3 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,18 @@ public function setup(

/**
* Return the clients call-history
*
*
* @return array<mixed>
*/
public function getHistory() : array
public function getHistory(): array
{
return $this->history;
}

/**
* @param array<mixed> $args
*/
public function __call(string $method, array $args) : mixed
public function __call(string $method, array $args): mixed
{
if (
!is_object($args[0]) ||
Expand Down
18 changes: 9 additions & 9 deletions src/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,42 +31,42 @@ public function __set(string $key, mixed $value)
$this->attributes[$key] = $value;
}

public function __get(string $key) : mixed
public function __get(string $key): mixed
{
return $this->attributes[$key];
}

public function __isset(string $key) : bool
public function __isset(string $key): bool
{
return isset($this->attributes[$key]);
}

#[\ReturnTypeWillChange]
public function offsetSet($key, $value) : void
public function offsetSet($key, $value): void
{
$this->{$key} = $value;
}

#[\ReturnTypeWillChange]
public function offsetExists($key) : bool
public function offsetExists($key): bool
{
return \array_key_exists($key, $this->attributes);
}

#[\ReturnTypeWillChange]
public function offsetUnset($key) : void
public function offsetUnset($key): void
{
unset($this->attributes[$key]);
}

#[\ReturnTypeWillChange]
public function offsetGet($key) : mixed
public function offsetGet($key): mixed
{
return \array_key_exists($key, $this->attributes) ? $this->attributes[$key] : null;
}

#[\ReturnTypeWillChange]
public function count() : int
public function count(): int
{
return \count($this->attributes);
}
Expand All @@ -75,15 +75,15 @@ public function count() : int
* @return array<string, mixed>
*/
#[\ReturnTypeWillChange]
public function jsonSerialize() : array
public function jsonSerialize(): array
{
return $this->toArray();
}

/**
* @return array<mixed>
*/
public function toArray() : array
public function toArray(): array
{
return $this->attributes;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Util/Id.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

namespace Olssonm\Swish\Util;

use GuzzleHttp\Psr7\Response;
use Psr\Http\Message\ResponseInterface;

class Id
{
/**
* Parse the ID from the response's Location-header.
*
* @param Response $response
* @param ResponseInterface $response
* @return null|string
*/
public static function parse(Response $response): ?string
public static function parse(ResponseInterface $response): ?string
{
$url = parse_url($response->getHeaderLine('Location'), PHP_URL_PATH);
return is_string($url) ? pathinfo($url, PATHINFO_BASENAME) : null;
Expand Down

0 comments on commit cedcba3

Please sign in to comment.