FormWrapper   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 7
Bugs 1 Features 3
Metric Value
wmc 6
c 7
b 1
f 3
lcom 0
cbo 0
dl 0
loc 74
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 3
A getForm() 0 4 1
A getName() 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
     * The name of the form.
32
     *
33
     * @var string
34
     */
35
    protected $name;
36
37
    /**
38
     * Collection of actions.
39
     *
40
     * @var Action[]
41
     */
42
    protected $successActions;
43
44
    /**
45
     * Generates a wrapper for a given form.
46
     *
47
     * @param string   $name           The name of form
48
     * @param string   $formClass      Fqcn of form
49
     * @param Action[] $successActions Collection of actions
50
     */
51
    public function __construct($name, $formClass, array $successActions = [])
52
    {
53
        $this->formClass = $formClass;
54
        $this->name = $name;
55
        foreach ($successActions as $action) {
56
            if (!$action instanceof Action) {
57
                throw new \InvalidArgumentException(
58
                    'All actions passed to the FormWrapper must be an instance of Action'
59
                );
60
            }
61
        }
62
        $this->successActions = $successActions;
63
    }
64
65
    /**
66
     * Gets the fully qualified class name of the form.
67
     *
68
     * @return string
69
     */
70
    public function getForm()
71
    {
72
        return $this->formClass;
73
    }
74
75
    /**
76
     * Gets name of the form.
77
     *
78
     * @return string
79
     */
80
    public function getName()
81
    {
82
        return $this->name;
83
    }
84
85
    /**
86
     * Returns registered actions to be called in form success.
87
     *
88
     * @return Action[]
89
     */
90
    public function getSuccessActions()
91
    {
92
        return $this->successActions;
93
    }
94
}
95