Passed
Pull Request — 3.x (#71)
by Hari
06:16
created

AbstractInput   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 99
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A read() 0 3 1
A get() 0 3 1
A getFullName() 0 7 2
A setNamePrefix() 0 4 1
A setName() 0 4 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
/**
14
 * 
15
 * An abstract input class; serves as the base for Fields, Fieldsets, and
16
 * Collections.
17
 * 
18
 * @package Aura.Input
19
 * 
20
 */
21
abstract class AbstractInput
22
{
23
    /**
24
     * 
25
     * The name for the input.
26
     * 
27
     * @var string
28
     * 
29
     */
30
    protected $name;
31
    
32
    /**
33
     * 
34
     * The prefix for the name, typically composed of the parent input names.
35
     * 
36
     * @var string
37
     * 
38
     */
39
    protected $name_prefix;
40
    
41
    /**
42
     * 
43
     * Sets the name for the input.
44
     * 
45
     * @param string $name The input name.
46
     * 
47
     * @return self
48
     * 
49
     */
50
    public function setName($name)
51
    {
52
        $this->name = $name;
53
        return $this;
54
    }
55
    
56
    /**
57
     * 
58
     * Sets the name prefix for the input, typically composed of the parent
59
     * input names.
60
     * 
61
     * @param string $name_prefix The name prefix.
62
     * 
63
     * @return self
64
     * 
65
     */
66
    public function setNamePrefix($name_prefix)
67
    {
68
        $this->name_prefix = $name_prefix;
69
        return $this;
70
    }
71
    
72
    /**
73
     * 
74
     * Returns the full name for this input, incuding the prefix (if any).
75
     * 
76
     * @return string
77
     * 
78
     */
79
    public function getFullName()
80
    {
81
        $name = $this->name;
82
        if ($this->name_prefix) {
83
            $name = $this->name_prefix . "[{$name}]";
84
        }
85
        return $name;
86
    }
87
    
88
    /**
89
     * 
90
     * Support for this input when addressed via Fieldset::__get().
91
     * 
92
     * @return self
93
     * 
94
     */
95
    public function read()
96
    {
97
        return $this;
98
    }
99
    
100
    /**
101
     * 
102
     * Returns this input for the presentation layer.
103
     * 
104
     * @return self
105
     * 
106
     */
107
    public function get()
108
    {
109
        return $this;
110
    }
111
    
112
    /**
113
     * 
114
     * Returns the value of this input for use in arrays.
115
     * 
116
     * @return mixed
117
     * 
118
     */
119
    abstract public function getValue();
120
}
121