Issues (74)

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.

src/services/ModelService.php (3 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
2
namespace keeko\tools\services;
3
4
use keeko\framework\schema\ActionSchema;
5
use keeko\tools\model\Project;
6
use keeko\tools\model\Relationship;
7
use keeko\tools\model\Relationships;
8
use phootwork\collection\Map;
9
use phootwork\collection\Set;
10
use Propel\Generator\Model\Database;
11
use Propel\Generator\Model\Table;
12
13
class ModelService extends AbstractService {
14
15
	/** @var ModelReader */
16
	private $reader = null;
17
18
	public function read(Project $project = null) {
19
		if ($project === null) {
20
			if ($this->project->hasSchemaFile()) {
21
				$project = $this->project;
22
			} else {
23
				$project = new Project($this->project->getRootPath() . '/vendor/keeko/core');
24
			}
25
		}
26
		$this->reader = new ModelReader($project, $this->service);
27
	}
28
29
	/**
30
	 * @return ModelReader
31 12
	 */
32 12
	private function getReader() {
33 12
		if ($this->reader === null) {
34 12
			$this->read();
35 12
		}
36
		return $this->reader;
37 12
	}
38 12
39
	/**
40 12
	 * Returns the propel schema. The three locations, where the schema is looked up in:
41 12
	 *
42 12
	 * @return string|null the path to the schema
43 12
	 */
44 12
	public function getSchema() {
45
		if ($this->getReader()->getProject()->hasSchemaFile()) {
46 12
			return $this->getReader()->getProject()->getSchemaFileName();
47 12
		}
48
49 12
		return null;
50
	}
51
52
	public function isCoreSchema() {
53 12
		return $this->getReader()->getProject()->getPackage()->getFullName() == 'keeko/core';
54
	}
55 12
56
	public function hasSchema() {
57
		return $this->getReader()->getProject()->hasSchemaFile();
58 3
	}
59 3
60
	/**
61
	 * Returns the propel database
62
	 *
63
	 * @return Database
64
	 */
65
	public function getDatabase() {
66
		return $this->getReader()->getDatabase();
67
	}
68
69
	/**
70
	 * Returns the tableName for a given name
71
	 *
72 12
	 * @param String $name tableName or modelName
73 12
	 * @return String tableName
74 12
	 */
75 12
	public function getTableName($name) {
76 12
		return $this->getReader()->getTableName($name);
77 12
	}
78
79 12
	/**
80
	 * Returns all model names
81
	 *
82
	 * @return Set
83
	 */
84
	public function getModelNames() {
85
		return $this->getReader()->getModelNames();
86
	}
87
88 11
	/**
89 11
	 * Returns the propel models from the database, where table namespace matches package namespace
90 11
	 *
91 11
	 * @return Map
92 11
	 */
93
	public function getModels() {
94 11
		return $this->getReader()->getModels();
95
	}
96
97
	/**
98
	 * Returns the model for the given name
99
	 *
100
	 * @param String $name modelName or tableName
101
	 * @return Table
102
	 */
103
	public function getModel($name) {
104
		return $this->getReader()->getModel($name);
105
	}
106
107
// 	/**
108
// 	 * Returns the model names for a given package
109
// 	 *
110
// 	 * @param PackageSchema $package a package to search models for, if omitted global package is used
111
// 	 * @return array array with string of model names
112
// 	 */
113
// 	public function getPackageModelNames(PackageSchema $package = null) {
114
// 		if ($package === null) {
115
// 			$package = $this->packageService->getPackage();
116
// 		}
117 1
118 1
// 		$models = [];
0 ignored issues
show
Unused Code Comprehensibility introduced by
52% 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...
119 1
// 		// if this is a core-module, find the related model
120 1
// 		if ($package->getVendor() == 'keeko' && $this->isCoreSchema()) {
121
// 			$model = $package->getName();
122 1
// 			if ($this->hasModel($model)) {
123
// 				$models [] = $model;
124 1
// 			}
125 1
// 		}
126 1
127 1
// 		// anyway, generate all
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...
128 1
// 		else {
129 1
// 			foreach ($this->getModels() as $model) {
130
// 				$models [] = $model->getOriginCommonName();
131 1
// 			}
132
// 		}
133
134
// 		return $models;
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...
135
// 	}
136
137
	/**
138
	 * Checks whether the given model exists
139
	 *
140 7
	 * @param String $name tableName or modelName
141 7
	 * @return boolean
142 7
	 */
143
	public function hasModel($name) {
144
		return $this->getReader()->hasModel($name);
145
	}
146
147 7
	/**
148
	 * Parses the model name from a given action name
149 7
	 *
150
	 * @param ActionSchema $action
151
	 * @return String modelName
152
	 */
153
	public function getModelNameByAction(ActionSchema $action) {
154
		$actionName = $action->getName();
155
		$modelName = null;
156
		if (($pos = strpos($actionName, '-')) !== false) {
157
			$modelName = substr($actionName, 0, $pos);
158 8
		}
159 8
		return $modelName;
160
	}
161
162
	/**
163
	 * Returns the full model object name, including namespace
164
	 *
165
	 * @param ActionSchema $action
166
	 * @return String fullModelObjectName
167 1
	 */
168 1
	public function getFullModelObjectName(ActionSchema $action) {
169 1
		$database = $this->getDatabase();
170 1
		$modelName = $this->getModelNameByAction($action);
171 1
		$model = $this->getModel($modelName);
172 1
		$modelObjectName = $model->getPhpName();
173 1
174 1
		return $database->getNamespace() . '\\' . $modelObjectName;
175 1
	}
176 1
177
	/**
178 1
	 * Returns wether the given action refers to a model.
179 1
	 *
180
	 * Examples:
181 1
	 *
182
	 * Action: user-create => model: user
183
	 * Action: recover-password => no model
184
	 *
185
	 * @param ActionSchema $action
186
	 * @return boolean
187
	 */
188
	public function isModelAction(ActionSchema $action) {
189
		$modelName = $this->getModelNameByAction($action);
190
		return $this->hasModel($modelName);
191
	}
192
193
	/**
194
	 * Returns all model relationships.
195
	 *
196
	 * @param Table $model
197
	 * @return Relationships
198
	 */
199
	public function getRelationships(Table $model) {
200
		return $this->getReader()->getRelationships($model);
201
	}
202
203
	/**
204
	 * Returns a relationship for a given related type name on a given model
205
	 *
206
	 * @param Table $model
207
	 * @param string $relatedTypeName
208
	 * @return Relationship
209
	 */
210
	public function getRelationship(Table $model, $relatedTypeName) {
211
		$relationships = $this->getRelationships($model);
212 10
		return $relationships->get($relatedTypeName);
213 10
	}
214
}
215