Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| Types | |
100.00% |
6 / 6 |
|
100.00% |
6 / 6 |
6 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| schemaOf | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| typeOf | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isNode | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| clearCache | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Cosray\Node; |
| 6 | |
| 7 | use Cosray\Node\Schema\Registry; |
| 8 | |
| 9 | class Types |
| 10 | { |
| 11 | /** @var array<class-string, Schema> */ |
| 12 | private array $cache = []; |
| 13 | |
| 14 | private readonly Registry $registry; |
| 15 | |
| 16 | public function __construct(?Registry $registry = null) |
| 17 | { |
| 18 | $this->registry = $registry ?? Registry::withDefaults(); |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * @param class-string $class |
| 23 | */ |
| 24 | public function schemaOf(string $class): Schema |
| 25 | { |
| 26 | return $this->cache[$class] ??= new Schema($class, $this->registry); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @param class-string $class |
| 31 | */ |
| 32 | public function typeOf(string $class): Type |
| 33 | { |
| 34 | return new Type($class, $this); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * @param class-string $class |
| 39 | */ |
| 40 | public function get(string $class, string $key, mixed $default = null): mixed |
| 41 | { |
| 42 | return $this->schemaOf($class)->get($key, $default); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @param class-string $class |
| 47 | */ |
| 48 | public function isNode(string $class): bool |
| 49 | { |
| 50 | return class_exists($class); |
| 51 | } |
| 52 | |
| 53 | public function clearCache(): void |
| 54 | { |
| 55 | $this->cache = []; |
| 56 | } |
| 57 | } |