|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* BankAccountValidator class |
|
5
|
|
|
* |
|
6
|
|
|
* PHP version 7.3 |
|
7
|
|
|
* |
|
8
|
|
|
* @author WeDev Brasil Team <[email protected]> |
|
9
|
|
|
* @author Adeildo Amorim <[email protected]> |
|
10
|
|
|
* @copyright 2020 We Dev Tecnologia Ltda |
|
11
|
|
|
* @link https://github.com/wedevBr/bankly-laravel/ |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace WeDevBr\Bankly\Validators\Card; |
|
15
|
|
|
|
|
16
|
|
|
use WeDevBr\Bankly\Types\Card\Address; |
|
17
|
|
|
|
|
18
|
|
|
class AddressValidator |
|
19
|
|
|
{ |
|
20
|
|
|
private $address; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* AddressValidator constructor. |
|
24
|
|
|
* @param Address $bankAccount |
|
|
|
|
|
|
25
|
|
|
*/ |
|
26
|
|
|
public function __construct(Address $address) |
|
27
|
|
|
{ |
|
28
|
|
|
$this->address = $address; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* This validate the card |
|
33
|
|
|
*/ |
|
34
|
|
|
public function validate(): void |
|
35
|
|
|
{ |
|
36
|
|
|
$this->validateZipCode(); |
|
37
|
|
|
$this->validateAddress(); |
|
38
|
|
|
$this->validateNumber(); |
|
39
|
|
|
$this->validateNeighborhood(); |
|
40
|
|
|
$this->validateCity(); |
|
41
|
|
|
$this->validateState(); |
|
42
|
|
|
$this->validateCountry(); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* This validate a zip code |
|
47
|
|
|
* |
|
48
|
|
|
* @return void |
|
49
|
|
|
* @throws InvalidArgumentException |
|
50
|
|
|
*/ |
|
51
|
|
|
private function validateZipCode() |
|
52
|
|
|
{ |
|
53
|
|
|
$zipCode = $this->address->zipCode; |
|
54
|
|
|
if (empty($zipCode) || !is_string($zipCode) || !is_numeric($zipCode)) { |
|
55
|
|
|
throw new \InvalidArgumentException('zip code should be a numeric string'); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* This validates a address |
|
61
|
|
|
* |
|
62
|
|
|
* @return void |
|
63
|
|
|
* @throws InvalidArgumentException |
|
64
|
|
|
*/ |
|
65
|
|
View Code Duplication |
private function validateAddress() |
|
|
|
|
|
|
66
|
|
|
{ |
|
67
|
|
|
$address = $this->address->address; |
|
68
|
|
|
if (empty($address) || !is_string($address)) { |
|
69
|
|
|
throw new \InvalidArgumentException('address should be a string'); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* This validate a address number |
|
75
|
|
|
* |
|
76
|
|
|
* @return void |
|
77
|
|
|
* @throws InvalidArgumentException |
|
78
|
|
|
*/ |
|
79
|
|
|
private function validateNumber() |
|
80
|
|
|
{ |
|
81
|
|
|
$number = $this->address->number; |
|
82
|
|
|
if (empty($number) || !is_string($number) || !is_numeric($number)) { |
|
83
|
|
|
throw new \InvalidArgumentException('number should be a numeric string'); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* This validate a virtual card neighborhood |
|
89
|
|
|
* |
|
90
|
|
|
* @return void |
|
91
|
|
|
* @throws InvalidArgumentException |
|
92
|
|
|
*/ |
|
93
|
|
View Code Duplication |
private function validateNeighborhood() |
|
|
|
|
|
|
94
|
|
|
{ |
|
95
|
|
|
$neighborhood = $this->address->neighborhood; |
|
96
|
|
|
if (empty($neighborhood) || !is_string($neighborhood)) { |
|
97
|
|
|
throw new \InvalidArgumentException('neighborhood should be a string'); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* This validate a virtual card city |
|
103
|
|
|
* |
|
104
|
|
|
* @return void |
|
105
|
|
|
* @throws InvalidArgumentException |
|
106
|
|
|
*/ |
|
107
|
|
View Code Duplication |
private function validateCity() |
|
|
|
|
|
|
108
|
|
|
{ |
|
109
|
|
|
$city = $this->address->city; |
|
110
|
|
|
if (empty($city) || !is_string($city)) { |
|
111
|
|
|
throw new \InvalidArgumentException('city should be a string'); |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* This validate a virtual card state |
|
117
|
|
|
* |
|
118
|
|
|
* @return void |
|
119
|
|
|
* @throws InvalidArgumentException |
|
120
|
|
|
*/ |
|
121
|
|
View Code Duplication |
private function validateState() |
|
|
|
|
|
|
122
|
|
|
{ |
|
123
|
|
|
$state = $this->address->state; |
|
124
|
|
|
if (empty($state) || !is_string($state)) { |
|
125
|
|
|
throw new \InvalidArgumentException('state should be a string'); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* This validate a virtual card country |
|
131
|
|
|
* |
|
132
|
|
|
* @return void |
|
133
|
|
|
* @throws InvalidArgumentException |
|
134
|
|
|
*/ |
|
135
|
|
View Code Duplication |
private function validateCountry() |
|
|
|
|
|
|
136
|
|
|
{ |
|
137
|
|
|
$country = $this->address->country; |
|
138
|
|
|
if (empty($country) || !is_string($country)) { |
|
139
|
|
|
throw new \InvalidArgumentException('country should be a string'); |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.