FormFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 44
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A newInstance() 0 9 2
A __construct() 0 3 1
1
<?php
2
/**
3
 * 
4
 * This file is part of the Aura project for PHP.
5
 * 
6
 * @package Aura.Input
7
 * 
8
 * @license http://opensource.org/licenses/MIT-license.php MIT
9
 * 
10
 */
11
namespace Aura\Input;
12
13
use Aura\Input\Exception;
14
15
/**
16
 * 
17
 * A factory to create top-level form objects by name.
18
 * 
19
 * @package Aura.Input
20
 * 
21
 */
22
class FormFactory
23
{
24
    /**
25
     * 
26
     * A map of form names to factory callables.
27
     * 
28
     * @var array
29
     * 
30
     */
31
    protected $map = [];
32
33
    /**
34
     * 
35
     * Constructor.
36
     * 
37
     * @param array $map A map of form names to factory callables.
38
     * 
39
     */
40
    public function __construct($map = [])
41
    {
42
        $this->map = $map;
43
    }
44
45
    /**
46
     *
47
     * Returns a new instance of a named form.
48
     *
49
     * @param string $name The name of the form to create.
50
     *
51
     * @param mixed $options
52
     *
53
     * @return Form
54
     *
55
     * @throws Exception\NoSuchForm When the named form does not exist.
56
     */
57
    public function newInstance($name, $options = null)
58
    {
59
        if (! isset($this->map[$name])) {
60
            throw new Exception\NoSuchForm($name);
61
        }
62
        
63
        $factory = $this->map[$name];
64
        $form = $factory($options);
65
        return $form;
66
    }
67
}
68