Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
IsoCountry
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 3
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 data
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 fromData
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3namespace Olz\Api\ApiObjects;
4
5use PhpTypeScriptApi\PhpStan\ApiObjectInterface;
6
7/**
8 * @implements ApiObjectInterface<non-empty-string>
9 */
10class IsoCountry implements ApiObjectInterface {
11    /** @param non-empty-string $alpha2 */
12    public function __construct(protected string $alpha2) {
13    }
14
15    public function data(): mixed {
16        return $this->alpha2;
17    }
18
19    public static function fromData(mixed $data): IsoCountry {
20        if (!is_string($data)) {
21            throw new \InvalidArgumentException("IsoCountry must be string");
22        }
23        if (!$data || !preg_match('/^[a-zA-Z]{2}$/', $data)) {
24            throw new \InvalidArgumentException("IsoCountry must be a 2-letter code");
25        }
26        return new IsoCountry($data);
27    }
28}