Address::postcode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace DummyGenerator\Core;
6
7
use DummyGenerator\Definitions\Extension\AddressExtensionInterface;
8
use DummyGenerator\Definitions\Extension\Awareness\GeneratorAwareExtensionInterface;
9
use DummyGenerator\Definitions\Extension\Awareness\GeneratorAwareExtensionTrait;
10
use DummyGenerator\Definitions\Extension\Awareness\RandomizerAwareExtensionInterface;
11
use DummyGenerator\Definitions\Extension\Awareness\RandomizerAwareExtensionTrait;
12
use DummyGenerator\Definitions\Extension\Awareness\ReplacerAwareExtensionInterface;
13
use DummyGenerator\Definitions\Extension\Awareness\ReplacerAwareExtensionTrait;
14
15
class Address implements
16
    AddressExtensionInterface,
17
    GeneratorAwareExtensionInterface,
18
    RandomizerAwareExtensionInterface,
19
    ReplacerAwareExtensionInterface
20
{
21
    use GeneratorAwareExtensionTrait;
22
    use RandomizerAwareExtensionTrait;
23
    use ReplacerAwareExtensionTrait;
24
25
    /** @var string[] */
26
    protected array $citySuffix = [
27
        'Ville',
28
    ];
29
30
    /** @var string[] */
31
    protected array $streetSuffix = [
32
        'Street',
33
    ];
34
35
    /** @var string[] */
36
    protected array $cityFormats = [
37
        '{{firstName}}{{citySuffix}}',
38
    ];
39
40
    /** @var string[] */
41
    protected array $streetNameFormats = [
42
        '{{lastName}} {{streetSuffix}}',
43
    ];
44
45
    /** @var string[] */
46
    protected array $streetAddressFormats = [
47
        '{{buildingNumber}} {{streetName}}',
48
    ];
49
50
    /** @var string[] */
51
    protected array $addressFormats = [
52
        '{{streetAddress}} {{postcode}} {{city}}',
53
    ];
54
55
    /** @var string[] */
56
    protected array $buildingNumber = ['%#'];
57
58
    /** @var string[] */
59
    protected array $postcode = ['#####', '##-###'];
60
61
    /** @var string[] */
62
    protected array $country = ['England', 'France'];
63
64 3
    public function citySuffix(): string
65
    {
66 3
        return $this->randomizer->randomElement($this->citySuffix);
67
    }
68
69 4
    public function streetSuffix(): string
70
    {
71 4
        return $this->randomizer->randomElement($this->streetSuffix);
72
    }
73
74 3
    public function buildingNumber(): string
75
    {
76 3
        return $this->replacer->numerify($this->randomizer->randomElement($this->buildingNumber));
77
    }
78
79 2
    public function city(): string
80
    {
81 2
        $format = $this->randomizer->randomElement($this->cityFormats);
82
83 2
        return $this->generator->parse($format);
84
    }
85
86 3
    public function streetName(): string
87
    {
88 3
        $format = $this->randomizer->randomElement($this->streetNameFormats);
89
90 3
        return $this->generator->parse($format);
91
    }
92
93 2
    public function streetAddress(): string
94
    {
95 2
        $format = $this->randomizer->randomElement($this->streetAddressFormats);
96
97 2
        return $this->generator->parse($format);
98
    }
99
100 2
    public function postcode(): string
101
    {
102 2
        return $this->replacer->toUpper($this->replacer->bothify($this->randomizer->randomElement($this->postcode)));
103
    }
104
105 1
    public function address(): string
106
    {
107 1
        $format = $this->randomizer->randomElement($this->addressFormats);
108
109 1
        return $this->generator->parse($format);
110
    }
111
112 1
    public function country(): string
113
    {
114 1
        return $this->randomizer->randomElement($this->country);
115
    }
116
}
117