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

Country   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 7
c 1
b 0
f 0
dl 0
loc 35
rs 10
ccs 5
cts 5
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromArray2() 0 7 3
A __construct() 0 8 1
A fromArray() 0 5 1
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