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

ToneAnalysis   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 69
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 69
loc 69
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A create() 15 15 3
A getDocumentAnalysis() 4 4 1
A getSentenceAnalysis() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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