BankAccountValidator   A
last analyzed

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
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