Humidity::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 1
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 *
4
 * PHP version 5.5
5
 *
6
 * @package Forecast\Model
7
 * @author  Sergey V.Kuzin <[email protected]>
8
 * @license MIT
9
 */
10
declare(strict_types=1);
11
12
namespace Forecast\Model;
13
14
15
use Forecast\ForecastItemInterface;
16
17
class Humidity implements ModelInterface
18
{
19
    /** @var float  */
20
    protected $humidity = null;
21
    /** @var float  */
22
    protected $dewPoint = null;
23
24
    /**
25
     * @api
26
     *
27
     * @return float
28
     */
29
    public function getHumidity(): float
30
    {
31
        return $this->humidity;
32
    }
33
34
    /**
35
     * @api
36
     *
37
     * @return float
38
     */
39
    public function getDewPoint(): float
40
    {
41
        return $this->dewPoint;
42
    }
43
44
    /**
45
     * @api
46
     *
47
     * @return string
48
     */
49
    public function __toString(): string
50
    {
51
        return (string)$this->humidity;
52
    }
53
54
    public function setData(array $data): self
55
    {
56
        if (
57
            !($trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)) ||
58
            !(isset($trace[1]['class']) && in_array(ForecastItemInterface::class, class_implements($trace[1]['class'])))
59
        ) {
60
            trigger_error('Member not available: setData', E_USER_ERROR);
61
        }
62
63
        $this->humidity = $data['humidity'] * 100;
0 ignored issues
show
Documentation Bug introduced by
It seems like $data['humidity'] * 100 can also be of type integer. However, the property $humidity is declared as type double. 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...
64
        $this->dewPoint = isset($data['dewPoint']) ? $data['dewPoint'] : null;
0 ignored issues
show
Documentation Bug introduced by
It seems like isset($data['dewPoint'])...data['dewPoint'] : null can also be of type integer. However, the property $dewPoint is declared as type double. 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...
65
66
        return $this;
67
    }
68
}
69