Completed
Push — master ( 9200bf...e0f8ea )
by Richard
15s
created

Text::render()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
c 2
b 0
f 1
cc 2
eloc 7
nc 2
nop 0
crap 2
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
namespace Xoops\Form;
13
14
/**
15
 * Text - a simple text field
16
 *
17
 * @category  Xoops\Form\Text
18
 * @package   Xoops\Form
19
 * @author    Kazumi Ono (AKA onokazu) http://www.myweb.ne.jp/, http://jp.xoops.org/
20
 * @copyright 2001-2015 XOOPS Project (http://xoops.org)
21
 * @license   GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
22
 * @link      http://xoops.org
23
 */
24
class Text extends Element
25
{
26
    /**
27
     * __construct
28
     *
29
     * @param string|array $caption     Caption or array of all attributes
30
     * @param string       $name        name attribute
31
     * @param integer      $size        Size
32
     * @param integer      $maxlength   Maximum length of text
33
     * @param string       $value       Initial text
34
     * @param string       $placeholder placeholder for this element.
35
     */
36 5 View Code Duplication
    public function __construct($caption, $name = null, $size = 10, $maxlength = 64, $value = '', $placeholder = '')
37
    {
38 5
        if (is_array($caption)) {
39 3
            parent::__construct($caption);
40
        } else {
41 2
            parent::__construct([]);
42 2
            $this->setWithDefaults('caption', $caption, '');
43 2
            $this->setWithDefaults('name', $name, 'name_error');
44 2
            $this->setWithDefaults('size', $size, 10);
45 2
            $this->setWithDefaults('maxlength', $maxlength, 64);
46 2
            $this->set('value', $value);
47 2
            $this->setIfNotEmpty('placeholder', $placeholder);
48
        }
49 5
        $this->setIfNotSet('type', 'text');
50 5
        $this->setIfNotSet('value', '');
51 5
    }
52
53
    /**
54
     * Get size
55
     *
56
     * @return int
57
     */
58 1
    public function getSize()
59
    {
60 1
        return (int) $this->get('size');
61
    }
62
63
    /**
64
     * Get maximum text length
65
     *
66
     * @return int
67
     */
68 1
    public function getMaxlength()
69
    {
70 1
        return (int) $this->get('maxlength');
71
    }
72
73
    /**
74
     * Get placeholder for this element
75
     *
76
     * @return string
77
     */
78 1
    public function getPlaceholder()
79
    {
80 1
        return (string) $this->get('placeholder');
81
    }
82
83
    /**
84
     * Prepare HTML for output
85
     *
86
     * @return string HTML
87
     */
88 4
    public function render()
89
    {
90 4
        $this->themeDecorateElement();
91 4
        $dataList = $this->isDatalist();
92 4
        if (!empty($dataList)) {
93
            $this->add('list', 'list_' . $this->getName());
94
        }
95
96 4
        $attributes = $this->renderAttributeString();
97 4
        return '<input ' . $attributes . ' ' . $this->getExtra() .' >';
98
    }
99
}
100