Response   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 12
c 2
b 1
f 0
lcom 1
cbo 0
dl 0
loc 66
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getCode() 0 4 1
A getText() 0 10 2
A getLang() 0 10 2
A getFrom() 0 8 2
A getTo() 0 8 2
A getDecodedBodyValue() 0 8 2
1
<?php
2
3
/**
4
 * @Author Chiarillo Massimo
5
 */
6
7
namespace Yandex\TranslatorBundle\Http;
8
9
class Response
10
{
11
    private $decodedBody;
12
13
    /**
14
     * @param String $body
15
     */
16
    public function __construct($body)
17
    {
18
        $this->decodedBody = json_decode($body, true);
19
    }
20
21
    public function getText()
22
    {
23
        $text = $this->getDecodedBodyValue('text');
24
25
        if (!is_array($text)) {
26
            return null;
27
        }
28
29
        return reset($text);
30
    }
31
32
    protected function getLang()
33
    {
34
        $lang = $this->getDecodedBodyValue('lang');
35
36
        if (!$lang) {
37
            return false;
38
        }
39
40
        return explode('-', $lang);
41
    }
42
43
    public function getFrom()
44
    {
45
        if (!$lang = $this->getLang()) {
46
            return null;
47
        }
48
49
        return reset($lang);
50
    }
51
52
    public function getTo()
53
    {
54
        if (!$lang = $this->getLang()) {
55
            return null;
56
        }
57
58
        return end($lang);
59
    }
60
61
    public function getCode()
62
    {
63
        return $this->getDecodedBodyValue('code');
64
    }
65
66
    private function getDecodedBodyValue($key)
67
    {
68
        if (!array_key_exists($key, $this->decodedBody)) {
69
            return null;
70
        }
71
72
        return $this->decodedBody[$key];
73
    }
74
}
75