ExpressionStrategy::provideValues()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

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
ccs 6
cts 7
cp 0.8571
crap 3.0261
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 1
    public function generateArguments(array $config): array
21
    {
22 1
        $parent = parent::generateArguments($config);
23
24 1
        $parent['expression'] = $config['expression'];
25
26 1
        $this->provideValues($parent, $config);
27
28 1
        return $parent;
29
    }
30
31
    /**
32
     * @param array<string, mixed> $args
33
     * @param array<string, mixed> $config
34
     *
35
     * @return void
36
     */
37 1
    protected function provideValues(array &$args, array $config): void
38
    {
39 1
        if (empty($config['variable'])) {
40
            return;
41
        }
42
43 1
        $values = [];
44 1
        foreach ($config['variable'] as $value) {
45 1
            $values[$value['name']] = $this->sanitize($value['value']);
46
        }
47
48 1
        $args['values'] = $values;
49
    }
50
51 1
    protected function getValidatorProperty(): string
52
    {
53 1
        return 'expression';
54
    }
55
56 1
    protected function getAttributeClassName(): string
57
    {
58 1
        return Expression::class;
59
    }
60
}
61