ValidValidator   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 84
rs 10
c 0
b 0
f 0
wmc 13

5 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 20 5
A validateUrl() 0 9 3
A validateInfo() 0 2 1
A validateApi() 0 2 1
A validateBpm() 0 9 3
1
<?php
2
3
namespace App\Validator\Constraints\Scenario\Config;
4
5
use App\Entity\Scenario;
6
use Symfony\Component\Validator\Constraint;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Validator\Constraint was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Symfony\Component\Validator\ConstraintValidator;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Validator\ConstraintValidator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
/**
10
 * Class ValidValidator
11
 */
12
final class ValidValidator extends ConstraintValidator
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17
    public function validate($scenario, Constraint $constraint)
18
    {
19
        $config = $scenario->getConfig();
20
21
        switch ($scenario->getType()) {
22
            case Scenario::TYPE_API:
23
                $this->validateApi($config, $constraint);
24
                break;
25
26
            case Scenario::TYPE_BPM:
27
                $this->validateBpm($config, $constraint);
28
                break;
29
30
            case Scenario::TYPE_INFO:
31
                $this->validateInfo($config, $constraint);
32
                break;
33
34
            case Scenario::TYPE_URL:
35
                $this->validateUrl($config, $constraint);
36
                break;
37
        }
38
    }
39
40
    /**
41
     * Validate api scenario config
42
     *
43
     * @param array $config
44
     * @param \Symfony\Component\Validator\Constraint $constraint
45
     */
46
    protected function validateApi(array $config, Constraint $constraint)
47
    {
48
49
    }
50
51
    /**
52
     * Validate bpm scenario config
53
     *
54
     * @param array $config
55
     * @param \Symfony\Component\Validator\Constraint $constraint
56
     */
57
    protected function validateBpm(array $config, Constraint $constraint)
58
    {
59
        foreach (['bpm', 'process_definition_key'] as $attribute) {
60
            if (!array_key_exists($attribute, $config)) {
61
                $this->context
62
                    ->buildViolation($constraint->missing)
63
                    ->setParameter('{{ attribute }}', '"'.$attribute.'"')
64
                    ->atPath('config.'.$attribute)
65
                    ->addViolation();
66
            }
67
        }
68
    }
69
70
    /**
71
     * Validate info scenario config
72
     *
73
     * @param array $config
74
     * @param \Symfony\Component\Validator\Constraint $constraint
75
     */
76
    protected function validateInfo(array $config, Constraint $constraint)
77
    {
78
79
    }
80
81
    /**
82
     * Validate url scenario config
83
     *
84
     * @param array $config
85
     * @param \Symfony\Component\Validator\Constraint $constraint
86
     */
87
    protected function validateUrl(array $config, Constraint $constraint)
88
    {
89
        foreach (['url'] as $attribute) {
90
            if (!array_key_exists($attribute, $config)) {
91
                $this->context
92
                    ->buildViolation($constraint->missing)
93
                    ->setParameter('{{ attribute }}', '"'.$attribute.'"')
94
                    ->atPath('config.'.$attribute)
95
                    ->addViolation();
96
            }
97
        }
98
    }
99
}
100