Passed
Push — feature/configure_company ( 5f97ab...38f251 )
by Laurent
03:30 queued 10s
created

ContactAddress   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
c 0
b 0
f 0
dl 0
loc 32
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A fromString() 0 3 1
A __construct() 0 6 1
A fromArray() 0 7 2
A getValue() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the G.L.S.R. Apps package.
7
 *
8
 * (c) Dev-Int Création <[email protected]>.
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Domain\Common\Model\VO;
15
16
final class ContactAddress
17
{
18
    private string $address;
19
    private string $zipCode;
20
    private string $town;
21
    private string $country;
22
23
    public function __construct(string $address, string $zipCode, string $town, string $country)
24
    {
25
        $this->address = $address;
26
        $this->zipCode = $zipCode;
27
        $this->town = $town;
28
        $this->country = $country;
29
    }
30
31
    public static function fromString(string $address, string $zipCode, string $town, string $country): self
32
    {
33
        return new self($address, $zipCode, $town, $country);
34
    }
35
36
    public static function fromArray(array $addressData): self
37
    {
38
        if ([$address, $zipcode, $town, $country] = $addressData) {
39
            return new self($address, $zipcode, $town, $country);
40
        }
41
42
        throw new \DomainException('The address data are not valid');
43
    }
44
45
    public function getValue(): string
46
    {
47
        return $this->address . "\n" . $this->zipCode . ' ' . $this->town . ', ' . $this->country;
48
    }
49
}
50