BankAccountValidator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace WeDevBr\Bankly\Validators\Billet;
4
5
use WeDevBr\Bankly\Types\Billet\BankAccount;
6
7
/**
8
 * BankAccountValidator class
9
 *
10
 * PHP version 7.3|7.4|8.0
11
 *
12
 * @author    WeDev Brasil Team <[email protected]>
13
 * @author    Rafael Teixeira <[email protected]>
14
 * @copyright 2021 We Dev Tecnologia Ltda
15
 * @link      https://github.com/wedevBr/bankly-laravel/
16
 */
17
class BankAccountValidator
18
{
19
    /** @var BankAccount */
20
    private $bankAccount;
21
22
    /**
23
     * @param BankAccount $bankAccount
24
     */
25
    public function __construct(BankAccount $bankAccount)
26
    {
27
        $this->bankAccount = $bankAccount;
28
    }
29
30
    /**
31
     * Validate the attributes of the bank accoun class for deposit billet
32
     *
33
     * @return void
34
     */
35
    public function validate(): void
36
    {
37
        $this->validateBranch();
38
        $this->validateNumber();
39
    }
40
41
    /**
42
     * This validates the branch
43
     *
44
     * @return void
45
     * @throws \InvalidArgumentException
46
     */
47
    private function validateBranch()
48
    {
49
        $branch = $this->bankAccount->branch;
50
        if (empty($branch) || !is_string($branch) || !is_numeric($branch)) {
51
            throw new \InvalidArgumentException('branch should be a numeric string');
52
        }
53
    }
54
55
    /**
56
     * This validates the bank account number
57
     *
58
     * @return void
59
     * @throws \InvalidArgumentException
60
     */
61
    private function validateNumber()
62
    {
63
        $number = $this->bankAccount->number;
64
        if (empty($number) || !is_string($number) || !is_numeric($number)) {
65
            throw new \InvalidArgumentException('bank account number should be a numeric string');
66
        }
67
    }
68
}
69