Skip to content

Commit

Permalink
Code: polished
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Sep 13, 2022
1 parent ef5080e commit 16659c5
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
12 changes: 10 additions & 2 deletions src/Api/Entity/Payment.php
Expand Up @@ -7,6 +7,7 @@
use Contributte\GopayInline\Api\Objects\Parameter;
use Contributte\GopayInline\Api\Objects\Payer;
use Contributte\GopayInline\Api\Objects\Target;
use Contributte\GopayInline\Exception\InvalidStateException;
use Money\Money;

class Payment extends AbstractEntity
Expand Down Expand Up @@ -89,11 +90,18 @@ public function setAmount(Money $amount): void
}

/**
* @psalm-return non-empty-string
* @return non-empty-string
*/
public function getCurrency(): string
{
return $this->amount->getCurrency()->getCode();
/** @var string $code */
$code = $this->amount->getCurrency()->getCode();

if ($code === '') {
throw new InvalidStateException('Currency code cannot be empty');
}

return $code;
}

public function getOrderNumber(): ?string
Expand Down
12 changes: 10 additions & 2 deletions src/Api/Objects/Eet.php
Expand Up @@ -2,6 +2,7 @@

namespace Contributte\GopayInline\Api\Objects;

use Contributte\GopayInline\Exception\InvalidStateException;
use Money\Currency;
use Money\Money;

Expand Down Expand Up @@ -112,11 +113,18 @@ public function getTaxReducedRateSecondInCents(): ?string
}

/**
* @psalm-return non-empty-string
* @return non-empty-string
*/
public function getCurrency(): string
{
return $this->sum->getCurrency()->getCode();
/** @var string $code */
$code = $this->sum->getCurrency()->getCode();

if ($code === '') {
throw new InvalidStateException('Currency code cannot be empty');
}

return $code;
}

public function getTaxBaseNoVat(): ?Money
Expand Down
4 changes: 0 additions & 4 deletions src/Bridges/Nette/DI/GopayExtension.php
Expand Up @@ -2,10 +2,6 @@

namespace Contributte\GopayInline\Bridges\Nette\DI;

if (!class_exists('\Nette\DI\Definitions\Statement')) {
class_alias('\Nette\DI\Statement', '\Nette\DI\Definitions\Statement');
}

use Contributte\GopayInline\Client;
use Contributte\GopayInline\Config;
use Nette\DI\CompilerExtension;
Expand Down
3 changes: 2 additions & 1 deletion src/Http/Response.php
Expand Up @@ -6,6 +6,7 @@
use Countable;
use IteratorAggregate;
use RecursiveArrayIterator;
use ReturnTypeWillChange;

/**
* @property-read array $data
Expand Down Expand Up @@ -103,7 +104,7 @@ public function offsetExists($offset): bool
* @param mixed $offset
* @return mixed
*/
#[\ReturnTypeWillChange]
#[ReturnTypeWillChange]
public function offsetGet($offset)
{
if ($this->data === null) {
Expand Down
6 changes: 1 addition & 5 deletions src/Service/AbstractService.php
Expand Up @@ -80,23 +80,19 @@ protected function makeRequest(string $method, string $uri, ?array $data = null,

// Set-up method
switch ($method) {

// GET =========================================
case HttpClient::METHOD_GET:
$request->appendOpts([
CURLOPT_HTTPGET => true,
]);

break;

// POST ========================================
case HttpClient::METHOD_POST:
$request->appendOpts([
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $contentType === Http::CONTENT_FORM ? http_build_query((array) $data) : json_encode($data),
]);

break;

default:
throw new InvalidStateException('Unsupported http method');
}
Expand Down

0 comments on commit 16659c5

Please sign in to comment.