Skip to content

Commit 90ca8b6

Browse files
[HSDK-2] refactor
1 parent 999933f commit 90ca8b6

File tree

3 files changed

+7
-27
lines changed

3 files changed

+7
-27
lines changed

src/paymethods/Card.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Card implements Paymethod
77
private $year;
88
private $month;
99

10-
public function __construct($card_number, $year, $month)
10+
public function __construct(string $card_number, int $year, int $month)
1111
{
1212
$this->set_card_number($card_number);
1313
$this->set_expiration_date($year, $month);
@@ -18,12 +18,8 @@ public function get_card_number()
1818
return $this->card_number;
1919
}
2020

21-
public function set_card_number($card_number)
21+
public function set_card_number(string $card_number)
2222
{
23-
if (gettype($card_number) != "string") {
24-
throw new \Exception('$card_number must be a string.');
25-
}
26-
2723
if(!preg_match("/^[0-9]{14,19}$/", $card_number)) {
2824
throw new \Exception('$card_number don\'t match with pattern.');
2925
}
@@ -41,22 +37,14 @@ public function get_month()
4137
return $this->month;
4238
}
4339

44-
public function set_expiration_date($year, $month)
40+
public function set_expiration_date(int $year, int $month)
4541
{
46-
if (gettype($year) != "integer") {
47-
throw new \Exception('$year must be a string.');
48-
}
49-
5042
if($year < 1000 or $year >9999) {
5143
throw new \Exception('$year doesn\'t have a correct value.');
5244
}
5345

5446
$this->year = $year;
5547

56-
if (gettype($month) != "integer") {
57-
throw new \Exception('$month must be a string.');
58-
}
59-
6048
if($month < 1 or $month > 12) {
6149
throw new \Exception('$month doesn\'t have a correct value.');
6250
}

src/paymethods/FastPay.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,13 @@
33

44
class FastPay implements Paymethod
55
{
6-
public function __construct($token)
6+
public function __construct(string $token)
77
{
88
$this->set_token($token);
99
}
1010

11-
public function set_token($token)
11+
public function set_token(string $token)
1212
{
13-
if (gettype($token) != "string") {
14-
throw new \Exception('$token must be a string.');
15-
}
16-
1713
if(!preg_match("/^[0-9a-fA-F]{32}$/", $token)) {
1814
throw new \Exception('$token don\'t match with pattern.');
1915
}

src/paymethods/StoredCard.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,13 @@
33

44
class StoredCard implements Paymethod
55
{
6-
public function __construct($token)
6+
public function __construct(string $token)
77
{
88
$this->set_token($token);
99
}
1010

11-
public function set_token($token)
11+
public function set_token(string $token)
1212
{
13-
if (gettype($token) != "string") {
14-
throw new \Exception('$token must be a string.');
15-
}
16-
1713
if(!preg_match("/^[\w-]{6,128}$/", $token)) {
1814
throw new \Exception('$token don\'t match with pattern.');
1915
}

0 commit comments

Comments
 (0)