Completed
Pull Request — develop (#5)
by Adam
01:21
created

SentenceAnalysis   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 49
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 14 3
A getSentences() 0 4 1
1
<?php
2
3
namespace IBM\Watson\ToneAnalyzer\Model;
4
5
use IBM\Watson\Common\Model\ApiResponseInterface;
6
7
class SentenceAnalysis implements ApiResponseInterface
8
{
9
    /**
10
     * @var array
11
     */
12
    private $sentences;
13
14
    /**
15
     * SentenceAnalysis constructor.
16
     *
17
     * @param array $sentences
18
     */
19
    public function __construct(array $sentences)
20
    {
21
        $this->sentences = $sentences;
22
    }
23
24
    /**
25
     * Create sentence analysis
26
     *
27
     * @param array $data
28
     *
29
     * @return \IBM\Watson\ToneAnalyzer\Model\SentenceAnalysis
30
     */
31
    public static function create(array $data)
32
    {
33
        $sentences = [];
34
35
        if (!isset($data['sentences_tone'])) {
36
            return new self($sentences);
37
        }
38
39
        foreach ($data['sentences_tone'] as $sentenceTone) {
40
            $sentences[] = Sentence::create($sentenceTone);
41
        }
42
43
        return new self($sentences);
44
    }
45
46
    /**
47
     * Get sentences
48
     *
49
     * @return array
50
     */
51
    public function getSentences()
52
    {
53
        return $this->sentences;
54
    }
55
}
56