AddressValidator   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 82
Duplicated Lines 34.15 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 1
dl 28
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 validateAddressLine() 7 7 3
A validateCity() 7 7 3
A validateState() 7 7 3
A validateZipCode() 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\Billet;
4
5
use WeDevBr\Bankly\Types\Billet\Address;
6
7
/**
8
 * AddressValidator 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 AddressValidator
18
{
19
    /** @var Address */
20
    private $address;
21
22
    /**
23
     * @param Address $address
24
     */
25
    public function __construct(Address $address)
26
    {
27
        $this->address = $address;
28
    }
29
30
    /**
31
     * Validate the attributes of the address class
32
     *
33
     * @return void
34
     */
35
    public function validate(): void
36
    {
37
        $this->validateAddressLine();
38
        $this->validateCity();
39
        $this->validateState();
40
        $this->validateZipCode();
41
    }
42
43
    /**
44
     * This validates the address line
45
     *
46
     * @return void
47
     * @throws \InvalidArgumentException
48
     */
49 View Code Duplication
    private function validateAddressLine()
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
        $addressLine = $this->address->addressLine;
52
        if (empty($addressLine) || !is_string($addressLine)) {
53
            throw new \InvalidArgumentException('address line should be a string');
54
        }
55
    }
56
57
    /**
58
     * This validates the city address
59
     *
60
     * @return void
61
     * @throws \InvalidArgumentException
62
     */
63 View Code Duplication
    private function validateCity()
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
        $city = $this->address->city;
66
        if (empty($city) || !is_string($city)) {
67
            throw new \InvalidArgumentException('city address should be a string');
68
        }
69
    }
70
71
    /**
72
     * This validates the state address
73
     *
74
     * @return void
75
     * @throws \InvalidArgumentException
76
     */
77 View Code Duplication
    private function validateState()
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...
78
    {
79
        $state = $this->address->state;
80
        if (empty($state) || !is_string($state)) {
81
            throw new \InvalidArgumentException('state address should be a string');
82
        }
83
    }
84
85
    /**
86
     * This validates a zip code
87
     *
88
     * @return void
89
     * @throws \InvalidArgumentException
90
     */
91 View Code Duplication
    private function validateZipCode()
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
        $zipCode = $this->address->zipCode;
94
        if (empty($zipCode) || !is_string($zipCode)) {
95
            throw new \InvalidArgumentException('zip code should be a string');
96
        }
97
    }
98
}
99