This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | |-------------------------------------------------------------------------- |
||
5 | | Translatable fields |
||
6 | |-------------------------------------------------------------------------- |
||
7 | */ |
||
8 | /** |
||
9 | * Add an input field |
||
10 | * @param string $name The field name |
||
11 | * @param string $title The field title |
||
12 | * @param object $errors The laravel errors object |
||
13 | * @param string $lang the language of the field |
||
14 | * @param null|object $object The entity of the field |
||
15 | */ |
||
16 | use Illuminate\Support\ViewErrorBag; |
||
17 | |||
18 | Form::macro('i18nInput', function ($name, $title, ViewErrorBag $errors, $lang, $object = null, array $options = []) { |
||
19 | $options = array_merge(['class' => "form-control", 'placeholder' => $title], $options); |
||
20 | |||
21 | $string = "<div class='form-group " . ($errors->has($lang . '.' . $name) ? ' has-error' : '') . "'>"; |
||
22 | $string .= Form::label("{$lang}[{$name}]", $title); |
||
23 | |||
24 | if (is_object($object)) { |
||
25 | $currentData = $object->hasTranslation($lang) ? $object->translate($lang)->{$name} : ''; |
||
26 | } else { |
||
27 | $currentData = ''; |
||
28 | } |
||
29 | |||
30 | $string .= Form::text("{$lang}[{$name}]", Input::old("{$lang}[{$name}]", $currentData), $options); |
||
31 | $string .= $errors->first("{$lang}.{$name}", '<span class="help-block">:message</span>'); |
||
32 | $string .= "</div>"; |
||
33 | |||
34 | return $string; |
||
35 | }); |
||
36 | |||
37 | /** |
||
38 | * Add a textarea |
||
39 | * @param string $name The field name |
||
40 | * @param string $title The field title |
||
41 | * @param object $errors The laravel errors object |
||
42 | * @param string $lang the language of the field |
||
43 | * @param null|object $object The entity of the field |
||
44 | */ |
||
45 | Form::macro('i18nTextarea', function ($name, $title, ViewErrorBag $errors, $lang, $object = null, array $options = []) { |
||
46 | $options = array_merge(['class' => 'ckeditor', 'rows' => 10, 'cols' => 10], $options); |
||
47 | |||
48 | $string = "<div class='form-group " . ($errors->has($lang . '.' . $name) ? ' has-error' : '') . "'>"; |
||
49 | $string .= Form::label("{$lang}[{$name}]", $title); |
||
50 | |||
51 | if (is_object($object)) { |
||
52 | $currentData = $object->hasTranslation($lang) ? $object->translate($lang)->{$name} : ''; |
||
53 | } else { |
||
54 | $currentData = ''; |
||
55 | } |
||
56 | |||
57 | $string .= Form::textarea("{$lang}[$name]", Input::old("{$lang}[{$name}]", $currentData), $options); |
||
58 | $string .= $errors->first("{$lang}.{$name}", '<span class="help-block">:message</span>'); |
||
59 | $string .= "</div>"; |
||
60 | |||
61 | return $string; |
||
62 | }); |
||
63 | |||
64 | /** |
||
65 | * Add a checkbox input field |
||
66 | * @param string $name The field name |
||
67 | * @param string $title The field title |
||
68 | * @param object $errors The laravel errors object |
||
69 | * @param string $lang the language of the field |
||
70 | * @param null|object $object The entity of the field |
||
71 | */ |
||
72 | Form::macro('i18nCheckbox', function ($name, $title, ViewErrorBag $errors, $lang, $object = null) { |
||
73 | $string = "<div class='checkbox" . ($errors->has($lang . '.' . $name) ? ' has-error' : '') . "'>"; |
||
74 | $string .= "<label for='{$lang}[{$name}]'>"; |
||
75 | $string .= "<input id='{$lang}[{$name}]' name='{$lang}[{$name}]' type='checkbox' class='flat-blue'"; |
||
76 | |||
77 | View Code Duplication | if (is_object($object)) { |
|
0 ignored issues
–
show
|
|||
78 | $currentData = $object->hasTranslation($lang) ? (bool) $object->translate($lang)->{$name} : ''; |
||
79 | } else { |
||
80 | $currentData = false; |
||
81 | } |
||
82 | |||
83 | $oldInput = Input::old("{$lang}.$name", $currentData) ? 'checked' : ''; |
||
0 ignored issues
–
show
It seems like
$currentData can also be of type boolean ; however, Illuminate\Http\Request::old() does only seem to accept string|array|null , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. ![]() |
|||
84 | $string .= "value='1' {$oldInput}>"; |
||
85 | $string .= $title; |
||
86 | $string .= $errors->first($name, '<span class="help-block">:message</span>'); |
||
87 | $string .= "</label>"; |
||
88 | $string .= "</div>"; |
||
89 | |||
90 | return $string; |
||
91 | }); |
||
92 | |||
93 | /* |
||
94 | |-------------------------------------------------------------------------- |
||
95 | | Standard fields |
||
96 | |-------------------------------------------------------------------------- |
||
97 | */ |
||
98 | /** |
||
99 | * Add an input field |
||
100 | * @param string $name The field name |
||
101 | * @param string $title The field title |
||
102 | * @param object $errors The laravel errors object |
||
103 | * @param null|object $object The entity of the field |
||
104 | */ |
||
105 | Form::macro('normalInput', function ($name, $title, ViewErrorBag $errors, $object = null, array $options = []) { |
||
106 | $options = array_merge(['class' => "form-control", 'placeholder' => $title], $options); |
||
107 | |||
108 | $string = "<div class='form-group " . ($errors->has($name) ? ' has-error' : '') . "'>"; |
||
109 | $string .= Form::label($name, $title); |
||
110 | |||
111 | if (is_object($object)) { |
||
112 | $currentData = $object->{$name} ?: ''; |
||
113 | } else { |
||
114 | $currentData = ''; |
||
115 | } |
||
116 | |||
117 | $string .= Form::text($name, Input::old($name, $currentData), $options); |
||
118 | $string .= $errors->first($name, '<span class="help-block">:message</span>'); |
||
119 | $string .= "</div>"; |
||
120 | |||
121 | return $string; |
||
122 | }); |
||
123 | |||
124 | Form::macro('normalTextarea', function ($name, $title, ViewErrorBag $errors, $object = null, array $options = []) { |
||
125 | $options = array_merge(['class' => 'ckeditor', 'rows' => 10, 'cols' => 10], $options); |
||
126 | |||
127 | $string = "<div class='form-group " . ($errors->has($name) ? ' has-error' : '') . "'>"; |
||
128 | $string .= Form::label($name, $title); |
||
129 | |||
130 | if (is_object($object)) { |
||
131 | $currentData = $object->{$name} ?: ''; |
||
132 | } else { |
||
133 | $currentData = ''; |
||
134 | } |
||
135 | |||
136 | $string .= Form::textarea($name, Input::old($name, $currentData), $options); |
||
137 | $string .= $errors->first($name, '<span class="help-block">:message</span>'); |
||
138 | $string .= "</div>"; |
||
139 | |||
140 | return $string; |
||
141 | }); |
||
142 | |||
143 | /** |
||
144 | * Add a checkbox input field |
||
145 | * @param string $name The field name |
||
146 | * @param string $title The field title |
||
147 | * @param object $errors The laravel errors object |
||
148 | * @param null|object $object The entity of the field |
||
149 | */ |
||
150 | Form::macro('normalCheckbox', function ($name, $title, ViewErrorBag $errors, $object = null) { |
||
151 | $string = "<div class='checkbox" . ($errors->has($name) ? ' has-error' : '') . "'>"; |
||
152 | $string .= "<input type='hidden' value='0' name='{$name}'/>"; |
||
153 | $string .= "<label for='$name'>"; |
||
154 | $string .= "<input id='$name' name='$name' type='checkbox' class='flat-blue'"; |
||
155 | |||
156 | View Code Duplication | if (is_object($object)) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
157 | $currentData = isset($object->$name) && (bool) $object->$name ? 'checked' : ''; |
||
158 | } else { |
||
159 | $currentData = false; |
||
160 | } |
||
161 | |||
162 | $oldInput = Input::old($name, $currentData) ? 'checked' : ''; |
||
0 ignored issues
–
show
It seems like
$currentData defined by false on line 159 can also be of type false ; however, Illuminate\Http\Request::old() does only seem to accept string|array|null , did you maybe forget to handle an error condition?
This check looks for type mismatches where the missing type is Consider the follow example <?php
function getDate($date)
{
if ($date !== null) {
return new DateTime($date);
}
return false;
}
This function either returns a new ![]() |
|||
163 | $string .= "value='1' {$oldInput}>"; |
||
164 | $string .= $title; |
||
165 | $string .= $errors->first($name, '<span class="help-block">:message</span>'); |
||
166 | $string .= "</label>"; |
||
167 | $string .= "</div>"; |
||
168 | |||
169 | return $string; |
||
170 | }); |
||
171 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.