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

TranslationMatch::getTranslatedText()   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
15
/**
16
 * Class TranslationMatch
17
 * @package badams\MicrosoftTranslator\Responses
18
 * @link https://msdn.microsoft.com/en-us/library/ff512417.aspx
19
 */
20
class TranslationMatch
21
{
22
    /**
23
     * @var string
24
     */
25
    protected $error;
26
27
    /**
28
     * @var int
29
     */
30
    protected $count;
31
32
    /**
33
     * @var int
34
     */
35
    protected $matchDegree;
36
37
    /**
38
     * @var int
39
     */
40
    protected $rating;
41
42
    /**
43
     * @var string
44
     */
45
    protected $translatedText;
46
47
    /**
48
     * TranslationMatch constructor.
49
     * @param $count
50
     * @param $matchDegree
51
     * @param $rating
52
     * @param $translatedText
53
     */
54 6
    public function __construct($count, $matchDegree, $rating, $translatedText, $error = null)
55
    {
56 6
        $this->count = (int)$count;
57 6
        $this->matchDegree = (int)$matchDegree;
58 6
        $this->rating = (int)$rating;
59 6
        $this->translatedText = $translatedText;
60 6
        $this->error = $error;
61 6
    }
62
63
    /**
64
     * @param \SimpleXMLElement $xml
65
     * @return TranslationMatch
66
     */
67 6
    public static function fromXmlElement(\SimpleXMLElement $xml)
68
    {
69 6
        return new TranslationMatch(
70 6
            (string)$xml->Count,
71 6
            (string)$xml->MatchDegree,
72 6
            (string)$xml->Rating,
73 6
            (string)$xml->TranslatedText
74 6
        );
75
    }
76
77
    /**
78
     * @return string
79
     */
80 3
    public function getTranslatedText()
81
    {
82 3
        return $this->translatedText;
83
    }
84
85
    /**
86
     * @return int
87
     */
88 3
    public function getMatchDegree()
89
    {
90 3
        return $this->matchDegree;
91
    }
92
93
    /**
94
     * @return int
95
     */
96 3
    public function getRating()
97
    {
98 3
        return $this->rating;
99
    }
100
101
    /**
102
     * @return int
103
     */
104 3
    public function getCount()
105
    {
106 3
        return $this->count;
107
    }
108
109
    /**
110
     * @return null|string
111
     */
112 3
    public function getError()
113
    {
114 3
        return $this->error;
115
    }
116
}