Completed
Pull Request — dev (#19)
by Arnaud
14:27 queued 06:29
created

AdminConfiguration::configureOptions()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 53
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 23
CRAP Score 3.0006

Importance

Changes 3
Bugs 1 Features 2
Metric Value
c 3
b 1
f 2
dl 0
loc 53
ccs 23
cts 24
cp 0.9583
rs 9.5797
cc 3
eloc 32
nc 1
nop 1
crap 3.0006

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace LAG\AdminBundle\Admin\Configuration;
4
5
use LAG\AdminBundle\Application\Configuration\ApplicationConfiguration;
6
use LAG\AdminBundle\Configuration\Configuration;
7
use LAG\AdminBundle\Configuration\ConfigurationInterface;
8
use Symfony\Component\OptionsResolver\Options;
9
use Symfony\Component\OptionsResolver\OptionsResolver;
10
11
/**
12
 * Ease Admin configuration manipulation.
13
 */
14
class AdminConfiguration extends Configuration implements ConfigurationInterface
15
{
16
    /**
17
     * @var ApplicationConfiguration
18
     */
19
    protected $applicationConfiguration;
20
21
    /**
22
     * AdminConfiguration constructor.
23
     *
24
     * @param ApplicationConfiguration $applicationConfiguration
25
     */
26 18
    public function __construct(ApplicationConfiguration $applicationConfiguration)
27
    {
28 18
        parent::__construct();
29
30 18
        $this->applicationConfiguration = $applicationConfiguration;
31 18
    }
32
33
    /**
34
     * @param OptionsResolver $resolver
35
     */
36 18
    public function configureOptions(OptionsResolver $resolver)
37
    {
38
        // inherited routing configuration from global application configuration
39
        $routing = $this
40 18
            ->applicationConfiguration
41 18
            ->getParameter('routing');
42
43
        // inherited max per page configuration
44
        $maxPerPage = $this
45 18
            ->applicationConfiguration
46 18
            ->getParameter('max_per_page');
47
48
        // optional options
49 18
        $resolver->setDefaults([
50
            'actions' => [
51
                'list' => [],
52
                'create' => [],
53
                'edit' => [],
54
                'delete' => [],
55 18
            ],
56
            'batch' => true,
57 18
            'routing_url_pattern' => $routing['url_pattern'],
58 18
            'routing_name_pattern' => $routing['name_pattern'],
59 18
            'controller' => 'LAGAdminBundle:CRUD',
60 18
            'max_per_page' => $maxPerPage,
61
            'data_provider' => null,
62
        ]);
63
        // required options
64 18
        $resolver->setRequired([
65 18
            'entity',
66
            'form',
67
        ]);
68
69 18
        $resolver->setDefault('menu', [
70
            'main' => [
71
                'action' => 'list'
72
            ]
73 18
        ]);
74
75 18
        $resolver->setNormalizer('actions', function(Options $options, $actions) {
76 18
            $normalizedActions = [];
77
78 18
            foreach ($actions as $name => $action) {
79
80 18
                if ($action === null) {
81
                    $action = [];
82
                }
83 18
                $normalizedActions[$name] = $action;
84
            }
85
86 18
            return $normalizedActions;
87 18
        });
88 18
    }
89
}
90