Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
IsoCountry
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
3 / 3
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 data
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 fromData
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
4
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}