-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpayment.php
49 lines (40 loc) · 1019 Bytes
/
payment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
require __DIR__.'/../vendor/autoload.php';
use Gksh\Bitmask\TinyBitmask;
enum PaymentMethod: int
{
case Cash = 1;
case Credit = 2;
case Debit = 4;
case Check = 8;
}
class PaymentMethods extends TinyBitmask
{
public function accept(PaymentMethod $method): PaymentMethods
{
return $this->set($method->value);
}
public function reject(PaymentMethod $method): PaymentMethods
{
return $this->unset($method->value);
}
public function accepts(PaymentMethod $method): bool
{
return $this->has($method->value);
}
}
class Invoice
{
public function __construct(public PaymentMethods $paymentMethods)
{
}
}
$invoice = new Invoice(
PaymentMethods::make()
->accept(PaymentMethod::Cash)
->accept(PaymentMethod::Debit)
);
dump([
'accepts_debit' => $invoice->paymentMethods->accepts(PaymentMethod::Debit), // true
'accepts_credit' => $invoice->paymentMethods->accepts(PaymentMethod::Credit), // false
]);