Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 7 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| IdTester | |
0.00% |
0 / 7 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setIdType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| testIdType | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
30 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace pvc\struct\types\id; |
| 4 | |
| 5 | use pvc\interfaces\struct\types\id\IdTesterInterface; |
| 6 | use pvc\interfaces\struct\types\id\IdType; |
| 7 | |
| 8 | class IdTester implements IdTesterInterface |
| 9 | { |
| 10 | public function __construct(protected IdType $idType = IdType::Integer) {} |
| 11 | |
| 12 | public function setIdType(IdType $idType): void |
| 13 | { |
| 14 | $this->idType = $idType; |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * testIdType |
| 19 | * @param mixed $id |
| 20 | * |
| 21 | * @return bool |
| 22 | * |
| 23 | * This method also encapsulates the restriction that if typed as integers, |
| 24 | * ids must be non-negative. |
| 25 | */ |
| 26 | public function testIdType(mixed $id) : bool |
| 27 | { |
| 28 | return match (gettype($id)) { |
| 29 | 'string' => $this->idType == IdType::String, |
| 30 | 'integer' => ($this->idType == IdType::Integer) && ($id >= 0), |
| 31 | default => false, |
| 32 | }; |
| 33 | } |
| 34 | } |