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

UtteranceAnalysis::getText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace IBM\Watson\ToneAnalyzer\Model;
4
5
use IBM\Watson\Common\Model\CreateableFromArray;
6
7
/**
8
 * Class UtteranceAnalysis
9
 */
10
class UtteranceAnalysis implements CreateableFromArray
11
{
12
    /**
13
     * @var string
14
     */
15
    const KEY_ID = 'utterance_id';
16
17
    /**
18
     * @var string
19
     */
20
    const KEY_TEXT = 'utterance_text';
21
22
    /**
23
     * @var string
24
     */
25
    const KEY_TONES = 'tones';
26
27
    /**
28
     * @var string
29
     */
30
    const KEY_ERROR = 'error';
31
32
    /**
33
     * @var integer
34
     */
35
    private $id;
36
37
    /**
38
     * @var string
39
     */
40
    private $text;
41
42
    /**
43
     * @var array
44
     */
45
    private $tones;
46
47
    /**
48
     * @var null|string
49
     */
50
    private $error;
51
52
    /**
53
     * @param integer     $id
54
     * @param string      $text
55
     * @param array       $tones
56
     * @param null|string $error
57
     */
58
    public function __construct($id, $text, array $tones, $error = null)
59
    {
60
        $this->id    = $id;
61
        $this->text  = $text;
62
        $this->tones = $tones;
63
        $this->error = $error;
64
    }
65
66
    /**
67
     * @param array $data
68
     *
69
     * @return \IBM\Watson\ToneAnalyzer\Model\UtteranceAnalysis
70
     */
71
    public static function create(array $data)
72
    {
73
        $tones = [];
74
        foreach ($data[static::KEY_TONES] as $tone) {
75
            $tones[] = ToneScore::create($tone);
76
        }
77
78
        return new self(
79
            $data[static::KEY_ID],
80
            $data[static::KEY_TEXT],
81
            $tones,
82
            isset($data[static::KEY_ERROR]) ?: null
0 ignored issues
show
Bug introduced by
It seems like isset($data[static::KEY_ERROR]) ?: null can also be of type boolean; however, IBM\Watson\ToneAnalyzer\...Analysis::__construct() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
83
        );
84
    }
85
86
    /**
87
     * @return integer
88
     */
89
    public function getId()
90
    {
91
        return $this->id;
92
    }
93
94
    /**
95
     * @return string
96
     */
97
    public function getText()
98
    {
99
        return $this->text;
100
    }
101
102
    /**
103
     * @return array
104
     */
105
    public function getTones()
106
    {
107
        return $this->tones;
108
    }
109
110
    /**
111
     * @return null|string
112
     */
113
    public function getError()
114
    {
115
        return $this->error;
116
    }
117
}
118