Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
Schema
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3/**
4 * @license MIT
5 * @author hazuki3417<hazuki3417@gmail.com>
6 * @copyright 2022 hazuki3417 all rights reserved.
7 */
8
9namespace Selen\MongoDB\Attributes;
10
11use Attribute;
12use LogicException;
13use Selen\MongoDB\Attribute\SchemaMarkerInterface;
14
15#[Attribute(Attribute::TARGET_CLASS)]
16class Schema implements SchemaMarkerInterface
17{
18    public const TYPE_ROOT     = 'root';
19    public const TYPE_INNER    = 'inner';
20    private const TYPE_SCHEMAS = [
21        self::TYPE_ROOT,
22        self::TYPE_INNER,
23    ];
24    /** @var string */
25    public $type;
26
27    public function __construct(string $type)
28    {
29        if (!\in_array($type, self::TYPE_SCHEMAS, true)) {
30            $format = 'Invalid value. Specify "%s" or "%s" for the schema type';
31            $mes    = \sprintf($format, self::TYPE_ROOT, self::TYPE_INNER);
32            throw new LogicException($mes);
33        }
34        $this->type = $type;
35    }
36}