Code Duplication    Length = 53-59 lines in 2 locations

app/Form/Former/Fields/CheckboxButton.php 1 location

@@ 21-79 (lines=59) @@
18
 *
19
 * @author Mohamed Alsharaf <[email protected]>
20
 */
21
class CheckboxButton extends Checkbox
22
{
23
    /**
24
     * Render radio buttons.
25
     *
26
     * @return string
27
     */
28
    public function render()
29
    {
30
        try {
31
            return '<div class="btn-toolbar checkbox-btn" data-toggle="buttons">' . parent::render() . '</div>';
32
        } catch (\Exception $e) {
33
            echo $e;
34
            die;
35
        }
36
    }
37
38
    /**
39
     * Render checkable radio button.
40
     *
41
     * @param array|string $item
42
     * @param int          $fallbackValue
43
     *
44
     * @return string
45
     */
46
    protected function createCheckable($item, $fallbackValue = 1)
47
    {
48
        // Make sure the parent class will create inline radios
49
        $this->inline = true;
50
        $this->grouped();
51
//        $this=
52
        // Extract the color for this button/radio & unset it to prevent creating attribute
53
        $color = $item['attributes']['color'];
54
        unset($item['attributes']['color']);
55
56
        // Color for selected button/radio
57
        $selectedColor = ';color:' . $color . ';';
58
59
        // Data attribute for the button color
60
        $item['attributes']['data-color'] = $color;
61
62
        // Generate the radio button
63
        $item = parent::createCheckable($item, $fallbackValue);
64
65
        // If property checked found, then make the button selected with styles
66
        if (strpos($item, 'checked') !== false) {
67
            $selectedColor = ';background:' . $color . ';color:white;';
68
        }
69
70
        // Add bootstrap classes for styling the buttons
71
        $item = str_replace('inline', 'btn btn-default', $item);
72
73
        // Add styles to the wrapper label tag
74
        $style = 'border-color: ' . $color . $selectedColor;
75
        $item  = str_replace('<label', '<label style="' . $style . '"', $item);
76
77
        return $item;
78
    }
79
}
80

app/Form/Former/Fields/RadioButton.php 1 location

@@ 21-73 (lines=53) @@
18
 *
19
 * @author Mohamed Alsharaf <[email protected]>
20
 */
21
class RadioButton extends Radio
22
{
23
    /**
24
     * Render radio buttons.
25
     *
26
     * @return string
27
     */
28
    public function render()
29
    {
30
        return '<div class="btn-toolbar radio-btn" data-toggle="buttons">' . parent::render() . '</div>';
31
    }
32
33
    /**
34
     * Render checkable radio button.
35
     *
36
     * @param array|string $item
37
     * @param int          $fallbackValue
38
     *
39
     * @return string
40
     */
41
    protected function createCheckable($item, $fallbackValue = 1)
42
    {
43
        // Make sure the parent class will create inline radios
44
        $this->inline = true;
45
46
        // Extract the color for this button/radio & unset it to prevent creating attribute
47
        $color = $item['attributes']['color'];
48
        unset($item['attributes']['color']);
49
50
        // Color for selected button/radio
51
        $selectedColor = ';color:' . $color . ';';
52
53
        // Data attribute for the button color
54
        $item['attributes']['data-color'] = $color;
55
56
        // Generate the radio button
57
        $item = parent::createCheckable($item, $fallbackValue);
58
59
        // If property checked found, then make the button selected with styles
60
        if (strpos($item, 'checked') !== false) {
61
            $selectedColor = ';background:' . $color . ';color:white;';
62
        }
63
64
        // Add bootstrap classes for styling the buttons
65
        $item = str_replace('inline', 'btn btn-default', $item);
66
67
        // Add styles to the wrapper label tag
68
        $style = 'border-color: ' . $color . $selectedColor;
69
        $item  = str_replace('<label', '<label style="' . $style . '"', $item);
70
71
        return $item;
72
    }
73
}
74