Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
Nest
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
6 / 6
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\AttributeMarkerInterface;
14
15#[Attribute(Attribute::TARGET_PROPERTY)]
16class Nest implements AttributeMarkerInterface
17{
18    public const TYPE_OBJECT       = 'object';
19    public const TYPE_ARRAY_OBJECT = 'arrayObject';
20    private const TYPE_SCHEMAS     = [
21        self::TYPE_OBJECT,
22        self::TYPE_ARRAY_OBJECT,
23    ];
24    /** @var string */
25    public $type;
26    /** @var string */
27    public $schemaClassName;
28
29    public function __construct(string $type, string $schemaClassName)
30    {
31        if (!\in_array($type, self::TYPE_SCHEMAS, true)) {
32            $format = 'Invalid value. Specify "%s" or "%s" for the nest type';
33            $mes    = \sprintf($format, self::TYPE_OBJECT, self::TYPE_ARRAY_OBJECT);
34            throw new LogicException($mes);
35        }
36        $this->type            = $type;
37        $this->schemaClassName = $schemaClassName;
38    }
39}