Issues (3641)

Validator/Constraint/TransferConstraint.php (1 issue)

1
<?php
2
3
/**
4
 * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace Spryker\Zed\PriceProductVolume\Business\Validator\Constraint;
9
10
use Symfony\Component\Validator\Constraints\Composite;
11
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
12
13
class TransferConstraint extends Composite
14
{
15
    /**
16
     * @var string
17
     */
18
    protected const FIELDS = 'fields';
19
20
    /**
21
     * @var string
22
     */
23
    protected const MISSING_FIELD_MESSAGE = 'This field is missing.';
24
25
    /**
26
     * @var array<mixed>
27
     */
28
    public $fields = [];
29
30
    /**
31
     * @param array<\Symfony\Component\Validator\Constraint>|null $options
32
     */
33
    public function __construct($options = null)
34
    {
35
        if (is_array($options)) {
36
            $options = [static::FIELDS => $options];
37
        }
38
39
        parent::__construct($options);
40
    }
41
42
    /**
43
     * @return array<string>
44
     */
45
    public function getRequiredOptions(): array
46
    {
47
        return [static::FIELDS];
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    public function getTargets(): string
54
    {
55
        return static::CLASS_CONSTRAINT;
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function getMissingFieldsMessage(): string
62
    {
63
        return static::MISSING_FIELD_MESSAGE;
64
    }
65
66
    /**
67
     * @return string
68
     */
69
    protected function getCompositeOption(): string
70
    {
71
        return static::FIELDS;
72
    }
73
74
    /**
75
     * {@inheritDoc}
76
     *
77
     * @throws \Symfony\Component\Validator\Exception\ConstraintDefinitionException
78
     *
79
     * @return void
80
     */
81
    protected function initializeNestedConstraints(): void
82
    {
83
        parent::initializeNestedConstraints();
84
85
        if (!is_array($this->fields)) {
0 ignored issues
show
The condition is_array($this->fields) is always true.
Loading history...
86
            throw new ConstraintDefinitionException(sprintf('The option "%s" is expected to be an array in constraint "%s".', static::FIELDS, static::class));
87
        }
88
    }
89
}
90