Issues (5)

src/Schema.php (1 issue)

1
<?php
2
/**
3
 * Schema Validator
4
 *
5
 * @author Vlad Shashkov <[email protected]>
6
 * @copyright Copyright (c) 2021, The Myaza Software
7
 */
8
9
declare(strict_types=1);
10
11
namespace SchemaValidator;
12
13
use Symfony\Component\Validator\Constraint;
14
15
final class Schema extends Constraint
16
{
17
    public const MISSING_FILED_CODE    = 'dddad9b7-b802-425d-a433-b56b39c5c3eb';
18
    public const UNKNOWN_RESOURCE_CODE = '771fd9d5-ea63-4523-9b2d-c2977efc50e3';
19
    public const INVALID_TYPE_ERROR    = '24231bed-2239-420e-add0-ae2a80ba360c';
20
21
    public const MESSAGE_FILED_MISSING = 'This field is missing.';
22
    public const UNKNOWN_RESOURCE      = 'Unknown resource. Allowed: {{ allowed }}';
23
    public const INVALID_TYPE          = 'This value should be of type {{ type }}.';
24
25
    /**
26
     * @var class-string
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string.
Loading history...
27
     */
28
    public string $type;
29
30
    public string $rootPath = '';
31
32
    public bool $strictTypes = false;
33
34
    /**
35
     * Schema constructor.
36
     *
37
     * @psalm-suppress UninitializedProperty,PossiblyNullArgument,MixedArgument
38
     *
39
     * @param string[] $groups
40
     */
41 39
    public function __construct(array $options = [], array $groups = null, mixed $payload = null)
42
    {
43 39
        parent::__construct($options, $groups, $payload);
44
45 39
        if (!class_exists($this->type) && !interface_exists($this->type)) {
46 1
            throw new \InvalidArgumentException(sprintf('Not found class or interface: %s', $this->type));
47
        }
48 38
    }
49
50
    /**
51
     * @return array<string>
52
     */
53 39
    public function getRequiredOptions(): array
54
    {
55 39
        return ['type'];
56
    }
57
58 1
    public function getTargets(): string
59
    {
60 1
        return self::CLASS_CONSTRAINT;
61
    }
62
}
63