Skip to content

Commit

Permalink
Optimized code
Browse files Browse the repository at this point in the history
  • Loading branch information
Norbert Huemmer committed Jul 30, 2020
1 parent a8c5c12 commit 5c91d2d
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 65 deletions.
30 changes: 16 additions & 14 deletions lib/Fhp/Action/GetSEPADirectDebitParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
class GetSEPADirectDebitParameters extends BaseAction
{
const SEQUENCE_TYPES = ['FRST', 'OOFF', 'FNAL', 'RCUR'];
const CORE_TYPES = ['CORE', 'COR1', 'B2B'];
const DIRECT_DEBIT_TYPES = ['CORE', 'COR1', 'B2B'];

/** @var string */
private $coreType;
private $directDebitType;

/** @var string */
private $seqType;
Expand All @@ -28,49 +28,51 @@ class GetSEPADirectDebitParameters extends BaseAction
/** @var HIDXES */
private $hidxes;

public static function create(string $seqType, bool $singleDirectDebit, string $coreType = 'CORE')
public static function create(string $seqType, bool $singleDirectDebit, string $directDebitType = 'CORE')
{
if (!in_array($coreType, self::CORE_TYPES)) {
throw new \InvalidArgumentException('Unknown CORE type, possible values are ' . implode(', ', self::CORE_TYPES));
if (!in_array($directDebitType, self::DIRECT_DEBIT_TYPES)) {
throw new \InvalidArgumentException('Unknown CORE type, possible values are ' . implode(', ', self::DIRECT_DEBIT_TYPES));
}
if (!in_array($seqType, self::SEQUENCE_TYPES)) {
throw new \InvalidArgumentException('Unknown SEPA sequence type, possible values are ' . implode(', ', self::SEQUENCE_TYPES));
}
$result = new GetSEPADirectDebitParameters();
$result->coreType = $coreType;
$result->directDebitType = $directDebitType;
$result->seqType = $seqType;
$result->singleDirectDebit = $singleDirectDebit;
return $result;
}

public static function getHixxesSegmentName(string $coreType, bool $singleDirectDebit): string
public static function getHixxesSegmentName(string $directDebitType, bool $singleDirectDebit): string
{
switch ($coreType) {
switch ($directDebitType) {
case 'CORE':
case 'COR1':
return $singleDirectDebit ? 'HIDSES' : 'HIDMES';
case 'B2B':
return $singleDirectDebit ? 'HIBSES' : 'HIBMES';
default:
throw new \InvalidArgumentException('Unknown CORE type, possible values are ' . implode(', ', self::CORE_TYPES));
throw new \InvalidArgumentException('Unknown DirectDebitTypes type, possible values are ' . implode(', ', self::DIRECT_DEBIT_TYPES));
}
}

/** {@inheritdoc} */
protected function createRequest(BPD $bpd, ?UPD $upd)
{
$this->hidxes = $bpd->requireLatestSupportedParameters(static::getHixxesSegmentName($this->coreType, $this->singleDirectDebit));

$this->hidxes = $bpd->requireLatestSupportedParameters(static::getHixxesSegmentName($this->directDebitType, $this->singleDirectDebit));
$this->isDone = true;

return []; // No request to the bank required
}

/**
* @return MinimaleVorlaufzeitSEPALastschrift|null The information about the lead time for the given Sequence Type and Core Type
* @return MinimaleVorlaufzeitSEPALastschrift|null The information about the lead time for the given Sequence Type and Direct Debit Type
*/
public function getMinimalLeadTime(): ?MinimaleVorlaufzeitSEPALastschrift
{
return $this->hidxes->getParameter()->getMinimalLeadTime($this->seqType, $this->coreType);
$parsed = $this->hidxes->getParameter()->getMinimalLeadTime($this->seqType);
if ($parsed instanceof MinimaleVorlaufzeitSEPALastschrift) {
return $parsed;
}
return $parsed[$this->directDebitType] ?? null;
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ParameterTerminierteSEPAFirmenEinzellastschriftEinreichenV1 extends BaseDe
/** @var int */
public $maximaleVorlaufzeitFRSTOOFF;

public function getMinimalLeadTime(string $seqType, string $coreType = 'B2B'): ?MinimaleVorlaufzeitSEPALastschrift
public function getMinimalLeadTime(string $seqType): ?MinimaleVorlaufzeitSEPALastschrift
{
$leadTime = in_array($seqType, ['FRST', 'OOFF']) ? $this->minimaleVorlaufzeitFRSTOOFF : $this->minimaleVorlaufzeitFNALRCUR;
return MinimaleVorlaufzeitSEPALastschrift::create($leadTime, '235959');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ abstract class ParameterTerminierteSEPAFirmenLastschriftEinreichenV2 extends Bas
/** @var string */
public $maximaleVorlaufzeitCodiert;

public function getMinimalLeadTime(string $seqType, string $coreType = 'CORE'): ?MinimaleVorlaufzeitSEPALastschrift
/** @return MinimaleVorlaufzeitSEPALastschrift[] */
public function getMinimalLeadTime(string $seqType)
{
$parsed = MinimaleVorlaufzeitSEPALastschrift::parseCodedB2B($this->minimaleVorlaufzeitCodiert);
return $parsed[$seqType] ?? null;
return array_map(function ($value) use ($seqType) {
return $value[$seqType] ?? null;
}, MinimaleVorlaufzeitSEPALastschrift::parseCodedB2B($this->minimaleVorlaufzeitCodiert));
}
}
4 changes: 2 additions & 2 deletions lib/Fhp/Segment/DSE/MinimaleVorlaufzeitSEPALastschrift.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ public static function parseCoded(string $coded): array
return $result;
}

/** @return MinimaleVorlaufzeitSEPALastschrift[]|array */
/** @return MinimaleVorlaufzeitSEPALastschrift[][]|array */
public static function parseCodedB2B(string $coded): array
{
$result = [];
foreach (array_chunk(explode(';', $coded), 3) as list($sequenceTypeCodiert, $minimaleSEPAVorlaufzeit, $cutOffZeit)) {
$seqTypes = self::SEQUENCE_TYPE_CODIERT[$sequenceTypeCodiert] ?? [];
foreach ($seqTypes as $seqType) {
$result[$seqType] = MinimaleVorlaufzeitSEPALastschrift::create($minimaleSEPAVorlaufzeit, $cutOffZeit, null, $sequenceTypeCodiert);
$result['B2B'][$seqType] = MinimaleVorlaufzeitSEPALastschrift::create($minimaleSEPAVorlaufzeit, $cutOffZeit, null, $sequenceTypeCodiert);
}
}
return $result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ParameterTerminierteSEPAEinzellastschriftEinreichenV1 extends BaseDeg impl
/** @var int */
public $maximaleVorlaufzeitFRSTOOFF;

public function getMinimalLeadTime(string $seqType, string $coreType = 'CORE'): ?MinimaleVorlaufzeitSEPALastschrift
public function getMinimalLeadTime(string $seqType): ?MinimaleVorlaufzeitSEPALastschrift
{
$leadTime = in_array($seqType, ['FRST', 'OOFF']) ? $this->minimaleVorlaufzeitFRSTOOFF : $this->minimaleVorlaufzeitFNALRCUR;
return MinimaleVorlaufzeitSEPALastschrift::create($leadTime, '235959');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ abstract class ParameterTerminierteSEPALastschriftEinreichenV2 extends BaseDeg i
/** @var string */
public $maximaleVorlaufzeitCodiert;

public function getMinimalLeadTime(string $seqType, string $coreType = 'CORE'): ?MinimaleVorlaufzeitSEPALastschrift
public function getMinimalLeadTime(string $seqType)
{
$parsed = MinimaleVorlaufzeitSEPALastschrift::parseCoded($this->minimaleVorlaufzeitCodiert);
return $parsed[$coreType][$seqType] ?? null;
return array_map(function ($value) use ($seqType) {
return $value[$seqType] ?? null;
}, MinimaleVorlaufzeitSEPALastschrift::parseCoded($this->minimaleVorlaufzeitCodiert));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@

interface SEPADirectDebitMinimalLeadTimeProvider
{
public function getMinimalLeadTime(string $seqType, string $coreType = 'CORE'): ?MinimaleVorlaufzeitSEPALastschrift;
/** @return MinimaleVorlaufzeitSEPALastschrift|MinimaleVorlaufzeitSEPALastschrift[]*/
public function getMinimalLeadTime(string $seqType);
}

0 comments on commit 5c91d2d

Please sign in to comment.