AddressValidator::validateAddressLine()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
dl 7
loc 7
rs 10
c 0
b 0
f 0
cc 3
nc 2
nop 0
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