Completed
Push — master ( 390b51...0e9cfd )
by Mario
11:43
created

UltravioletIndexDenormalizer::denormalize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
c 0
b 0
f 0
rs 9.6666
cc 2
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Marek\OpenWeatherMap\Denormalizer;
6
7
use Marek\OpenWeatherMap\API\Value\Response\APIResponse;
8
use Marek\OpenWeatherMap\API\Value\Response\GeographicCoordinates;
9
use Marek\OpenWeatherMap\API\Value\Response\UltravioletIndex\UltravioletIndex;
10
11
class UltravioletIndexDenormalizer extends AbstractDenormalizer
12
{
13
    public function denormalize(array $data, APIResponse $response): APIResponse
14
    {
15
        if (!$response instanceof UltravioletIndex) {
16
            return $response;
17
        }
18
19
        $response->value = $this->getData('value', $data);
20
        $response->date = $this->getDateTimeFromTimestamp('date', $data);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getDateTimeFromTimestamp('date', $data) of type object<DateTimeImmutable> is incompatible with the declared type object<DateTime> of property $date.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
21
        $response->isoDate = $this->getValue('date_iso', $data, \DateTimeInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getValue('date_is...teTimeInterface::class) can also be of type array. However, the property $isoDate is declared as type object<DateTime>. 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...
22
23
        $location = new GeographicCoordinates();
24
        $location->latitude = $this->getData('lat', $data);
25
        $location->longitude = $this->getData('lon', $data);
26
27
        $response->location = $location;
0 ignored issues
show
Documentation Bug introduced by
It seems like $location of type object<Marek\OpenWeather...\GeographicCoordinates> is incompatible with the declared type object<Marek\OpenWeather...alue\Response\Location> of property $location.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
28
29
        return $response;
30
    }
31
}
32