LengthStrategy   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 94.44%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 32
ccs 17
cts 18
cp 0.9444
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A generateArguments() 0 20 3
A getValidatorProperty() 0 3 1
A getAttributeClassName() 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\Length;
17
18
class LengthStrategy extends AbstractConstraintStrategy
19
{
20 1
    protected function generateArguments(array $config): array
21
    {
22 1
        $parent = parent::generateArguments($config);
23 1
        $attributesInteger = ['min', 'max'];
24 1
        foreach ($attributesInteger as $attribute) {
25 1
            if (!\array_key_exists($attribute, $config)) {
26
                continue;
27
            }
28
29 1
            $config[$attribute] = (int) $config[$attribute];
30
        }
31
32 1
        $current = [
33 1
            'max' => $config['max'] ?? null,
34 1
            'min' => $config['min'] ?? null,
35 1
            'minMessage' => $config['min_message'] ?? null,
36 1
            'maxMessage' => $config['max_message'] ?? null,
37 1
        ];
38
39 1
        return array_filter(array_merge($parent, $current));
40
    }
41
42 1
    protected function getValidatorProperty(): string
43
    {
44 1
        return 'length';
45
    }
46
47 1
    protected function getAttributeClassName(): string
48
    {
49 1
        return Length::class;
50
    }
51
}
52