FormWidget   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 45
c 0
b 0
f 0
wmc 3
lcom 2
cbo 3
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 7 1
A run() 0 8 2
1
<?php /** MicroFormWidget */
2
3
namespace Micro\Widget;
4
5
use Micro\Form\Form;
6
use Micro\Mvc\Widget;
7
use Micro\Web\Html\Html;
8
9
/**
10
 * FormWidget class file.
11
 *
12
 * @author Oleg Lunegov <[email protected]>
13
 * @link https://github.com/linpax/microphp-framework
14
 * @copyright Copyright (c) 2013 Oleg Lunegov
15
 * @license https://github.com/linpax/microphp-framework/blob/master/LICENSE
16
 * @package Micro
17
 * @subpackage Widget
18
 * @version 1.0
19
 * @since 1.0
20
 */
21
class FormWidget extends Widget
22
{
23
    /** @var string $action action url */
24
    public $action = '';
25
    /** @var string $method send form method */
26
    public $method = 'GET';
27
    /** @var string $type type of form */
28
    public $type = 'text/plain';
29
    /** @var string $client client js code */
30
    public $client = '';
31
    /** @var array $attributes attributes for form element */
32
    public $attributes = [];
33
34
35
    /**
36
     * Initialize widget
37
     *
38
     * @access public
39
     *
40
     * @return Form
41
     */
42
    public function init()
43
    {
44
        $this->attributes['type'] = $this->type;
45
        echo Html::beginForm($this->action, $this->method, $this->attributes);
46
47
        return new Form;
48
    }
49
50
    /**
51
     * Running widget
52
     *
53
     * @access public
54
     *
55
     * @return void
56
     */
57
    public function run()
58
    {
59
        $result = Html::endForm();
60
        if ($this->client) {
61
            $result .= Html::script($this->client);
62
        }
63
        echo $result;
64
    }
65
}
66