Completed
Push — master ( 46457b...75f199 )
by Byron
02:07
created

GetTranslationsResponse::getState()   A

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
use badams\MicrosoftTranslator\Language;
15
16
/**
17
 * Class GetTranslationsResponse
18
 * @package badams\MicrosoftTranslator\Responses
19
 * @link https://msdn.microsoft.com/en-us/library/ff512417.aspx
20
 */
21
class GetTranslationsResponse
22
{
23
    /**
24
     * @var Language
25
     */
26
    protected $from;
27
28
    /**
29
     * @var string
30
     */
31
    protected $state;
32
33
    /**
34
     * @var TranslationMatch[]
35
     */
36
    protected $translations;
37
38
    /**
39
     * GetTranslationsResponse constructor.
40
     * @param $from
41
     * @param null $state
42
     */
43 6
    public function __construct($from, $state = null)
44
    {
45 6
        $this->from = new Language((string)$from);
46 6
        $this->state = $state;
47 6
    }
48
49
    /**
50
     * @param \SimpleXMLElement $xml
51
     * @return GetTranslationsResponse
52
     */
53 6
    public static function fromXml(\SimpleXMLElement $xml)
54
    {
55 6
        $instance = new GetTranslationsResponse($xml->From, $xml->State);
56
57 6
        foreach ($xml->Translations as $match) {
58 6
            $instance->addTranslation(TranslationMatch::fromXmlElement($match->TranslationMatch));
59 6
        }
60
61 6
        return $instance;
62
    }
63
64 6
    public function addTranslation(TranslationMatch $translation)
65
    {
66 6
        $this->translations[] = $translation;
67 6
    }
68
69
    /**
70
     * @return TranslationMatch[]
71
     */
72 5
    public function getTranslations()
73
    {
74 5
        return $this->translations;
75
    }
76
77
    /**
78
     * @return null|string
79
     */
80 3
    public function getState()
81
    {
82 3
        return $this->state;
83
    }
84
85
    /**
86
     * @return Language
87
     */
88 3
    public function getFrom()
89
    {
90 3
        return $this->from;
91
    }
92
}