Completed
Push — master ( 2a953d...5971d3 )
by
unknown
27s queued 10s
created

BillPaymentValidator   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 82
Duplicated Lines 25.61 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 16
lcom 1
cbo 1
dl 21
loc 82
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A validate() 0 7 1
A validateBankBranch() 7 7 4
A validateBankAccount() 7 7 4
A validateAmount() 0 7 3
A validateId() 7 7 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace WeDevBr\Bankly\Validators;
4
5
use WeDevBr\Bankly\BillPayment;
6
7
/**
8
 * BillPaymentValidator 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 2020 We Dev Tecnologia Ltda
15
 * @link      https://github.com/wedevBr/bankly-laravel/
16
 */
17
class BillPaymentValidator
18
{
19
    private $billPayment;
20
21
    /**
22
     * BillPaymentValidator constructor.
23
     * @param BillPayment $billPayment
24
     */
25
    public function __construct(BillPayment $billPayment)
26
    {
27
        $this->billPayment = $billPayment;
28
    }
29
30
    /**
31
     * This validate the bank account
32
     *
33
     * @return void
34
     */
35
    public function validate(): void
36
    {
37
        $this->validateBankBranch();
38
        $this->validateBankAccount();
39
        $this->validateAmount();
40
        $this->validateId();
41
    }
42
43
    /**
44
     * This validate a bank branch
45
     *
46
     * @return void
47
     * @throws InvalidArgumentException
48
     */
49 View Code Duplication
    private function validateBankBranch()
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...
50
    {
51
        $bankBranch = $this->billPayment->bankBranch;
52
        if (is_null($bankBranch) || !is_string($bankBranch) || !is_numeric($bankBranch)) {
53
            throw new \InvalidArgumentException('branch should be a numeric string');
54
        }
55
    }
56
57
    /**
58
     * This validate a bank account
59
     *
60
     * @return void
61
     * @throws InvalidArgumentException
62
     */
63 View Code Duplication
    private function validateBankAccount()
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...
64
    {
65
        $bankAccount = $this->billPayment->bankAccount;
66
        if (is_null($bankAccount) || !is_string($bankAccount)  || !is_numeric($bankAccount)) {
67
            throw new \InvalidArgumentException('account should be a numeric string');
68
        }
69
    }
70
71
    /**
72
     * This validates a amount
73
     *
74
     * @return void
75
     * @throws InvalidArgumentException
76
     */
77
    private function validateAmount()
78
    {
79
        $amount = $this->billPayment->amount;
80
        if (is_null($amount) || !is_numeric($amount)) {
81
            throw new \InvalidArgumentException('amount should be a numeric');
82
        }
83
    }
84
85
    /**
86
     * This validates a given ID
87
     *
88
     * @return void
89
     * @throws InvalidArgumentException
90
     */
91 View Code Duplication
    private function validateId()
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...
92
    {
93
        $id = $this->billPayment->id;
94
        if (is_null($id) || !is_string($id)) {
95
            throw new \InvalidArgumentException('ID should be a string');
96
        }
97
    }
98
}
99