Test Failed
Pull Request — master (#12)
by Stanislau
03:12
created

ExpressionStrategy   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getAttributeClassName() 0 3 1
A generateArguments() 0 9 1
A provideValues() 0 12 3
A getValidatorProperty() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 *  This file is part of the Micro framework package.
7
 *
8
 *  (c) Stanislau Komar <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Micro\Library\DTO\Preparation\Processor\Property\Assert;
15
16
use Symfony\Component\Validator\Constraints\Expression;
17
18
class ExpressionStrategy extends AbstractConstraintStrategy
19
{
20
    public function generateArguments(array $config): array
21
    {
22
        $parent = parent::generateArguments($config);
23
24
        $parent['expression'] = $config['expression'];
25
26
        $this->provideValues($parent, $config);
27
28
        return $parent;
29
    }
30
31
    protected function provideValues(array &$args, array &$config): void
32
    {
33
        if (empty($config['variable'])) {
34
            return;
35
        }
36
37
        $values = [];
38
        foreach ($config['variable'] as $value) {
39
            $values[$value['name']] = $this->sanitize($value['value']);
40
        }
41
42
        $args['values'] = $values;
43
    }
44
45
    protected function getValidatorProperty(): string
46
    {
47
        return 'expression';
48
    }
49
50
    protected function getAttributeClassName(): string
51
    {
52
        return Expression::class;
53
    }
54
}
55