Passed
Push — master ( 4c30a2...697d1a )
by Matthijs
05:29
created

FormBuilder::tree()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 10
nc 6
nop 2
dl 0
loc 16
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace Hideyo\Ecommerce\Framework\Providers;
4
5
use Html;
6
use Form;
0 ignored issues
show
Bug introduced by
The type Form was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
8
class FormBuilder extends \Collective\Html\FormBuilder
9
{
10
    /**
11
     * delete ajax button
12
     * @param  string  $url            
13
     * @param  string  $buttonLabel    
14
     * @param  array   $formParameters 
15
     * @param  array   $buttonOptions  
16
     * @param  boolean $title          
17
     * @return object                  
18
     */
19
    public function deleteajax($url, $buttonLabel = 'Delete', $formParameters = array(), $buttonOptions = array(), $title = false)
20
    {
21
        if (empty($formParameters)) {
22
            $formParameters = array(
23
                'method'=>'DELETE',
24
                'class' =>'delete-form delete-button',
25
                'url'   =>$url,
26
                'style' => 'display:inline',
27
                'data-title' => $title
28
            );
29
        } else {
30
            $formParameters['url'] = $url;
31
            $formParameters['method'] = 'DELETE';
32
        };
33
34
        return Form::open($formParameters)
0 ignored issues
show
Bug Best Practice introduced by
The expression return Form::open($formP...ptions) . Form::close() returns the type string which is incompatible with the documented return type object.
Loading history...
35
            . Form::submit($buttonLabel, $buttonOptions)
36
            . Form::close();
37
    }
38
39
    /**
40
     * multi select2 
41
     * @param  string $name        
42
     * @param  array  $list        
43
     * @param  array  $selected    
44
     * @param  array  $options     
45
     * @param  string $placeholder 
46
     * @return string             
47
     */
48
    public function multiselect2($name, array $list = [], array $selected = [], $options = [], $placeholder = 'Select one...')
0 ignored issues
show
Unused Code introduced by
The parameter $placeholder is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

48
    public function multiselect2($name, array $list = [], array $selected = [], $options = [], /** @scrutinizer ignore-unused */ $placeholder = 'Select one...')

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
49
    {
50
        $options['name'] = $name;
51
        $html = array();
52
        if (is_array($selected)) {
0 ignored issues
show
introduced by
The condition is_array($selected) is always true.
Loading history...
53
            foreach ($selected as $key => $value) {
54
                      $selected[$value] = $value;
55
            }
56
        }
57
58
        //dd($list, $selected);
59
        foreach ($list as $value => $display) {
60
            $sel = isset($selected[$value])?' selected="selected"':'';
61
            $html[] = '<option value="'.$value.'"'.$sel.'>'.e($display).'</option>';
62
        }
63
     
64
        // build out a final select statement, which will contain all the values.
65
        $options = Html::attributes($options);
66
        $list = "";        
67
        
68
        if ($html) {
69
            $list = implode('', $html);
70
        }
71
    
72
        return "<select multiple {$options} class=\"select2 form-control\">{$list}</select>";
73
    }
74
75
    /**
76
     * select2
77
     * @param string $name        
78
     * @param  array  $list        
79
     * @param  [type] $selected    
0 ignored issues
show
Documentation Bug introduced by
The doc comment [type] at position 0 could not be parsed: Unknown type name '[' at position 0 in [type].
Loading history...
80
     * @param  array  $options     
81
     * @param  string $placeholder 
82
     * @return string             
83
     */
84
    public function select2($name, array $list = [], $selected, $options = [], $placeholder = 'Select one...')
0 ignored issues
show
Unused Code introduced by
The parameter $placeholder is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

84
    public function select2($name, array $list = [], $selected, $options = [], /** @scrutinizer ignore-unused */ $placeholder = 'Select one...')

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
85
    {
86
        $options['name'] = $name;
87
        $html = array();
88
89
        foreach ($list as $value => $display) {
90
            $sel = '';
91
            if ($selected == $value) {
92
                $sel = ' selected="selected"';
93
            }
94
            
95
            $html[] = '<option value="'.$value.'"'.$sel.'>'.e($display).'</option>';
96
        }
97
     
98
        // build out a final select statement, which will contain all the values.
99
        $options = HTML::attributes($options);
100
        $list = "";
101
        if ($html) {
102
            $list = implode('', $html);
103
        }
104
     
105
        return "<select {$options} class=\"select2 form-control\">{$list}</select>";
106
    }
107
}