Skip to content

Commit 1666012

Browse files
authored
Merge pull request #508 from Philipp91/php-props
Migrate some core classes to PHP properties
2 parents 575a5a8 + c6eb65f commit 1666012

File tree

6 files changed

+70
-180
lines changed

6 files changed

+70
-180
lines changed

lib/Fhp/BaseAction.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,24 @@
3737
abstract class BaseAction implements \Serializable
3838
{
3939
/** @var int[] Stores segment numbers that were assigned to the segments returned from {@link createRequest()}. */
40-
protected $requestSegmentNumbers;
40+
protected ?array $requestSegmentNumbers = null;
4141

4242
/**
43-
* @var string|null Contains the name of the segment, that might need a tan, used by FinTs::execute to signal
43+
* Contains the name of the segment, that might need a tan, used by FinTs::execute to signal
4444
* to the bank that supplying a tan is supported.
4545
*/
46-
protected $needTanForSegment = null;
46+
protected ?string $needTanForSegment = null;
4747

48-
/**
49-
* If set, the last response from the server regarding this action asked for a TAN from the user.
50-
* @var TanRequest|null
51-
*/
52-
protected $tanRequest;
48+
/** If set, the last response from the server regarding this action asked for a TAN from the user. */
49+
protected ?TanRequest $tanRequest = null;
5350

54-
/** @var bool */
55-
protected $isDone = false;
51+
protected bool $isDone = false;
5652

5753
/**
5854
* Will be populated with the message the bank sent along with the success indication, can be used to show to
5955
* the user.
60-
* @var string
6156
*/
62-
public $successMessage;
57+
public ?string $successMessage = null;
6358

6459
/**
6560
* @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)
231226
/** @return int[] */
232227
public function getRequestSegmentNumbers(): array
233228
{
234-
return $this->requestSegmentNumbers;
229+
return $this->requestSegmentNumbers ?? [];
235230
}
236231

237232
/**

lib/Fhp/Connection.php

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,10 @@
77
*/
88
class Connection
99
{
10-
/**
11-
* @var string
12-
*/
13-
protected $url;
14-
15-
/**
16-
* @var resource
17-
*/
18-
protected $curlHandle;
19-
20-
/**
21-
* @var int
22-
*/
23-
protected $timeoutConnect = 15;
24-
25-
/**
26-
* @var int
27-
*/
28-
protected $timeoutResponse = 30;
10+
protected string $url;
11+
protected ?\CurlHandle $curlHandle = null;
12+
protected int $timeoutConnect = 15;
13+
protected int $timeoutResponse = 30;
2914

3015
public function __construct(string $url, int $timeoutConnect = 15, int $timeoutResponse = 30)
3116
{
@@ -34,9 +19,12 @@ public function __construct(string $url, int $timeoutConnect = 15, int $timeoutR
3419
$this->timeoutResponse = $timeoutResponse;
3520
}
3621

37-
private function connect()
22+
/**
23+
* @throws CurlException When initializing cURL fails.
24+
*/
25+
private function connect(): void
3826
{
39-
$this->curlHandle = curl_init();
27+
$this->curlHandle = curl_init() ?: throw new CurlException('Failed initializing cURL.');
4028

4129
curl_setopt($this->curlHandle, CURLOPT_SSL_VERIFYPEER, true);
4230
curl_setopt($this->curlHandle, CURLOPT_SSL_VERIFYHOST, 2);
@@ -52,7 +40,7 @@ private function connect()
5240
curl_setopt($this->curlHandle, CURLOPT_HTTPHEADER, ['cache-control: no-cache', 'Content-Type: text/plain']);
5341
}
5442

55-
public function disconnect()
43+
public function disconnect(): void
5644
{
5745
if ($this->curlHandle !== null) {
5846
curl_close($this->curlHandle);
@@ -76,7 +64,7 @@ public function send(string $message): string
7664

7765
if (false === $response) {
7866
throw new CurlException(
79-
'Failed connection to ' . $this->url . ': ' . curl_error($this->curlHandle),
67+
'Failed sending to ' . $this->url . ': ' . curl_error($this->curlHandle),
8068
null,
8169
curl_errno($this->curlHandle),
8270
curl_getinfo($this->curlHandle),

lib/Fhp/Model/StatementOfAccount/Statement.php

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,12 @@ class Statement
77
public const CD_CREDIT = 'credit';
88
public const CD_DEBIT = 'debit';
99

10-
/**
11-
* @var array of Transaction
12-
*/
13-
protected $transactions = [];
14-
15-
/**
16-
* @var float
17-
*/
18-
protected $startBalance = 0.0;
19-
20-
/**
21-
* @var float|null
22-
*/
23-
protected $endBalance = null;
24-
25-
/**
26-
* @var string|null
27-
*/
28-
protected $creditDebit = null;
29-
30-
/**
31-
* @var \DateTime|null
32-
*/
33-
protected $date;
10+
/** @var Transaction[] */
11+
protected array $transactions = [];
12+
protected float $startBalance = 0.0;
13+
protected ?float $endBalance = null;
14+
protected ?string $creditDebit = null;
15+
protected ?\DateTime $date = null;
3416

3517
/**
3618
* Get transactions

lib/Fhp/Model/StatementOfAccount/StatementOfAccount.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66

77
class StatementOfAccount
88
{
9-
/**
10-
* @var Statement[]
11-
*/
12-
protected $statements = [];
9+
/** @var Statement[] */
10+
protected array $statements = [];
1311

1412
/**
1513
* Get statements

0 commit comments

Comments
 (0)