GetTranslationsResponse::getState()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * This file is part of the badams\MicrosoftTranslator library
4
 *
5
 * @license http://opensource.org/licenses/MIT
6
 * @link https://github.com/badams/microsoft-translator
7
 * @package badams/microsoft-translator
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace badams\MicrosoftTranslator\Responses;
14
15
use badams\MicrosoftTranslator\Language;
16
17
/**
18
 * Class GetTranslationsResponse
19
 * @package badams\MicrosoftTranslator\Responses
20
 * @link https://msdn.microsoft.com/en-us/library/ff512417.aspx
21
 */
22
class GetTranslationsResponse
23
{
24
    /**
25
     * @var Language
26
     */
27
    protected $from;
28
29
    /**
30
     * @var string
31
     */
32
    protected $state;
33
34
    /**
35
     * @var TranslationMatch[]
36
     */
37
    protected $translations;
38
39
    /**
40
     * GetTranslationsResponse constructor.
41
     * @param $from
42
     * @param null $state
43
     */
44 9
    public function __construct($from, $state = null)
45
    {
46 9
        $this->from = new Language((string)$from);
47 9
        $this->state = $state;
48 9
    }
49
50
    /**
51
     * @param \SimpleXMLElement $xml
52
     * @return GetTranslationsResponse
53
     */
54 9
    public static function fromXml(\SimpleXMLElement $xml)
55
    {
56 9
        $instance = new GetTranslationsResponse($xml->From, $xml->State);
57
58 9
        foreach ($xml->Translations->TranslationMatch as $match) {
59 9
            $instance->addTranslation(TranslationMatch::fromXmlElement($match));
60 9
        }
61
62 9
        return $instance;
63
    }
64
65 9
    public function addTranslation(TranslationMatch $translation)
66
    {
67 9
        $this->translations[] = $translation;
68 9
    }
69
70
    /**
71
     * @return TranslationMatch[]
72
     */
73 8
    public function getTranslations()
74
    {
75 6
        return $this->translations;
76 6
    }
77
78
    /**
79
     * @return null|string
80
     */
81 3
    public function getState()
82
    {
83 3
        return $this->state;
84
    }
85
86
    /**
87
     * @return Language
88
     */
89 6
    public function getFrom()
90
    {
91 6
        return $this->from;
92
    }
93
}
94