Passed
Push — master ( ff7c30...ced429 )
by Jhao
02:29
created

GenericRequest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 7
c 1
b 0
f 0
dl 0
loc 22
ccs 8
cts 9
cp 0.8889
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 3 1
A __construct() 0 7 2
A toArray() 0 3 1
1
<?php
2
3
/**
4
 * This file is part of RussianPost SDK package.
5
 *
6
 * © Appwilio (http://appwilio.com), greabock (https://github.com/greabock), JhaoDa (https://github.com/jhaoda)
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Appwilio\RussianPostSDK\Core;
15
16
final class GenericRequest implements Arrayable
17
{
18
    /** @var array */
19
    private $data;
20
21 4
    public static function create(iterable $data): self
22
    {
23 4
        return new self($data);
24
    }
25
26 4
    public function __construct(iterable $data)
27
    {
28 4
        if ($data instanceof \Traversable) {
29
            $data = \iterator_to_array($data);
30
        }
31
32 4
        $this->data = $data;
0 ignored issues
show
Documentation Bug introduced by
It seems like $data can also be of type iterable. However, the property $data is declared as type array. 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...
33 4
    }
34
35 4
    public function toArray(): array
36
    {
37 4
        return $this->data;
38
    }
39
}
40