| Total Complexity | 9 |
| Total Lines | 76 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 8 | class Country |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * Uppercased country code |
||
| 12 | * @var string |
||
| 13 | */ |
||
| 14 | protected $code; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var string |
||
| 18 | */ |
||
| 19 | protected $name; |
||
| 20 | |||
| 21 | public function __construct(string $code = null, string $name = null) |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Create from a given source (array, pairs) |
||
| 32 | * |
||
| 33 | * Country::create('be,Belgium') |
||
| 34 | * Country::create('be','Belgium') |
||
| 35 | * Country::create(['be','Belgium']) |
||
| 36 | * |
||
| 37 | * @param mixed $source |
||
| 38 | * @param array<string> $more |
||
| 39 | * @return self |
||
| 40 | */ |
||
| 41 | public static function create($source, ...$more) |
||
| 42 | { |
||
| 43 | if (!is_array($source)) { |
||
| 44 | $source = explode(',', $source); |
||
| 45 | } |
||
| 46 | if (!empty($more)) { |
||
| 47 | $source = array_merge($source, $more); |
||
| 48 | } |
||
| 49 | return new self($source[0], $source[1]); |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Get the uppercased country code |
||
| 54 | */ |
||
| 55 | public function getCode(): ?string |
||
| 56 | { |
||
| 57 | return $this->code; |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Set the country code |
||
| 62 | */ |
||
| 63 | public function setCode(string $code): self |
||
| 64 | { |
||
| 65 | $this->code = strtoupper($code); |
||
| 66 | return $this; |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Get the name of the country |
||
| 71 | */ |
||
| 72 | public function getName(): ?string |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Set the name of the country |
||
| 79 | */ |
||
| 80 | public function setName(string $name): self |
||
| 84 | } |
||
| 85 | } |
||
| 86 |