ExpressionStrategy   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 93.75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 41
ccs 15
cts 16
cp 0.9375
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 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