Skip to content

Commit dc0f5e4

Browse files
committed
Code: add types
1 parent a3d71d8 commit dc0f5e4

11 files changed

Lines changed: 53 additions & 83 deletions

src/Comgate.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@
55
class Comgate
66
{
77

8-
/** @var string */
9-
private $merchant;
8+
private string $merchant;
109

11-
/** @var string */
12-
private $secret;
10+
private string $secret;
1311

14-
/** @var bool */
15-
private $test;
12+
private bool $test;
1613

1714
public function __construct(string $merchant, string $secret, bool $test = true)
1815
{

src/Entity/AbstractPayment.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,22 @@
77
class AbstractPayment extends AbstractEntity
88
{
99

10-
/** @var int */
11-
protected $price;
10+
protected int $price;
1211

1312
/** @var string ISO 4217 */
14-
protected $curr;
13+
protected string $curr;
1514

16-
/** @var string */
17-
protected $label;
15+
protected string $label;
1816

19-
/** @var string */
20-
protected $refId;
17+
protected string $refId;
2118

22-
/** @var string */
23-
protected $email;
19+
protected string $email;
2420

25-
/** @var string */
26-
protected $country = CountryCode::ALL;
21+
protected string $country = CountryCode::ALL;
2722

28-
/** @var string */
29-
protected $account;
23+
protected string $account;
3024

31-
/** @var string */
32-
protected $name;
25+
protected string $name;
3326

3427
public function getPrice(): int
3528
{

src/Entity/Payment.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,24 @@
1111
class Payment extends AbstractPayment
1212
{
1313

14-
/** @var string */
15-
private $method = PaymentMethodCode::ALL;
14+
private string $method = PaymentMethodCode::ALL;
1615

1716
/** @var string ISO 639-1 */
18-
private $lang = LangCode::CS;
17+
private string $lang = LangCode::CS;
1918

20-
/** @var bool */
21-
private $prepareOnly = true;
19+
private bool $prepareOnly = true;
2220

23-
/** @var bool */
24-
private $preauth = false;
21+
private bool $preauth = false;
2522

26-
/** @var bool */
27-
private $initRecurring = false;
23+
private bool $initRecurring = false;
2824

29-
/** @var bool */
30-
private $verification = false;
25+
private bool $verification = false;
3126

32-
/** @var bool */
33-
private $embedded = false;
27+
private bool $embedded = false;
3428

3529
final private function __construct()
3630
{
31+
// Noop
3732
}
3833

3934
public static function of(

src/Entity/PaymentStatus.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
class PaymentStatus extends AbstractEntity
66
{
77

8-
/** @var string */
9-
private $transId;
8+
private string $transId;
109

1110
final private function __construct()
1211
{
12+
// Noop
1313
}
1414

1515
public static function of(string $transId): self

src/Entity/RecurringPayment.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
class RecurringPayment extends AbstractPayment
1010
{
1111

12-
/** @var string */
13-
private $initRecurringId;
12+
private string $initRecurringId;
1413

1514
final private function __construct()
1615
{
16+
// Noop
1717
}
1818

1919
public static function of(

src/Entity/Refund.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,18 @@
88
class Refund extends AbstractEntity
99
{
1010

11-
/** @var int */
12-
private $amount;
11+
private int $amount;
1312

1413
/** @var string ISO 4217 */
15-
private $curr;
14+
private string $curr;
1615

17-
/** @var string */
18-
private $transId;
16+
private string $transId;
1917

20-
/** @var string|null */
21-
private $refId;
18+
private ?string $refId = null;
2219

2320
final private function __construct()
2421
{
22+
// Noop
2523
}
2624

2725
public static function of(

src/Entity/Response/AbstractResponseEntity.php

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
abstract class AbstractResponseEntity extends Response
1111
{
1212

13-
/**
14-
* @param Response|ResponseInterface $origin
15-
*/
16-
public function __construct($origin)
13+
public function __construct(Response|ResponseInterface $origin)
1714
{
1815
if ($origin instanceof Response) {
1916
$origin = $origin->getOrigin();
@@ -22,12 +19,7 @@ public function __construct($origin)
2219
parent::__construct($origin);
2320
}
2421

25-
/**
26-
* @param string $fieldId
27-
* @param int|string|null $default
28-
* @return int|string|null
29-
*/
30-
public function get(string $fieldId, $default = null)
22+
public function get(string $fieldId, int|string|null $default = null): int|string|null
3123
{
3224
$value = $this->getData()[$fieldId] ?? $default;
3325
if ($value !== null && !is_string($value) && !is_int($value)) {
@@ -37,6 +29,21 @@ public function get(string $fieldId, $default = null)
3729
return $value;
3830
}
3931

32+
public function getErrorCode(): int
33+
{
34+
return $this->getRequiredInteger('code');
35+
}
36+
37+
public function getErrorMessage(): ?string
38+
{
39+
return $this->getString('message');
40+
}
41+
42+
public function isOk(): bool
43+
{
44+
return $this->getInteger('code', -1) === 0;
45+
}
46+
4047
/**
4148
* @phpstan-return ($default is null ? (string|null) : string)
4249
*/
@@ -91,19 +98,4 @@ protected function getRequiredBool(string $fieldId): bool
9198
return $value;
9299
}
93100

94-
public function getErrorCode(): int
95-
{
96-
return $this->getRequiredInteger('code');
97-
}
98-
99-
public function getErrorMessage(): ?string
100-
{
101-
return $this->getString('message');
102-
}
103-
104-
public function isOk(): bool
105-
{
106-
return $this->getInteger('code', -1) === 0;
107-
}
108-
109101
}

src/Entity/Storno.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
class Storno extends AbstractEntity
66
{
77

8-
/** @var string */
9-
private $transId;
8+
private string $transId;
109

1110
final private function __construct()
1211
{
12+
// Noop
1313
}
1414

1515
public static function of(
@@ -27,7 +27,6 @@ public function getTransId(): string
2727
return $this->transId;
2828
}
2929

30-
3130
/**
3231
* @return mixed[]
3332
*/

src/Gateway/PaymentService.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
class PaymentService
1818
{
1919

20-
/** @var HttpClient */
21-
protected $client;
20+
protected HttpClient $client;
2221

2322
public function __construct(HttpClient $client)
2423
{

src/Http/HttpClient.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
class HttpClient
99
{
1010

11-
/** @var ClientInterface */
12-
protected $client;
11+
protected ClientInterface $client;
1312

14-
/** @var Comgate */
15-
protected $comgate;
13+
protected Comgate $comgate;
1614

1715
public function __construct(ClientInterface $client, Comgate $comgate)
1816
{

0 commit comments

Comments
 (0)