Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
IdTypeTrait
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
4 / 4
6
100.00% covered (success)
100.00%
1 / 1
 getIdTester
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setIdTester
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setIdType
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 testIdType
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace pvc\struct\types\id;
4
5use pvc\interfaces\struct\types\id\IdTesterInterface;
6use pvc\interfaces\struct\types\id\IdType;
7use pvc\struct\types\err\NonExistentIdTesterException;
8
9trait IdTypeTrait
10{
11    protected IdTesterInterface $idTester;
12
13    protected function getIdTester() : ?IdTesterInterface
14    {
15        return $this->idTester ?? null;
16    }
17
18    public function setIdTester(IdTesterInterface $idTester): void
19    {
20        $this->idTester = $idTester;
21    }
22
23    public function setIdType(IdType $idType) : void
24    {
25        if ($this->getIdTester() === null) {
26            throw new NonExistentIdTesterException();
27        }
28        $this->idTester->setIdType($idType);
29    }
30
31    /**
32     * via the nullsafe operator, this method identifies a key as valid if the
33     * idTester property is not set.  Note that the key can be of any data type
34     * (e.g. an array, an object, etc) and this method will pass it through
35     */
36    public function testIdType($id) : bool
37    {
38        $result = $this->getIdTester()?->testIdType($id);
39        if ($result === null) return true;
40        return $result;
41    }
42}