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

ExpressionStrategy::provideValues()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 12
rs 10
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