Street::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 4
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Talentify\ValueObject\Geography\Address\ByCountry\Br;
6
7
use InvalidArgumentException;
8
use Talentify\ValueObject\Geography\Address\Street as B;
9
use Talentify\ValueObject\StringUtils;
10
11
class Street extends B
12
{
13
    /** @var string */
14
    private $type;
15
16
    /**
17
     * @throws \InvalidArgumentException if supplied value is invalid.
18
     */
19
    public function __construct(string $type, string $name, string $number, string $otherIdentifiers)
20
    {
21
        $this->setType($type);
22
23
        parent::__construct($name, $number, $otherIdentifiers);
24
    }
25
26
    protected function setType(string $type) : void
27
    {
28
        $normalized = StringUtils::trimSpacesWisely($type);
29
        if (empty($normalized)) {
30
            throw new InvalidArgumentException(sprintf('The value "%s" is not a valid brazilian street type.', $type));
31
        }
32
33
        $this->type = StringUtils::convertCaseToTitle($normalized);
34
    }
35
36
    public function getType() : string
37
    {
38
        return $this->type;
39
    }
40
41
    /**
42
     * e.g.: Avenida João Jorge, 112, ap. 31
43
     */
44
    public function getFormatted() : string
45
    {
46
        return sprintf(
47
            '%s %s, %s, %s',
48
            $this->getType(),
49
            $this->getName(),
50
            $this->getNumber(),
51
            $this->getOtherIdentifiers()
52
        );
53
    }
54
}
55