diff --git a/lib/Fhp/BaseAction.php b/lib/Fhp/BaseAction.php index d36dec6a..76ab7fc3 100644 --- a/lib/Fhp/BaseAction.php +++ b/lib/Fhp/BaseAction.php @@ -37,29 +37,24 @@ abstract class BaseAction implements \Serializable { /** @var int[] Stores segment numbers that were assigned to the segments returned from {@link createRequest()}. */ - protected $requestSegmentNumbers; + protected ?array $requestSegmentNumbers = null; /** - * @var string|null Contains the name of the segment, that might need a tan, used by FinTs::execute to signal + * Contains the name of the segment, that might need a tan, used by FinTs::execute to signal * to the bank that supplying a tan is supported. */ - protected $needTanForSegment = null; + protected ?string $needTanForSegment = null; - /** - * If set, the last response from the server regarding this action asked for a TAN from the user. - * @var TanRequest|null - */ - protected $tanRequest; + /** If set, the last response from the server regarding this action asked for a TAN from the user. */ + protected ?TanRequest $tanRequest = null; - /** @var bool */ - protected $isDone = false; + protected bool $isDone = false; /** * Will be populated with the message the bank sent along with the success indication, can be used to show to * the user. - * @var string */ - public $successMessage; + public ?string $successMessage = null; /** * @deprecated Beginning from PHP7.4 __unserialize is used for new generated strings, then this method is only used for previously generated strings - remove after May 2023 @@ -231,7 +226,7 @@ public function processResponse(Message $response) /** @return int[] */ public function getRequestSegmentNumbers(): array { - return $this->requestSegmentNumbers; + return $this->requestSegmentNumbers ?? []; } /** diff --git a/lib/Fhp/Connection.php b/lib/Fhp/Connection.php index 5b2981da..c461473d 100644 --- a/lib/Fhp/Connection.php +++ b/lib/Fhp/Connection.php @@ -7,25 +7,10 @@ */ class Connection { - /** - * @var string - */ - protected $url; - - /** - * @var resource - */ - protected $curlHandle; - - /** - * @var int - */ - protected $timeoutConnect = 15; - - /** - * @var int - */ - protected $timeoutResponse = 30; + protected string $url; + protected ?\CurlHandle $curlHandle = null; + protected int $timeoutConnect = 15; + protected int $timeoutResponse = 30; public function __construct(string $url, int $timeoutConnect = 15, int $timeoutResponse = 30) { @@ -34,9 +19,12 @@ public function __construct(string $url, int $timeoutConnect = 15, int $timeoutR $this->timeoutResponse = $timeoutResponse; } - private function connect() + /** + * @throws CurlException When initializing cURL fails. + */ + private function connect(): void { - $this->curlHandle = curl_init(); + $this->curlHandle = curl_init() ?: throw new CurlException('Failed initializing cURL.'); curl_setopt($this->curlHandle, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($this->curlHandle, CURLOPT_SSL_VERIFYHOST, 2); @@ -52,7 +40,7 @@ private function connect() curl_setopt($this->curlHandle, CURLOPT_HTTPHEADER, ['cache-control: no-cache', 'Content-Type: text/plain']); } - public function disconnect() + public function disconnect(): void { if ($this->curlHandle !== null) { curl_close($this->curlHandle); @@ -76,7 +64,7 @@ public function send(string $message): string if (false === $response) { throw new CurlException( - 'Failed connection to ' . $this->url . ': ' . curl_error($this->curlHandle), + 'Failed sending to ' . $this->url . ': ' . curl_error($this->curlHandle), null, curl_errno($this->curlHandle), curl_getinfo($this->curlHandle), diff --git a/lib/Fhp/Model/StatementOfAccount/Statement.php b/lib/Fhp/Model/StatementOfAccount/Statement.php index 32237a50..b45e39f5 100644 --- a/lib/Fhp/Model/StatementOfAccount/Statement.php +++ b/lib/Fhp/Model/StatementOfAccount/Statement.php @@ -7,30 +7,12 @@ class Statement public const CD_CREDIT = 'credit'; public const CD_DEBIT = 'debit'; - /** - * @var array of Transaction - */ - protected $transactions = []; - - /** - * @var float - */ - protected $startBalance = 0.0; - - /** - * @var float|null - */ - protected $endBalance = null; - - /** - * @var string|null - */ - protected $creditDebit = null; - - /** - * @var \DateTime|null - */ - protected $date; + /** @var Transaction[] */ + protected array $transactions = []; + protected float $startBalance = 0.0; + protected ?float $endBalance = null; + protected ?string $creditDebit = null; + protected ?\DateTime $date = null; /** * Get transactions diff --git a/lib/Fhp/Model/StatementOfAccount/StatementOfAccount.php b/lib/Fhp/Model/StatementOfAccount/StatementOfAccount.php index 2cf2e603..1b5f9bfd 100644 --- a/lib/Fhp/Model/StatementOfAccount/StatementOfAccount.php +++ b/lib/Fhp/Model/StatementOfAccount/StatementOfAccount.php @@ -6,10 +6,8 @@ class StatementOfAccount { - /** - * @var Statement[] - */ - protected $statements = []; + /** @var Statement[] */ + protected array $statements = []; /** * Get statements diff --git a/lib/Fhp/Model/StatementOfAccount/Transaction.php b/lib/Fhp/Model/StatementOfAccount/Transaction.php index 1483a30d..af3151fb 100644 --- a/lib/Fhp/Model/StatementOfAccount/Transaction.php +++ b/lib/Fhp/Model/StatementOfAccount/Transaction.php @@ -8,86 +8,28 @@ class Transaction public const CD_CREDIT = 'credit'; public const CD_DEBIT = 'debit'; - /** - * @var \DateTime|null - */ - protected $bookingDate; - - /** - * @var \DateTime|null - */ - protected $valutaDate; - - /** - * @var float - */ - protected $amount; - - /** - * @var string - */ - protected $creditDebit; - - /** - * @var bool - */ - protected $isStorno; - - /** - * @var string - */ - protected $bookingCode; - - /** - * @var string - */ - protected $bookingText; - - /** - * @var string - */ - protected $description1; - - /** - * @var string - */ - protected $description2; + protected ?\DateTime $bookingDate = null; + protected ?\DateTime $valutaDate = null; + protected float $amount; + protected string $creditDebit; + protected bool $isStorno; + protected string $bookingCode; + protected string $bookingText; + protected string $description1; + protected string $description2; /** * Array keys are identifiers like "SVWZ" for the main description. * @var string[] */ - protected $structuredDescription; + protected array $structuredDescription; - /** - * @var string - */ - protected $bankCode; - - /** - * @var string - */ - protected $accountNumber; - - /** - * @var string - */ - protected $name; - - /** - * @var bool - */ - protected $booked; - - /** - * @var int - */ - protected $pn; - - /** - * @var int - */ - protected $textKeyAddition; + protected string $bankCode; + protected string $accountNumber; + protected string $name; + protected bool $booked; + protected int $pn; + protected int $textKeyAddition; /** * Get booking date. @@ -121,10 +63,9 @@ public function getValutaDate(): ?\DateTime * * @return $this */ - public function setBookingDate(?\DateTime $date = null) + public function setBookingDate(?\DateTime $date = null): static { $this->bookingDate = $date; - return $this; } @@ -133,10 +74,9 @@ public function setBookingDate(?\DateTime $date = null) * * @return $this */ - public function setValutaDate(?\DateTime $date = null) + public function setValutaDate(?\DateTime $date = null): static { $this->valutaDate = $date; - return $this; } @@ -153,10 +93,9 @@ public function getAmount(): float * * @return $this */ - public function setBooked(bool $booked) + public function setBooked(bool $booked): static { $this->booked = $booked; - return $this; } @@ -165,10 +104,9 @@ public function setBooked(bool $booked) * * @return $this */ - public function setAmount(float $amount) + public function setAmount(float $amount): static { - $this->amount = (float) $amount; - + $this->amount = $amount; return $this; } @@ -185,10 +123,9 @@ public function getCreditDebit(): string * * @return $this */ - public function setCreditDebit(string $creditDebit) + public function setCreditDebit(string $creditDebit): static { $this->creditDebit = $creditDebit; - return $this; } @@ -205,10 +142,9 @@ public function isStorno(): bool * * @return $this */ - public function setIsStorno(bool $isStorno) + public function setIsStorno(bool $isStorno): static { $this->isStorno = $isStorno; - return $this; } @@ -225,10 +161,9 @@ public function getBookingCode(): string * * @return $this */ - public function setBookingCode(string $bookingCode) + public function setBookingCode(string $bookingCode): static { - $this->bookingCode = (string) $bookingCode; - + $this->bookingCode = $bookingCode; return $this; } @@ -245,10 +180,9 @@ public function getBookingText(): string * * @return $this */ - public function setBookingText(string $bookingText) + public function setBookingText(string $bookingText): static { - $this->bookingText = (string) $bookingText; - + $this->bookingText = $bookingText; return $this; } @@ -265,10 +199,9 @@ public function getDescription1(): string * * @return $this */ - public function setDescription1(string $description1) + public function setDescription1(string $description1): static { - $this->description1 = (string) $description1; - + $this->description1 = $description1; return $this; } @@ -285,10 +218,9 @@ public function getDescription2(): string * * @return $this */ - public function setDescription2(string $description2) + public function setDescription2(string $description2): static { - $this->description2 = (string) $description2; - + $this->description2 = $description2; return $this; } @@ -306,10 +238,9 @@ public function getStructuredDescription(): array * Set structuredDescription * * @param string[] $structuredDescription - * * @return $this */ - public function setStructuredDescription(array $structuredDescription) + public function setStructuredDescription(array $structuredDescription): static { $this->structuredDescription = $structuredDescription; @@ -353,10 +284,9 @@ public function getBankCode(): string * * @return $this */ - public function setBankCode(string $bankCode) + public function setBankCode(string $bankCode): static { - $this->bankCode = (string) $bankCode; - + $this->bankCode = $bankCode; return $this; } @@ -373,10 +303,9 @@ public function getAccountNumber(): string * * @return $this */ - public function setAccountNumber(string $accountNumber) + public function setAccountNumber(string $accountNumber): static { - $this->accountNumber = (string) $accountNumber; - + $this->accountNumber = $accountNumber; return $this; } @@ -401,10 +330,9 @@ public function getBooked(): bool * * @return $this */ - public function setName(string $name) + public function setName(string $name): static { - $this->name = (string) $name; - + $this->name = $name; return $this; } @@ -422,7 +350,7 @@ public function getPN(): int * @param int|mixed $nr Will be parsed to an int. * @return $this */ - public function setPN($nr) + public function setPN($nr): static { $this->pn = intval($nr); return $this; @@ -442,7 +370,7 @@ public function getTextKeyAddition(): int * @param int|mixed $textKeyAddition Will be parsed to an int. * @return $this */ - public function setTextKeyAddition($textKeyAddition) + public function setTextKeyAddition($textKeyAddition): static { $this->textKeyAddition = intval($textKeyAddition); return $this; diff --git a/lib/Fhp/PaginateableAction.php b/lib/Fhp/PaginateableAction.php index b01d4807..08a49ace 100644 --- a/lib/Fhp/PaginateableAction.php +++ b/lib/Fhp/PaginateableAction.php @@ -19,18 +19,17 @@ abstract class PaginateableAction extends BaseAction { /** - * @var BaseSegment[] Stores the request created by BaseAction::getNextRequest to be reused in case the bank wants + * Stores the request created by BaseAction::getNextRequest to be reused in case the bank wants * to split the result over multiple pages e.g. request/response pairs. This avoids the need for {@link BPD} to be * available for paginated requests. */ - protected $requestSegments; + protected ?array $requestSegments = null; /** * If set, the last response from the server regarding this action indicated that there are more results to be * fetched using this pagination token. This is called "Aufsetzpunkt" in the specification. - * @var string|null */ - protected $paginationToken; + protected ?string $paginationToken = null; /** * @deprecated Beginning from PHP7.4 __unserialize is used for new generated strings, then this method is only used for previously generated strings - remove after May 2023