Completed
Push — develop ( 9b1d71...66130e )
by Adam
03:07 queued 01:21
created

SentenceAnalysis   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 88
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A create() 0 14 2
A getId() 0 4 1
A getText() 0 4 1
A getTones() 0 4 1
1
<?php
2
3
namespace IBM\Watson\ToneAnalyzer\Model;
4
5
use IBM\Watson\Common\Model\CreateableFromArray;
6
7
/**
8
 * Class SentenceAnalysis
9
 */
10
class SentenceAnalysis implements CreateableFromArray
11
{
12
    /**
13
     * @var string
14
     */
15
    const KEY_ID = 'sentence_id';
16
17
    /**
18
     * @var string
19
     */
20
    const KEY_TEXT = 'text';
21
22
    /**
23
     * @var string
24
     */
25
    const KEY_TONES = 'tones';
26
27
    /**
28
     * @var string
29
     */
30
    private $id;
31
32
    /**
33
     * @var string
34
     */
35
    private $text;
36
37
    /**
38
     * @var array
39
     */
40
    private $tones;
41
42
    /**
43
     * @param string $id
44
     * @param string $text
45
     * @param array  $tones
46
     */
47
    public function __construct($id, $text, array $tones = [])
48
    {
49
        $this->id    = $id;
50
        $this->text  = $text;
51
        $this->tones = $tones;
52
    }
53
54
    /**
55
     * @param array $data
56
     *
57
     * @return \IBM\Watson\ToneAnalyzer\Model\SentenceAnalysis
58
     */
59
    public static function create(array $data)
60
    {
61
        $tones = [];
62
63
        foreach ($data[static::KEY_TONES] as $tone) {
64
            $tones[] = ToneScore::create($tone);
65
        }
66
67
        return new self(
68
            $data[static::KEY_ID],
69
            $data[static::KEY_TEXT],
70
            $tones
71
        );
72
    }
73
74
    /**
75
     * @return string
76
     */
77
    public function getId()
78
    {
79
        return $this->id;
80
    }
81
82
    /**
83
     * @return string
84
     */
85
    public function getText()
86
    {
87
        return $this->text;
88
    }
89
90
    /**
91
     * @return array
92
     */
93
    public function getTones()
94
    {
95
        return $this->tones;
96
    }
97
}
98