Completed
Push — master ( 77cb3d...eaae4c )
by
unknown
24s queued 11s
created

BankAccountValidator   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 1
dl 0
loc 52
rs 10
c 0
b 0
f 0

4 Methods

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