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

DocumentAnalysis   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 72
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A create() 0 18 3
A getTones() 0 4 1
A getWarning() 0 4 1
1
<?php
2
3
namespace IBM\Watson\ToneAnalyzer\Model;
4
5
use IBM\Watson\Common\Model\CreateableFromArray;
6
7
/**
8
 * Class DocumentAnalysis
9
 */
10
class DocumentAnalysis implements CreateableFromArray
11
{
12
    /**
13
     * @var string
14
     */
15
    const KEY_TONES = 'tones';
16
17
    /**
18
     * @var string
19
     */
20
    const KEY_WARNING = 'warning';
21
22
    /**
23
     * @var array
24
     */
25
    private $tones;
26
27
    /**
28
     * @var null
29
     */
30
    private $warning;
31
32
    /**
33
     * @param array       $tones
34
     * @param null|string $warning
35
     */
36
    public function __construct(array $tones = [], $warning = null)
37
    {
38
        $this->tones = $tones;
39
        $this->warning = $warning;
0 ignored issues
show
Documentation Bug introduced by
It seems like $warning can also be of type string. However, the property $warning is declared as type null. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
40
    }
41
42
    /**
43
     * @param array $data
44
     *
45
     * @return \IBM\Watson\ToneAnalyzer\Model\DocumentAnalysis
46
     */
47
    public static function create(array $data)
48
    {
49
        $tones = [];
50
        $warning = null;
51
52
        foreach ($data[static::KEY_TONES] as $tone) {
53
            $tones[] = ToneScore::create($tone);
54
        }
55
56
        if (isset($data[static::KEY_WARNING])) {
57
            $warning = $data[static::KEY_WARNING];
58
        }
59
60
        return new self(
61
            $tones,
62
            $warning
63
        );
64
    }
65
66
    /**
67
     * @return array
68
     */
69
    public function getTones()
70
    {
71
        return $this->tones;
72
    }
73
74
    /**
75
     * @return null|string
76
     */
77
    public function getWarning()
78
    {
79
        return $this->warning;
80
    }
81
}
82