Skip to content

Commit

Permalink
Update ninjify/qa dependency, fix founded issues
Browse files Browse the repository at this point in the history
  • Loading branch information
trejjam committed Mar 24, 2019
1 parent 94094f9 commit e464a29
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 35 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -12,7 +12,7 @@
"ext-hash": "*"
},
"require-dev": {
"ninjify/qa": "^0.8.0",
"ninjify/qa": "^0.9.0",
"ninjify/nunjuck": "^0.2.1"
},
"suggest": {
Expand Down
8 changes: 8 additions & 0 deletions ruleset.xml
Expand Up @@ -60,6 +60,14 @@
<exclude-pattern>src/DataApi/Responses/Response.php</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.ControlStructures.ControlStructureSpacing.IncorrectLinesCountBeforeControlStructure">
<exclude-pattern>*</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.ControlStructures.RequireMultiLineTernaryOperator.MultiLineTernaryOperatorNotUsed">
<exclude-pattern>*</exclude-pattern>
</rule>

<!--Exclude folders -->
<exclude-pattern>/tests/tmp</exclude-pattern>
</ruleset>
2 changes: 0 additions & 2 deletions src/DataApi/DataApiObject.php
Expand Up @@ -154,12 +154,10 @@ public function offsetSet($offset, $value): void
$value = intval($value);

break;

case 'float':
$value = floatval($value);

break;

case 'bool':
$value = $value === '1';

Expand Down
6 changes: 2 additions & 4 deletions src/DataApi/Processors/Digester.php
Expand Up @@ -71,16 +71,14 @@ protected function processItem($value): string
if (Utils::isList($value)) {
return $this->processList($value);
}

return $this->processHash($value);
}

protected function convertValue($value): string
{
if (is_bool($value)) {
if ($value) {
return '1';
}
return '0';
return $value ? '1' : '0';
}

return strval($value);
Expand Down
1 change: 1 addition & 0 deletions src/DataApi/Processors/Processor.php
Expand Up @@ -39,6 +39,7 @@ protected function processItem(array $value, array $currentPath): array
if (Utils::isList($value)) {
return $this->processList($value, $currentPath);
}

return $this->processHash($value, $currentPath);
}

Expand Down
2 changes: 1 addition & 1 deletion src/DataApi/Responses/GetPaymentMethodsResponse.php
Expand Up @@ -22,14 +22,14 @@ public static function createFromResponse(
array $response
): self
{
/** @var GetPaymentMethodsResponse $instance */
$instance = parent::createFromResponse($response);
$instance->setAccountId($response['accountId']);

$methods = [];
foreach ($response['methods'] as $method) {
$methods[] = new MerchantAccountMethod($method);
}

$instance->setMethods($methods);

return $instance;
Expand Down
4 changes: 2 additions & 2 deletions src/DataApi/Responses/GetPaymentsResponse.php
Expand Up @@ -36,7 +36,7 @@ public static function createFromResponse(
foreach ($response['payments'] as $payment) {
$payments[] = new Payment($payment);
}
unset($payment);

$instance->setPayments($payments);

$pagination = new PaginationResponse($response['pagination']);
Expand All @@ -59,7 +59,7 @@ public function getPayments(): array
public function setPayments(array $payments = []): void
{
$this->payments = ValueFormatter::formatList(
'Tp\DataApi\Parameters\Payment',
Payment::class,
$payments
);
}
Expand Down
7 changes: 7 additions & 0 deletions src/DataApi/ValueFormatter.php
Expand Up @@ -24,6 +24,7 @@ public static function format(string $type, $value)
if ($isNull) {
return null;
}

$method = 'format' . ucfirst($type);
if (method_exists(self::class, $method)) {
return static::$method($value);
Expand All @@ -42,6 +43,7 @@ public static function formatInt(?int $value): ?int
if ($value === null) {
return null;
}

return intval($value);
}

Expand All @@ -50,6 +52,7 @@ public static function formatFloat(?float $value): ?float
if ($value === null) {
return null;
}

return floatval($value);
}

Expand All @@ -58,6 +61,7 @@ public static function formatBool(?bool $value): ?bool
if ($value === null) {
return null;
}

return boolval($value);
}

Expand All @@ -69,6 +73,7 @@ public static function formatString($value): ?string
if ($value === null) {
return null;
}

return strval($value);
}

Expand All @@ -80,11 +85,13 @@ public static function formatDateTime($value): ?DateTimeInterface
if ($value === null) {
return null;
}

if ($value === '0000-00-00 00:00:00') {
return null;
} elseif ($value instanceof DateTimeInterface) {
return $value;
}

return new DateTimeImmutable($value);
}

Expand Down
1 change: 1 addition & 0 deletions src/Helper/ButtonMerchant.php
Expand Up @@ -85,6 +85,7 @@ public function render(): string
if ($this->buttonStyle === null) {
return "<a href=\"{$targetUrl}\">{$this->buttonText}</a>";
}

$gateUrl = $this->payment->getMerchantConfig()->gateUrl;

$buttonStyle = rawurlencode($this->buttonStyle);
Expand Down
5 changes: 5 additions & 0 deletions src/Helper/RadioMerchant.php
Expand Up @@ -178,6 +178,7 @@ public function renderRadio(): string
if ($this->currency) {
$queryArgs['currency'] = $this->currency;
}

$queryArgs['signature'] = $this->createSignature($queryArgs);

$queryArgs = http_build_query($queryArgs);
Expand All @@ -188,10 +189,12 @@ public function renderRadio(): string
$out = "<link href=\"{$href}\" type=\"text/css\" rel=\"stylesheet\" />\n";
$out .= "<script type=\"text/javascript\">\n";
$out .= "\tvar thepayGateUrl = {$thepayGateUrl};\n";

if ($this->appendCode) {
$thepayAppendCode = Escaper::jsonEncode($this->appendCode);
$out .= "\tvar thepayAppendCode = {$thepayAppendCode};\n";
}

$out .= "</script>\n";

$src = "{$gateUrl}radiobuttons/js/jquery.js?v=" . time();
Expand Down Expand Up @@ -241,6 +244,7 @@ public function redirectOnlinePayment(
if (headers_sent()) {
throw new Exception('Redirect error - headers have been already sent');
}

$this->clearCookies();

// Output buffer must be empty for the redirect to be successful.
Expand All @@ -249,6 +253,7 @@ public function redirectOnlinePayment(
ob_end_clean();
$obCleaned = true;
}

if ($obCleaned) {
// If the output buffer was being used, start buffering again.
// Makes function’s behavior more consistent and predictable.
Expand Down
2 changes: 2 additions & 0 deletions src/Payment.php
Expand Up @@ -111,6 +111,7 @@ public function setValue(float $value): void
if ($value < 0) {
throw new InvalidParameterException('value');
}

$this->value = $value;
}

Expand Down Expand Up @@ -366,6 +367,7 @@ public function getArgs(): array
if ($this->deposit !== null) {
$input['deposit'] = $this->getDeposit() ? '1' : '0';
}

if ($this->isRecurring !== null) {
$input['isRecurring'] = $this->getIsRecurring() ? '1' : '0';
}
Expand Down
2 changes: 1 addition & 1 deletion src/PermanentPaymentResponse.php
Expand Up @@ -23,6 +23,7 @@ public function __construct(stdClass $data)
if (property_exists($data, 'errorDescription')) {
$this->errorDescription = $data->errorDescription;
}

if (
property_exists($data, 'paymentMethods') &&
$data->paymentMethods instanceof stdClass &&
Expand All @@ -38,7 +39,6 @@ public function __construct(stdClass $data)
$value->vs
);
}
unset($value);
}
}

Expand Down
18 changes: 7 additions & 11 deletions src/ReturnedPayment.php
Expand Up @@ -170,6 +170,7 @@ public function __construct(MerchantConfig $config, ?array $args = null)
if (!empty($args['merchantId'])) {
$this->requestMerchantId = intval($args['merchantId']);
}

if (!empty($args['accountId'])) {
$this->requestAccountId = intval($args['accountId']);
}
Expand All @@ -183,11 +184,7 @@ public function __construct(MerchantConfig $config, ?array $args = null)
}

foreach (self::$OPTIONAL_ARGS_DEFAULT as $arg => $defaultValue) {
if (!isset($args[$arg])) {
$this->{$arg} = $defaultValue;
} else {
$this->{$arg} = $args[$arg];
}
$this->{$arg} = $args[$arg] ?? $defaultValue;
}

foreach (self::$BOOL_ARGS as $key) {
Expand Down Expand Up @@ -232,8 +229,8 @@ public function verifySignature(?string $signature = null): bool
if ($signature === null) {
$signature = $this->signature;
}
// Compute the signature for arguments specified, and compare
// it to the specified signature.

// Compute the signature for specified arguments, and compare it to the specified signature.

$out = [];
$out[] = 'merchantId=' . $this->getRequestMerchantId();
Expand All @@ -251,13 +248,15 @@ public function verifySignature(?string $signature = null): bool
$out[] = sprintf('%s=%s', $property, $value);
}
}

$out[] = 'password=' . $this->getMerchantConfig()->password;

$sig = $this->hashFunction(implode('&', $out));

if ($sig === $signature) {
return true;
}

throw new InvalidSignatureException();
}

Expand All @@ -279,10 +278,7 @@ public function getRequestAccountId(): ?int
*/
public function getCurrency(): string
{
if ($this->currency === null) {
return 'CZK';
}
return $this->currency;
return parent::getCurrency() ?? 'CZK';
}

/**
Expand Down
21 changes: 8 additions & 13 deletions src/Utils.php
Expand Up @@ -34,14 +34,9 @@ public static function toArrayRecursive(array $value): array
{
$array = [];
foreach ($value as $k => $v) {
if (
is_array($v)
|| $v instanceof stdClass
) {
$array[$k] = static::toArrayRecursive((array) $v);
} else {
$array[$k] = $v;
}
$array[$k] = is_array($v) || $v instanceof stdClass
? static::toArrayRecursive((array) $v)
: $v;
}

return $array;
Expand All @@ -54,11 +49,11 @@ public static function toArrayRecursive(array $value): array
public static function isList(array $array): bool
{
$count = count($array);
if ($count) {
$range = range(0, $count - 1);
} else {
$range = [];
}

$range = $count
? range(0, $count - 1)
: [];

$keys = array_keys($array);

return $keys === $range;
Expand Down

0 comments on commit e464a29

Please sign in to comment.