Issues (225)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

stubs/Api/Model/Model.php (8 issues)

Upgrade to new PHP Analysis Engine

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
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 51 and the first side effect is on line 3.

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.

Loading history...
2
3
namespace {{namespace}};
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected '}', expecting T_NS_SEPARATOR
Loading history...
4
5
use {{namespace_model_extend}} as Model;
0 ignored issues
show
USE declarations must go after the first namespace declaration
Loading history...
6
use Illuminate\Http\Request;
0 ignored issues
show
USE declarations must go after the first namespace declaration
Loading history...
7
use Illuminate\Pagination\Paginator;
0 ignored issues
show
USE declarations must go after the first namespace declaration
Loading history...
8
use Schema;
0 ignored issues
show
USE declarations must go after the first namespace declaration
Loading history...
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.

Loading history...
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.

Loading history...
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
}