Completed
Push — master ( 29f185...9200bf )
by Michael
18s
created

BlockForm   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 58.97 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 94.74%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 0
cbo 2
dl 23
loc 39
ccs 18
cts 19
cp 0.9474
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B render() 23 23 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
 * BlockForm - Form that will output formatted as a HTML table
16
 *
17
 * No styles and no JavaScript to check for required fields.
18
 *
19
 * @category  Xoops\Form\BlockForm
20
 * @package   Xoops\Form
21
 * @author    trabis <[email protected]>
22
 * @copyright 2012-2016 XOOPS Project (http://xoops.org)
23
 * @license   GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
24
 * @link      http://xoops.org
25
 */
26
class BlockForm extends Form
27
{
28
    /**
29
     * __construct
30
     */
31 2
    public function __construct()
32
    {
33 2
        parent::__construct('', '', '');
34 2
    }
35
36
    /**
37
     * render
38
     *
39
     * @return string
40
     */
41 2 View Code Duplication
    public function render()
42
    {
43 2
        $ret = '<div>';
44
        /* @var $ele Element */
45 2
        foreach ($this->getElements() as $ele) {
46 2
            if ($ele->has('datalist')) {
47
                $ret .= $ele->renderDatalist();
48
            }
49 2
            if (!$ele->isHidden()) {
50 2
                $ret .= '<div class="form-group">';
51 2
                $ret .= '<label>' . $ele->getCaption();
52 2
                $ret .= ($ele->isRequired() ? '<span class="caption-required">*</span>' : '') . '</label>';
53 2
                $ret .= $ele->render();
54 2
                $ret .= '<small class="text-muted">' . $ele->getDescription() . '</small>';
55 2
                $ret .= '<p class="dsc_pattern_vertical">' . $ele->getPatternDescription() . '</p>';
56 2
                $ret .= '</div>' . "\n";
57
            } else {
58 2
                $ret .= $ele->render(). "\n";
59
            }
60
        }
61 2
        $ret .= '</div>';
62 2
        return $ret;
63
    }
64
}
65