Completed
Push — master ( 5e1d37...9b264a )
by Beñat
04:46
created

FormWrapper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 5
Bugs 0 Features 2
Metric Value
wmc 5
c 5
b 0
f 2
lcom 1
cbo 0
dl 0
loc 55
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 3
A getForm() 0 4 1
A getSuccessActions() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the WPSymfonyForm plugin.
5
 *
6
 * Copyright (c) 2015-2016 LIN3S <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace LIN3S\WPSymfonyForm\Wrapper;
13
14
use LIN3S\WPSymfonyForm\Action\Action;
15
16
/**
17
 * FormWrapper class.
18
 *
19
 * @author Gorka Laucirica <[email protected]>
20
 */
21
class FormWrapper
22
{
23
    /**
24
     * The fully qualified class name of form.
25
     *
26
     * @var string
27
     */
28
    protected $formClass;
29
30
    /**
31
     * Array of actions.
32
     *
33
     * @var array
34
     */
35
    protected $successActions;
36
37
    /**
38
     * Generates a wrapper for a given form.
39
     *
40
     * @param string   $formClass      Fqcn of form
41
     * @param Action[] $successActions Array of actions
42
     */
43
    public function __construct($formClass, $successActions = [])
44
    {
45
        $this->formClass = $formClass;
46
        foreach ($successActions as $action) {
47
            if (!$action instanceof Action) {
48
                throw new \InvalidArgumentException(
49
                    'All actions passed to the FormWrapper must be an instance of ActionInterface'
50
                );
51
            }
52
        }
53
        $this->successActions = $successActions;
54
    }
55
56
    /**
57
     * Returns a new instance of the Form.
58
     *
59
     * @return \Symfony\Component\Form\Form
60
     */
61
    public function getForm()
62
    {
63
        return new $this->formClass();
64
    }
65
66
    /**
67
     * Returns registered actions to be called in form success.
68
     *
69
     * @return Action[]
70
     */
71
    public function getSuccessActions()
72
    {
73
        return $this->successActions;
74
    }
75
}
76