Test Setup Failed
Push — main ( ab2c03...5e665b )
by Vasil
03:31
created

Country::fromArray2()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 7
rs 10
ccs 0
cts 0
cp 0
cc 3
nc 3
nop 1
crap 12
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VasilDakov\Econt\Model;
6
7
final class Country
8
{
9
    /*
10
    id	int	[0..1]
11
    code2	string	[0..1] ISO 3166-1 alpha-2 code (e.g. BG, GB, GR)
12
    code3	string	[0..1] ISO 3166-1 alpha-3 code (e.g. BGR ,GBR, GRC)
13
    name	string	[0..1] The bulgarian name of the country
14
    nameEn	string	[0..1] The international name of the country
15
    isEU	boolean	[0..1] True if country is a member of the EU
16 4
    */
17
18
    public function __construct(
19
        public readonly ?int $id,
20
        public readonly ?string $code2,
21
        public readonly ?string $code3,
22
        public readonly ?string $name,
23
        public readonly ?string $nameEn,
24 4
        public readonly ?bool $isEU
25
    ) {
26 4
    }
27
28 4
    public static function fromArray(array $data): Country
29
    {
30 4
        list($id, $code2, $code3, $name, $nameEn, $isEU) = array_values($data);
31
32
        return new Country($id, $code2, $code3, $name, $nameEn, $isEU);
33
    }
34
35
    public static function fromArray2(array $data = []): Country
36
    {
37
        foreach (get_object_vars($obj = new self) as $property => $default) {
0 ignored issues
show
Bug introduced by
The call to VasilDakov\Econt\Model\Country::__construct() has too few arguments starting with id. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
        foreach (get_object_vars($obj = /** @scrutinizer ignore-call */ new self) as $property => $default) {

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
38
            if (!array_key_exists($property, $data)) continue;
39
            $obj->{$property} = $data[$property]; // assign value to object
40
        }
41
        return $obj;
42
    }
43
}
44