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

ToneAnalysis::create()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 15

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
dl 15
loc 15
rs 9.7666
c 0
b 0
f 0
cc 3
nc 2
nop 1
1
<?php
2
3
namespace IBM\Watson\ToneAnalyzer\Model;
4
5
use IBM\Watson\Common\Model\CreateableFromArray;
6
7
/**
8
 * Class ToneAnalysis
9
 */
10 View Code Duplication
class ToneAnalysis implements CreateableFromArray
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
{
12
    /**
13
     * @var string
14
     */
15
    const KEY_DOCUMENT_TONE = 'document_tone';
16
17
    /**
18
     * @var string
19
     */
20
    const KEY_SENTENCE_TONE = 'sentences_tone';
21
22
    /**
23
     * @var \IBM\Watson\ToneAnalyzer\Model\DocumentAnalysis
24
     */
25
    private $documentAnalysis;
26
27
    /**
28
     * @var array
29
     */
30
    private $sentenceAnalysis;
31
32
    /**
33
     * @param \IBM\Watson\ToneAnalyzer\Model\DocumentAnalysis $documentAnalysis
34
     * @param array                                           $sentenceAnalysis
35
     */
36
    public function __construct(DocumentAnalysis $documentAnalysis, array $sentenceAnalysis = [])
37
    {
38
        $this->documentAnalysis = $documentAnalysis;
39
        $this->sentenceAnalysis = $sentenceAnalysis;
40
    }
41
42
    /**
43
     * @param array $data
44
     *
45
     * @return \IBM\Watson\ToneAnalyzer\Model\ToneAnalysis
46
     */
47
    public static function create(array $data)
48
    {
49
        $sentenceTone = [];
50
51
        if (isset($data[static::KEY_SENTENCE_TONE])) {
52
            foreach ($data[static::KEY_SENTENCE_TONE] as $sentence) {
53
                $sentenceTone[] = SentenceAnalysis::create($sentence);
54
            }
55
        }
56
57
        return new self(
58
            DocumentAnalysis::create($data[static::KEY_DOCUMENT_TONE]),
59
            $sentenceTone
60
        );
61
    }
62
63
    /**
64
     * @return \IBM\Watson\ToneAnalyzer\Model\DocumentAnalysis
65
     */
66
    public function getDocumentAnalysis()
67
    {
68
        return $this->documentAnalysis;
69
    }
70
71
    /**
72
     * @return array
73
     */
74
    public function getSentenceAnalysis()
75
    {
76
        return $this->sentenceAnalysis;
77
    }
78
}
79