Completed
Push — master ( 690bad...4d799d )
by Rafael
14s queued 11s
created

WalletValidator::wallet()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
dl 11
loc 11
rs 9.9
c 0
b 0
f 0
cc 4
nc 3
nop 0
1
<?php
2
3
namespace WeDevBr\Bankly\Validators\Card;
4
5
use WeDevBr\Bankly\Types\Card\Password;
6
use WeDevBr\Bankly\Types\Card\Wallet;
7
8
/**
9
 * WalletValidator class
10
 *
11
 * PHP version 7.3|7.4|8.0
12
 *
13
 * @author    WeDev Brasil Team <[email protected]>
14
 * @author    Rafael Teixeira <[email protected]>
15
 * @copyright 2021 We Dev Tecnologia Ltda
16
 * @link      https://github.com/wedevBr/bankly-laravel/
17
 */
18
class WalletValidator
19
{
20
    /** @var array */
21
    protected $wallets = [
22
        'GooglePay',
23
        'ApplePay',
24
    ];
25
26
    /** @var array */
27
    protected $brands = [
28
        'Mastercard',
29
        'Visa',
30
    ];
31
32
    /**
33
     * @var Wallet
34
     */
35
    private $wallet;
36
37
    /**
38
     * WalletValidator constructor.
39
     * @param Wallet $wallet
40
     */
41
    public function __construct(Wallet $wallet)
42
    {
43
        $this->wallet = $wallet;
44
    }
45
46
    /**
47
     * This validate the wallet data
48
     */
49
    public function validate(): void
50
    {
51
        $this->proxy();
52
        $this->wallet();
53
        $this->brand();
54
    }
55
56
    /**
57
     * @return void
58
     * @throws \InvalidArgumentException
59
     */
60
    public function proxy()
61
    {
62
        $proxy = $this->wallet->proxy;
63
        if (empty($proxy) || !is_string($proxy)) {
64
            throw new \InvalidArgumentException('proxy should be a string');
65
        }
66
    }
67
68
    /**
69
     * @return void
70
     * @throws \InvalidArgumentException
71
     */
72 View Code Duplication
    public function wallet()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
    {
74
        $wallet = $this->wallet->wallet;
75
        if (empty($wallet) || !is_string($wallet)) {
76
            throw new \InvalidArgumentException('wallet should be a string');
77
        }
78
79
        if (!in_array($wallet, $this->wallets)) {
80
            throw new \InvalidArgumentException('this wallet is not valid');
81
        }
82
    }
83
84
    /**
85
     * @return void
86
     * @throws \InvalidArgumentException
87
     */
88 View Code Duplication
    public function brand()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
89
    {
90
        $brand = $this->wallet->brand;
91
        if (empty($brand) || !is_string($brand)) {
92
            throw new \InvalidArgumentException('brand should be a string');
93
        }
94
95
        if (!in_array($brand, $this->brands)) {
96
            throw new \InvalidArgumentException('this brand is not valid');
97
        }
98
    }
99
}
100