Completed
Push — master ( 305ae1...054033 )
by Jordi
03:35
created

Response::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Ip2c\Http;
4
5
class Response
6
{
7
    private $status;
8
    private $iso2;
9
    private $iso3;
10
    private $name;
11
12
    public function __construct($response)
13
    {
14
        $this->parseResult($response);
15
    }
16
17 4
    /**
18
     * @param $response
19 4
     * @return Response
20 4
     * @throws \Exception
21 3
     */
22 3
    private function parseResult($response)
23 1
    {
24
        $responseParts = explode(';', $response);
25
        if (count($responseParts) == 4) {
26 3
            list($this->status, $this->iso2, $this->iso3, $this->name) = $responseParts;
27
        } else {
28
            throw new \Exception('Inconsistent response from Ip2c', 1);
29
        }
30
    }
31
32 3
    /**
33
     * @return int
34 3
     */
35
    public function status()
36
    {
37
        return $this->status;
38
    }
39
40 3
    /**
41
     * @return string
42 3
     */
43
    public function iso2()
44
    {
45
        return $this->iso2;
46
    }
47
48 3
    /**
49
     * @return string
50 3
     */
51
    public function iso3()
52
    {
53
        return $this->iso3;
54
    }
55
56 3
    /**
57
     * @return string
58 3
     */
59
    public function name()
60
    {
61
        return $this->name;
62
    }
63
}
64