Completed
Pull Request — master (#13)
by Arnaud
11:42 queued 08:41
created

ActionFactory::create()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 34
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4.1574

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 34
ccs 11
cts 14
cp 0.7856
rs 8.5806
cc 4
eloc 17
nc 8
nop 3
crap 4.1574
1
<?php
2
3
namespace LAG\AdminBundle\Action\Factory;
4
5
use LAG\AdminBundle\Action\Action;
6
use LAG\AdminBundle\Admin\AdminInterface;
7
use LAG\AdminBundle\Admin\Factory\FilterFactory;
8
use LAG\AdminBundle\Configuration\Factory\ConfigurationFactory;
9
use LAG\AdminBundle\Field\Factory\FieldFactory;
10
11
class ActionFactory
12
{
13
    /**
14
     * @var FieldFactory
15
     */
16
    protected $fieldFactory;
17
18
    /**
19
     * @var FilterFactory
20
     */
21
    protected $filterFactory;
22
23
    /**
24
     * @var ConfigurationFactory
25
     */
26
    protected $configurationFactory;
27
28
    /**
29
     * ActionFactory constructor.
30
     *
31
     * @param FieldFactory $fieldFactory
32
     * @param FilterFactory $filterFactory
33
     * @param ConfigurationFactory $configurationFactory
34
     */
35 1
    public function __construct(
36
        FieldFactory $fieldFactory,
37
        FilterFactory $filterFactory,
38
        ConfigurationFactory $configurationFactory
39
    ) {
40 1
        $this->fieldFactory = $fieldFactory;
41 1
        $this->filterFactory = $filterFactory;
42 1
        $this->configurationFactory = $configurationFactory;
43 1
    }
44
45
    /**
46
     * Create an Action from configuration values.
47
     *
48
     * @param string $actionName
49
     * @param array $configuration
50
     * @param AdminInterface $admin
51
     *
52
     * @return Action
53
     */
54 1
    public function create($actionName, array $configuration, AdminInterface $admin)
55
    {
56
        // create action configuration object
57
        $actionConfiguration = $this
58 1
            ->configurationFactory
59 1
            ->createActionConfiguration($actionName, $admin, $configuration);
60
61
        // create action
62 1
        $action = new Action($actionName, $actionConfiguration);
63
64
        // adding fields items to actions
65 1
        foreach ($actionConfiguration->getParameter('fields') as $fieldName => $fieldConfiguration) {
66
            $field = $this
67 1
                ->fieldFactory
68 1
                ->create($fieldName, $fieldConfiguration);
69 1
            $action->addField($field);
70
        }
71
72
        // adding filters to the action
73 1
        foreach ($actionConfiguration->getParameter('filters') as $fieldName => $filterConfiguration) {
74
            $filter = $this
75
                ->filterFactory
76
                ->create($fieldName, $filterConfiguration);
77
            $action->addFilter($filter);
78
        }
79
80
        // add batch action
81 1
        if (count($action->getConfiguration()->getParameter('batch'))) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
82
83
            
84
        }
85
86 1
        return $action;
87
    }
88
}
89