Passed
Pull Request — develop (#23)
by Adam
01:31
created

DocumentAnalysis::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace IBM\Watson\ToneAnalyzer\Model;
6
7
use IBM\Watson\Common\Model\CreatableFromArray;
8
9
/**
10
 * DocumentAnalysis containing list of tones.
11
 */
12
class DocumentAnalysis implements CreatableFromArray
13
{
14
    const KEY_TONES = 'tones';
15
    const KEY_WARNING = 'warning';
16
17
    /**
18
     * @var array
19
     */
20
    private $tones;
21
22
    /**
23
     * @var string
24
     */
25
    private $warning;
26
27
    /**
28
     * @param array  $tones   Array of ToneScore objects.
29
     * @param string $warning Warning from response.
30
     */
31
    public function __construct(array $tones, string $warning = null)
32
    {
33
        $this->tones = $tones;
34
        $this->warning = $warning;
35
    }
36
37
    /**
38
     * Create DocumentAnalysis object from array.
39
     *
40
     * @param array $data
41
     *
42
     * @return \IBM\Watson\Common\Model\CreatableFromArray
43
     */
44
    public static function create(array $data): CreatableFromArray
45
    {
46
        $warning = null;
47
48
        if (isset($data[static::KEY_WARNING])) {
49
            $warning = $data[static::KEY_WARNING];
50
        }
51
52
        return new self($data[static::KEY_TONES], $warning);
53
    }
54
55
    /**
56
     * Get DocumentAnalysis tones.
57
     *
58
     * @return array
59
     */
60
    public function getTones(): array
61
    {
62
        return $this->tones;
63
    }
64
65
    /**
66
     * Get warning.
67
     *
68
     * @return string
69
     */
70
    public function getWarning(): string
71
    {
72
        return $this->warning;
73
    }
74
}
75