Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
// This is based on the `@Symfony` rule set documented in `vendor/friendsofphp/php-cs-fixer/doc/ruleSets/Symfony.rst`.

$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/lib');
->in([
__DIR__ . '/lib',
__DIR__ . '/Tests',
]);

return (new PhpCsFixer\Config())
->setRules([
Expand Down
3 changes: 1 addition & 2 deletions Tests/Unit/FinTsTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ protected function setUpConnection()
+ strlen($mockMiddle) + strlen($hnvsd) + strlen($mockSuffix);
$newLength = str_pad($newLength, HNHBKv3::NACHRICHTENGROESSE_LENGTH, '0', STR_PAD_LEFT);
return $mockPrefix . $newLength . $mockMiddle . $hnvsd . $mockSuffix;
} else {
return $mockResponse;
}
return $mockResponse;
});
return $this->connection;
}
Expand Down
15 changes: 7 additions & 8 deletions lib/Fhp/FinTs.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public function execute(BaseAction $action): void
$message = MessageBuilder::create()->add($requestSegments);

// Add HKTAN for authentication if necessary.
if (!($this->getSelectedTanMode() instanceof NoPsd2TanMode)) {
if (!$this->getSelectedTanMode() instanceof NoPsd2TanMode) {
if (($needTanForSegment = $action->getNeedTanForSegment()) !== null) {
$message->add(HKTANFactory::createProzessvariante2Step1(
$this->requireTanMode(), $this->selectedTanMedium, $needTanForSegment));
Expand Down Expand Up @@ -421,11 +421,10 @@ private function processServerResponse(BaseAction $action, Message $response, ?H
if ($confirmationRequest->getVerificationResult() === VopVerificationResult::CompletedFullMatch) {
// If someone hits this branch in practice, we can implement it.
throw new UnsupportedException('Combined VOP match confirmation and TAN request');
} else {
throw new UnexpectedResponseException(
'Unexpected TAN request on VOP result: ' . $confirmationRequest->getVerificationResult()
);
}
throw new UnexpectedResponseException(
'Unexpected TAN request on VOP result: ' . $confirmationRequest->getVerificationResult()
);
}
}
}
Expand Down Expand Up @@ -684,7 +683,7 @@ public function pollAction(BaseAction $action): void
public function confirmVop(BaseAction $action): void
{
$vopConfirmationRequest = $action->getVopConfirmationRequest();
if (!($vopConfirmationRequest instanceof VopConfirmationRequestImpl)) {
if (!$vopConfirmationRequest instanceof VopConfirmationRequestImpl) {
throw new \InvalidArgumentException('Unexpected type: ' . gettype($vopConfirmationRequest));
}
// We need to send the original request again, plus HKVPA as the confirmation.
Expand All @@ -697,7 +696,7 @@ public function confirmVop(BaseAction $action): void
->add(VopHelper::createHKVPAForConfirmation($vopConfirmationRequest));

// Add HKTAN for authentication if necessary.
if (!($this->getSelectedTanMode() instanceof NoPsd2TanMode)) {
if (!$this->getSelectedTanMode() instanceof NoPsd2TanMode) {
if (($needTanForSegment = $action->getNeedTanForSegment()) !== null) {
$message->add(HKTANFactory::createProzessvariante2Step1(
$this->requireTanMode(), $this->selectedTanMedium, $needTanForSegment));
Expand Down Expand Up @@ -930,7 +929,7 @@ private function ensureSynchronized(): void
// banks that don't support PSD2, we just keep the dummy TAN mode, as they wouldn't even understand 999.
$oldTanMode = $this->selectedTanMode;
$oldTanMedium = $this->selectedTanMedium;
if (!($this->selectedTanMode instanceof NoPsd2TanMode)) {
if (!$this->selectedTanMode instanceof NoPsd2TanMode) {
$this->selectedTanMode = null;
}
$this->selectedTanMedium = null;
Expand Down
6 changes: 2 additions & 4 deletions lib/Fhp/Model/StatementOfAccount/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,8 @@ public function getMainDescription(): string
{
if (array_key_exists('SVWZ', $this->structuredDescription)) {
return $this->structuredDescription['SVWZ'];
} else {
return '';
}
return '';
}

/**
Expand All @@ -266,9 +265,8 @@ public function getEndToEndID(): string
{
if (array_key_exists('EREF', $this->structuredDescription)) {
return $this->structuredDescription['EREF'];
} else {
return '';
}
return '';
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Fhp/Protocol/BPD.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function getBankName()
public function getAllSupportedParameters(string $type): array
{
return array_filter($this->parameters[$type] ?? [], function (BaseSegment $segment) {
return !($segment instanceof AnonymousSegment);
return !$segment instanceof AnonymousSegment;
});
}

Expand All @@ -101,7 +101,7 @@ public function getLatestSupportedParameters(string $type): ?BaseSegment
return null;
}
foreach ($this->parameters[$type] as $segment) {
if (!($segment instanceof AnonymousSegment)) {
if (!$segment instanceof AnonymousSegment) {
return $segment;
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Fhp/Protocol/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,19 +320,19 @@ public static function parse(string $rawMessage): Message
// Message header and footer must always be there, or something went badly wrong.
$result->header = $segments[0];
$result->footer = $segments[count($segments) - 1];
if (!($result->header instanceof HNHBKv3)) {
if (!$result->header instanceof HNHBKv3) {
$actual = $result->header->getName();
throw new \InvalidArgumentException("Expected first segment to be HNHBK, but got $actual: $rawMessage");
}
if (!($result->footer instanceof HNHBSv1)) {
if (!$result->footer instanceof HNHBSv1) {
$actual = $result->footer->getName();
throw new \InvalidArgumentException("Expected last segment to be HNHBS, but got $actual: $rawMessage");
}

// Check if there's an encryption header and "encrypted" data.
// Section B.8 specifies that there are exactly 4 segments: HNHBK, HNVSK, HNVSD, HNHBS.
if (count($segments) === 4 && $segments[1] instanceof HNVSKv3) {
if (!($segments[2] instanceof HNVSDv1)) {
if (!$segments[2] instanceof HNVSDv1) {
throw new \InvalidArgumentException("Expected third segment to be HNVSD: $rawMessage");
}
$result->wrapperSegments = $segments;
Expand Down
5 changes: 2 additions & 3 deletions lib/Fhp/Segment/BaseSegment.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,9 @@ public static function parse(string $rawSegment): static
if (static::class === BaseSegment::class) {
// Called as BaseSegment::parse(), so we need to determine the right segment type/class.
return Parser::detectAndParseSegment($rawSegment);
} else {
// The parse() function was called on the segment subclass itself.
return Parser::parseSegment($rawSegment, static::class);
}
// The parse() function was called on the segment subclass itself.
return Parser::parseSegment($rawSegment, static::class);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions lib/Fhp/Segment/Common/Sdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ public function getAmount(): float
{
if ($this->sollHabenKennzeichen === self::CREDIT) {
return $this->betrag->wert;
} elseif ($this->sollHabenKennzeichen === self::DEBIT) {
}

if ($this->sollHabenKennzeichen === self::DEBIT) {
return -1 * $this->betrag->wert;
} else {
throw new \InvalidArgumentException("Invalid sollHabenKennzeichen: $this->sollHabenKennzeichen");
}

throw new \InvalidArgumentException("Invalid sollHabenKennzeichen: $this->sollHabenKennzeichen");
}

public function getCurrency(): string
Expand Down
2 changes: 1 addition & 1 deletion lib/Fhp/Segment/SegmentDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function __construct(string $class)
public function validateObject($obj): void // Override
{
parent::validateObject($obj);
if (!($obj instanceof BaseSegment)) {
if (!$obj instanceof BaseSegment) {
throw new \InvalidArgumentException('Expected sub-class of BaseSegment, got ' . gettype($obj));
}
if ($obj->getName() !== $this->kennung) {
Expand Down
8 changes: 5 additions & 3 deletions lib/Fhp/Syntax/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,13 @@ private static function parseSegmentElement(string $rawElement, ElementDescripto
{
if (is_string($descriptor->type)) { // Scalar value / DE
return static::parseDataElement($rawElement, $descriptor->type);
} elseif ($descriptor->type->getName() === Bin::class) {
}

if ($descriptor->type->getName() === Bin::class) {
return static::parseBinaryBlock($rawElement);
} else {
return static::parseDeg($rawElement, $descriptor->type->name, $descriptor->optional);
}

return static::parseDeg($rawElement, $descriptor->type->name, $descriptor->optional);
}

/**
Expand Down
25 changes: 17 additions & 8 deletions lib/Fhp/Syntax/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,23 @@ public static function serializeDataElement($value, string $type): string
if ($value === null) {
return '';
}

if ($type === 'int' || $type === 'integer' || $type === 'string') {
// Convert UTF-8 (PHP's encoding) to ISO-8859-1 (FinTS wire format encoding)
return static::escape(mb_convert_encoding(strval($value), 'ISO-8859-1', 'UTF-8'));
} elseif ($type === 'float') {
}

if ($type === 'float') {
// Format with fixed 2 decimal places (there has to be some limit, and the specification does not specify
// one), then trim zeros from the end.
return rtrim(number_format($value, 2, ',', ''), '0');
} elseif ($type === 'bool' || $type === 'boolean') {
}

if ($type === 'bool' || $type === 'boolean') {
return $value ? 'J' : 'N';
} else {
throw new \RuntimeException("Unsupported type $type");
}

throw new \RuntimeException("Unsupported type $type");
}

/**
Expand Down Expand Up @@ -147,14 +152,18 @@ private static function serializeElement($value, $type, bool $fullySerialize)
{
if (is_string($type)) { // Scalar value / DE
return static::serializeDataElement($value, $type);
} elseif ($type->getName() === Bin::class) {
}

if ($type->getName() === Bin::class) {
/* @var Bin|null $value */
return $value === null ? '' : $value->toString();
} elseif ($fullySerialize) {
}

if ($fullySerialize) {
return static::serializeDeg($value, DegDescriptor::get($type->name));
} else {
return static::serializeElements($value, DegDescriptor::get($type->name));
}

return static::serializeElements($value, DegDescriptor::get($type->name));
}

/**
Expand Down