1 | <?php |
||
14 | abstract class Card |
||
15 | { |
||
16 | /** |
||
17 | * Regular expression for card number recognition. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | public static $pattern; |
||
22 | |||
23 | /** |
||
24 | * Credit card type: "debit", "credit". |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $type; |
||
29 | |||
30 | /** |
||
31 | * Credit card name. |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $name; |
||
36 | |||
37 | /** |
||
38 | * Brand name. |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $brand; |
||
43 | |||
44 | /** |
||
45 | * Card number length's. |
||
46 | * |
||
47 | * @var array |
||
48 | */ |
||
49 | protected $number_length; |
||
50 | |||
51 | /** |
||
52 | * CVC code length's. |
||
53 | * |
||
54 | * @var array |
||
55 | */ |
||
56 | protected $cvc_length; |
||
57 | |||
58 | /** |
||
59 | * Test cvc code checksum against Luhn algorithm. |
||
60 | * |
||
61 | * @var bool |
||
62 | */ |
||
63 | protected $checksum_test; |
||
64 | |||
65 | /** |
||
66 | * @var string|null |
||
67 | */ |
||
68 | private $card_number; |
||
69 | |||
70 | /** |
||
71 | * Card constructor. |
||
72 | * |
||
73 | * @param string $card_number |
||
74 | * |
||
75 | * @throws \LVR\CreditCard\Exceptions\CreditCardException |
||
76 | */ |
||
77 | 124 | public function __construct(string $card_number = '') |
|
85 | |||
86 | /** |
||
87 | * @param string $card_number |
||
88 | * |
||
89 | * @return $this |
||
90 | * @throws \LVR\CreditCard\Exceptions\CreditCardPatternException |
||
91 | */ |
||
92 | 90 | public function setCardNumber(string $card_number) |
|
106 | |||
107 | /** |
||
108 | * @return bool |
||
109 | * @throws \LVR\CreditCard\Exceptions\CreditCardChecksumException |
||
110 | * @throws \LVR\CreditCard\Exceptions\CreditCardCharactersException |
||
111 | * @throws \LVR\CreditCard\Exceptions\CreditCardException |
||
112 | * @throws \LVR\CreditCard\Exceptions\CreditCardLengthException |
||
113 | */ |
||
114 | 104 | public function isValidCardNumber() |
|
140 | |||
141 | /** |
||
142 | * @return string |
||
143 | */ |
||
144 | 14 | public function type() |
|
148 | |||
149 | /** |
||
150 | * @return string |
||
151 | */ |
||
152 | 1 | public function name() |
|
156 | |||
157 | /** |
||
158 | * @return string |
||
159 | */ |
||
160 | 1 | public function brand() |
|
164 | |||
165 | /** |
||
166 | * @param $cvc |
||
167 | * |
||
168 | * @return bool |
||
169 | */ |
||
170 | 1 | public function isValidCvc($cvc) |
|
175 | |||
176 | /** |
||
177 | * Check CVS length against possible lengths. |
||
178 | * |
||
179 | * @param string|int $cvc |
||
180 | * |
||
181 | * @param array $available_lengths |
||
182 | * |
||
183 | * @return bool |
||
184 | */ |
||
185 | 2 | public static function isValidCvcLength($cvc, array $available_lengths = [3, 4]) |
|
191 | |||
192 | /** |
||
193 | * @throws \LVR\CreditCard\Exceptions\CreditCardException |
||
194 | */ |
||
195 | 124 | protected function checkImplementation() |
|
229 | |||
230 | /** |
||
231 | * @return bool |
||
232 | */ |
||
233 | 45 | protected function validPattern() |
|
237 | |||
238 | /** |
||
239 | * @return bool |
||
240 | */ |
||
241 | 74 | protected function validLength() |
|
245 | |||
246 | /** |
||
247 | * @return bool |
||
248 | */ |
||
249 | 59 | protected function validChecksum() |
|
253 | |||
254 | /** |
||
255 | * @return bool |
||
256 | */ |
||
257 | 56 | protected function checksumTest() |
|
276 | } |
||
277 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: