ValidValidator::validateFormio()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 2
1
<?php
2
3
namespace App\Validator\Constraints\Form\Config;
4
5
use App\Entity\Form;
6
use Symfony\Component\Validator\Constraint;
7
use Symfony\Component\Validator\ConstraintValidator;
8
9
/**
10
 * Class ValidValidator
11
 */
12
final class ValidValidator extends ConstraintValidator
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17
    public function validate($form, Constraint $constraint)
18
    {
19
        $config = $form->getConfig();
20
21
        switch ($form->getType()) {
22
            case Form::TYPE_FORMIO:
23
                $this->validateFormio($config, $constraint);
24
                break;
25
        }
26
    }
27
28
    /**
29
     * Validate formio form config
30
     *
31
     * @param array $config
32
     * @param \Symfony\Component\Validator\Constraint $constraint
33
     */
34
    protected function validateFormio(array $config, Constraint $constraint)
35
    {
36
        foreach (['title', 'display', 'type', 'name', 'path', 'components', 'submissionAccess'] as $attribute) {
37
            if (!array_key_exists($attribute, $config)) {
38
                $this->context
39
                    ->buildViolation($constraint->missing)
40
                    ->setParameter('{{ attribute }}', '"'.$attribute.'"')
41
                    ->atPath('config.'.$attribute)
42
                    ->addViolation();
43
            }
44
        }
45
    }
46
}
47