Region::setName()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace EddTurtle\DirectUpload;
4
5
use EddTurtle\DirectUpload\Exceptions\InvalidRegionException;
6
7
/**
8
 * Class Region
9
 *
10
 * Region signifies an AWS Region, created and identified by it's hyphenated name.
11
 * More info on these can be found at: http://amzn.to/1FtPG6r
12
 *
13
 * @package EddTurtle\DirectUpload
14
 */
15
class Region
16
{
17
    private $possibleOptions = [
18
        // US
19
        "us-east-1",
20
        "us-east-2",
21
        "us-west-1",
22
        "us-west-2",
23
        // Africa
24
        "af-south-1",
25
        // Asia-Pacific
26
        "ap-east-1",
27
        "ap-south-1",
28
        "ap-northeast-1",
29
        "ap-northeast-2",
30
        "ap-northeast-3",
31
        "ap-southeast-1",
32
        "ap-southeast-2",
33
        // Canada
34
        "ca-central-1",
35
        // China
36
        "cn-north-1",
37
        "cn-northwest-1",
38
        // EU
39
        "eu-central-1",
40
        "eu-west-1",
41
        "eu-west-2",
42
        "eu-west-3",
43
        "eu-north-1",
44
        "eu-south-1",
45
        // Other
46
        "sa-east-1",
47
        "me-south-1",
48
    ];
49
50
    /**
51
     * @var string
52
     */
53
    private $name;
54
55
    public function __construct(string $region)
56
    {
57
        $this->setName($region);
58
    }
59
60
    /**
61
     * @return string the aws region.
62
     */
63
    public function __toString()
64
    {
65
        return $this->getName();
66
    }
67
68
    /**
69
     * @param string $region the aws region.
70
     *
71
     * @throws InvalidRegionException
72
     */
73
    public function setName(string $region): void
74
    {
75
        $region = strtolower($region);
76
        if (!in_array($region, $this->possibleOptions)) {
77
            throw new InvalidRegionException;
78
        }
79
        $this->name = $region;
80
    }
81
82
    /**
83
     * @return string the aws region.
84
     */
85
    public function getName(): string
86
    {
87
        return $this->name;
88
    }
89
}
90