ActionField   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
eloc 19
c 1
b 0
f 1
dl 0
loc 29
ccs 0
cts 14
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A configureOptions() 0 27 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LAG\AdminBundle\Field;
6
7
use Symfony\Component\OptionsResolver\Options;
8
use Symfony\Component\OptionsResolver\OptionsResolver;
9
10
/**
11
 * Display a link with button render and options.
12
 */
13
class ActionField extends AbstractField
14
{
15
    public function configureOptions(OptionsResolver $resolver): void
16
    {
17
        $resolver
18
            ->setDefaults([
19
                'template' => '@LAGAdmin/fields/action.html.twig',
20
                'translation' => true,
21
                'property_path' => null,
22
            ])
23
            ->addNormalizer('attr', function (Options $options, $value) {
24
                if (!empty($value['class'])) {
25
                    return $value;
26
                }
27
                $action = null;
28
29
                if ($options->offsetExists('action')) {
30
                    $action = $options->offsetGet('action');
31
                }
32
33
                if ('update' === $action) {
34
                    $value['class'] = 'btn btn-primary btn-sm';
35
                } elseif ('delete' === $action) {
36
                    $value['class'] = 'btn btn-danger btn-sm';
37
                } else {
38
                    $value['class'] = 'btn btn-secondary btn-sm';
39
                }
40
41
                return $value;
42
            })
43
        ;
44
    }
45
}
46