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