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 |
||
0 ignored issues
–
show
|
|||
2 | |||
3 | namespace {{namespace}}; |
||
0 ignored issues
–
show
|
|||
4 | |||
5 | use {{namespace_model_extend}} as Model; |
||
0 ignored issues
–
show
|
|||
6 | use Illuminate\Http\Request; |
||
0 ignored issues
–
show
|
|||
7 | use Illuminate\Pagination\Paginator; |
||
0 ignored issues
–
show
|
|||
8 | use Schema; |
||
0 ignored issues
–
show
|
|||
9 | // relationship tables use classes |
||
10 | {{relationship_tables_classes}} |
||
11 | // eager use classes |
||
12 | {{eager_use_classes}} |
||
13 | |||
14 | class {{class_name}} extends Model |
||
15 | { |
||
16 | /** |
||
17 | * The database table used by the model. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $table = '{{table_name}}'; |
||
22 | {{timestamps}} |
||
23 | |||
24 | {{primaryAttribute}} |
||
25 | public $fillable = [ |
||
26 | {{fillable}} |
||
27 | ]; |
||
28 | |||
29 | // validation rules |
||
30 | public static $rules = [ |
||
31 | {{validations}} |
||
32 | ]; |
||
33 | |||
34 | // eager loading objects |
||
35 | public $with = [ |
||
36 | {{eager}} |
||
37 | ]; |
||
38 | |||
39 | {{enum}} |
||
40 | |||
41 | {{belongsTo}} |
||
42 | |||
43 | {{reverseRelationship}} |
||
44 | |||
45 | |||
46 | //api resources |
||
47 | |||
48 | |||
49 | |||
50 | // save {{class_name_lw}} |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
50% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
51 | public function store(Request $request) |
||
52 | { |
||
53 | $vars = $request->all(); |
||
54 | |||
55 | //create eager objects |
||
56 | {{store_eager_objects}} |
||
57 | |||
58 | ${{class_name_lw}} = {{class_name}}::create($vars); |
||
59 | |||
60 | //create relationship_tables objects |
||
61 | {{relationship_tables_call}} |
||
62 | |||
63 | return ${{class_name_lw}} ; |
||
64 | } |
||
65 | |||
66 | |||
67 | // get {{class_name_lw}} by id |
||
68 | public function show($id) |
||
69 | { |
||
70 | ${{class_name_lw}} = {{class_name}}::find($id); |
||
71 | return ${{class_name_lw}}; |
||
72 | } |
||
73 | |||
74 | |||
75 | |||
76 | //get first row by field and value |
||
77 | public function findByField(Request $request) |
||
78 | { |
||
79 | ${{class_name_lw}} = {{class_name}}::where($request->input('field') , '=', $request->input('value'))->first(); |
||
80 | return ${{class_name_lw}} ; |
||
81 | } |
||
82 | |||
83 | |||
84 | // update {{class_name_lw}} by id |
||
85 | public function updateModel($id, Request $request) |
||
86 | { |
||
87 | // get vars |
||
88 | $vars = $request->all(); |
||
89 | |||
90 | //update eager objects |
||
91 | {{update_eager_objects}} |
||
92 | |||
93 | ${{class_name_lw}} = {{class_name}}::find($id); |
||
94 | ${{class_name_lw}}->fill($vars); |
||
95 | ${{class_name_lw}}->save(); |
||
96 | |||
97 | //update relationship_tables objects |
||
98 | {{remove_relationship_objects_call}} |
||
99 | |||
100 | {{relationship_tables_call}} |
||
101 | |||
102 | return ${{class_name_lw}}; |
||
103 | } |
||
104 | |||
105 | |||
106 | // delete model by id or ids |
||
107 | public static function destroy($ids) |
||
108 | { |
||
109 | $success = {{class_name}}::whereIn('id', $ids)->delete(); |
||
110 | |||
111 | return $success; |
||
112 | } |
||
113 | |||
114 | // query with search and pagination options |
||
115 | public function querySearch(Request $request) |
||
116 | { |
||
117 | // get query parameters |
||
118 | $params = $request->all(); |
||
119 | |||
120 | // get pagination conditions |
||
121 | if(isset($params["pagination"])) { |
||
122 | $pagination = $params["pagination"]; |
||
123 | } |
||
124 | else { // set default |
||
125 | $pagination = ["actual" => 1, "itensPerPage" => 25 ] ; |
||
126 | } |
||
127 | |||
128 | // resolve current page |
||
129 | $currentPage = $pagination["actual"]; |
||
130 | Paginator::currentPageResolver(function () use ($currentPage) { |
||
131 | return $currentPage; |
||
132 | }); |
||
133 | |||
134 | // set first condition 1=1 (all results) |
||
135 | $query = {{class_name}}::WhereNotNull('{{table_name}}.{{primary_key}}'); |
||
136 | |||
137 | // get filters conditions |
||
138 | $filters = isset($params["filters"]) ? $params["filters"] : $params; |
||
139 | |||
140 | // field by field condition |
||
141 | {{conditions}} |
||
142 | |||
143 | // join eager objects |
||
144 | {{eager_joins}} |
||
145 | |||
146 | // eager object condition |
||
147 | {{eager_conditions}} |
||
148 | |||
149 | // join relationship tables objects |
||
150 | {{relationship_tables_joins}} |
||
151 | // get sort clauses |
||
152 | if(isset($params["sort"]) && count($params["sort"])) { |
||
153 | foreach($params["sort"] as $sort){ |
||
154 | {{relationship_tables_joins_sort}} |
||
155 | $query->orderBy($sort["field"], $sort["order"]); |
||
156 | } |
||
157 | } |
||
158 | |||
159 | |||
160 | |||
161 | return $query->paginate($pagination["itensPerPage"]); |
||
162 | } |
||
163 | |||
164 | |||
165 | // query with fields filters and pagination |
||
166 | //json = {"pagination": {"actual": 1, "itensPerPage": 20}, "fields": ["name","email","cnpj"], "orderBy": "name"} |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
70% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
167 | public function queryFilters(Request $request) |
||
168 | { |
||
169 | // get query parameters |
||
170 | $params = $request->all(); |
||
171 | |||
172 | $orderBy = '{{primary_key}}'; |
||
173 | $fields = null; |
||
174 | $selectArray = []; |
||
175 | array_push($selectArray,'{{primary_key}}'); |
||
176 | |||
177 | // get pagination conditions |
||
178 | if(isset($params["pagination"])) { |
||
179 | $pagination = $params["pagination"]; |
||
180 | } |
||
181 | else { // set default |
||
182 | $pagination = ["actual" => 1, "itensPerPage" => 25 ] ; |
||
183 | } |
||
184 | |||
185 | // resolve current page |
||
186 | $currentPage = $pagination["actual"]; |
||
187 | Paginator::currentPageResolver(function () use ($currentPage) { |
||
188 | return $currentPage; |
||
189 | }); |
||
190 | |||
191 | if(isset($params["fields"])) { |
||
192 | $fields = $params["fields"]; |
||
193 | |||
194 | foreach ($fields as $field) { |
||
195 | if(Schema::hasColumn('{{table_name}}', $field)){ |
||
196 | array_push($selectArray, $field); |
||
197 | } |
||
198 | } |
||
199 | |||
200 | } |
||
201 | |||
202 | if(isset($params["orderBy"])) { |
||
203 | if(Schema::hasColumn('{{table_name}}',$params["orderBy"])){ |
||
204 | $orderBy = $params["orderBy"]; |
||
205 | } |
||
206 | } |
||
207 | |||
208 | ${{class_name_lw}} = {{class_name}}::WhereNotNull('{{table_name}}.{{primary_key}}'); |
||
209 | |||
210 | ${{class_name_lw}}->select($selectArray)->orderBy($orderBy,'asc'); |
||
211 | |||
212 | return ${{class_name_lw}}->paginate($pagination["itensPerPage"]); |
||
213 | } |
||
214 | |||
215 | |||
216 | {{relationship_tables_store}} |
||
217 | |||
218 | {{remove_relationship_objects}} |
||
219 | |||
220 | {{checkbox}} |
||
221 | } |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.