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

AddressValidator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace WeDevBr\Bankly\Validators\Billet;
4
5
use WeDevBr\Bankly\Types\Billet\Address;
6
use WeDevBr\Bankly\Types\Billet\Payer;
7
8
/**
9
 * AddressValidator class
10
 *
11
 * PHP version 7.3|7.4|8.0
12
 *
13
 * @author    WeDev Brasil Team <[email protected]>
14
 * @author    Rafael Teixeira <[email protected]>
15
 * @copyright 2021 We Dev Tecnologia Ltda
16
 * @link      https://github.com/wedevBr/bankly-laravel/
17
 */
18
class AddressValidator
19
{
20
    /** @var Address */
21
    private $address;
22
23
    /**
24
     * @param Address $address
25
     */
26
    public function __construct(Address $address)
27
    {
28
        $this->address = $address;
29
    }
30
31
    /**
32
     * Validate the attributes of the address class
33
     *
34
     * @return void
35
     */
36
    public function validate(): void
37
    {
38
        $this->validateAddressLine();
39
        $this->validateCity();
40
        $this->validateState();
41
        $this->validateZipCode();
42
    }
43
44
    /**
45
     * This validates the address line
46
     *
47
     * @return void
48
     * @throws InvalidArgumentException
49
     */
50 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...
51
    {
52
        $addressLine = $this->address->addressLine;
53
        if (empty($addressLine) || !is_string($addressLine)) {
54
            throw new \InvalidArgumentException('address line should be a string');
55
        }
56
    }
57
58
    /**
59
     * This validates the city address
60
     *
61
     * @return void
62
     * @throws InvalidArgumentException
63
     */
64 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...
65
    {
66
        $city = $this->address->city;
67
        if (empty($city) || !is_string($city)) {
68
            throw new \InvalidArgumentException('city address should be a string');
69
        }
70
    }
71
72
    /**
73
     * This validates the state address
74
     *
75
     * @return void
76
     * @throws InvalidArgumentException
77
     */
78 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...
79
    {
80
        $state = $this->address->state;
81
        if (empty($state) || !is_string($state)) {
82
            throw new \InvalidArgumentException('state address should be a string');
83
        }
84
    }
85
86
    /**
87
     * This validates a zip code
88
     *
89
     * @return void
90
     * @throws InvalidArgumentException
91
     */
92 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...
93
    {
94
        $zipCode = $this->address->zipCode;
95
        if (empty($zipCode) || !is_string($zipCode)) {
96
            throw new \InvalidArgumentException('zip code should be a string');
97
        }
98
    }
99
}
100