Issues (51)

Security Analysis    no request data  

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/ProcessingError.php (2 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
3
namespace ParamProcessor;
4
5
/**
6
 * @since 1.0
7
 *
8
 * @licence GNU GPL v2+
9
 * @author Jeroen De Dauw < [email protected] >
10
 */
11
class ProcessingError {
12
13
	const SEVERITY_MINOR = 0;	// Minor error. ie a deprecation notice
14
	const SEVERITY_LOW = 1;		// Lower-then-normal severity. ie an unknown parameter
15
	const SEVERITY_NORMAL = 2;	// Normal severity. ie an invalid value provided
16
	const SEVERITY_HIGH = 3;	// Higher-then-normal severity. ie an invalid value for a significant parameter
17
	const SEVERITY_FATAL = 4;	// Fatal error. Either a missing or an invalid required parameter
18
19
	const ACTION_IGNORE = 0;	// Ignore the error
20
	const ACTION_LOG = 1;		// Log the error
21
	const ACTION_WARN = 2;		// Warn that there is an error
22
	const ACTION_SHOW = 3;		// Show the error
23
	const ACTION_DEMAND = 4;	// Show the error and don't render output
24
25
	public $message;
26
	public $severity;
27
28
	/**
29
	 * List of 'tags' for the error. This is mainly meant for indicating an error
30
	 * type, such as 'missing parameter' or 'invalid value', but allows for multiple
31
	 * such indications.
32
	 *
33
	 * @since 0.4
34
	 *
35
	 * @var string[]
36
	 */
37
	private $tags;
38
39
	/**
40
	 * Where the error occurred.
41
	 *
42
	 * @since 0.4
43
	 *
44
	 * @var string|bool
45
	 */
46
	public $element;
47
48
	/**
49
	 * @param string $message
50
	 * @param integer $severity
51
	 * @param string|bool $element
52
	 * @param string[] $tags
53
	 */
54 35
	public function __construct( string $message, int $severity = self::SEVERITY_NORMAL, $element = false, array $tags = [] ) {
55 35
		$this->message = $message;
56 35
		$this->severity = $severity;
57 35
		$this->element = $element;
58 35
		$this->tags = $tags;
59 35
	}
60
61
	/**
62
	 * Adds one or more tags.
63
	 *
64
	 * @since 0.4.1
65
	 *
66
	 * @param string|string[] $criteria
0 ignored issues
show
There is no parameter named $criteria. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
67
	 */
68
	public function addTags() {
69
		$args = func_get_args();
70
		$this->tags = array_merge( $this->tags, is_array( $args[0] ) ? $args[0] : $args );
0 ignored issues
show
Documentation Bug introduced by
It seems like array_merge($this->tags,...0]) ? $args[0] : $args) of type array is incompatible with the declared type array<integer,string> of property $tags.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
71
	}
72
73
	public function getMessage(): string {
74
		return $this->message;
75
	}
76
77
	/**
78
	 * Returns the element this error occurred at, or 'unknown' when i's unknown.
79
	 */
80 17
	public function getElement(): string {
81 17
		return ( $this->element === false || $this->element === '' ) ? 'unknown' : $this->element;
82
	}
83
84
	/**
85
	 * Returns the severity of the error.
86
	 * @return integer Element of the self::SEVERITY_ enum
87
	 */
88
	public function getSeverity(): int {
89
		return $this->severity;
90
	}
91
92
	/**
93
	 * Returns if the severity is equal to or bigger then the provided one.
94
	 */
95 35
	public function hasSeverity( int $severity ): bool {
96 35
		return $this->severity >= $severity;
97
	}
98
99
	/**
100
	 * Returns if the error has a certain tag.
101
	 */
102
	public function hasTag( string $tag ): bool {
103
		return in_array( $tag, $this->tags );
104
	}
105
106
	/**
107
	 * @return string[]
108
	 */
109
	public function getTags(): array {
110
		return $this->tags;
111
	}
112
113
	/**
114
	 * Returns the action associated with the errors severity.
115
	 *
116
	 * @return integer Element of the self::ACTION_ enum
117
	 * @throws \Exception
118
	 */
119
	public function getAction(): int {
120
		// TODO: as option
121
		$errorActions = [
122
			self::SEVERITY_MINOR => self::ACTION_LOG,
123
			self::SEVERITY_LOW => self::ACTION_WARN,
124
			self::SEVERITY_NORMAL => self::ACTION_SHOW,
125
			self::SEVERITY_HIGH => self::ACTION_DEMAND,
126
		];
127
128
		if ( $this->severity === self::SEVERITY_FATAL ) {
129
			// This action should not be configurable, as lowering it would break in the Validator class.
130
			return self::ACTION_DEMAND;
131
		}
132
		elseif ( array_key_exists( $this->severity, $errorActions ) ) {
133
			return $errorActions[$this->severity];
134
		}
135
		else {
136
			throw new \Exception( "No action associated with error severity '$this->severity'" );
137
		}
138
	}
139
140
	/**
141
	 * Returns if the action associated with the severity is equal to or bigger then the provided one.
142
	 */
143
	public function hasAction( int $action ): bool {
144
		return $this->getAction() >= $action;
145
	}
146
147
	/**
148
	 * Returns if the error is fatal.
149
	 */
150 35
	public function isFatal(): bool {
151 35
		return $this->hasSeverity( self::SEVERITY_FATAL );
152
	}
153
154
	/**
155
	 * Returns if the error should be logged.
156
	 */
157
	public function shouldLog(): bool {
158
		return $this->hasAction( self::ACTION_LOG );
159
	}
160
161
	/**
162
	 * Returns if there should be a warning that errors are present.
163
	 */
164
	public function shouldWarn(): bool {
165
		return $this->hasAction( self::ACTION_WARN );
166
	}
167
168
	/**
169
	 * Returns if the error message should be shown.
170
	 */
171
	public function shouldShow(): bool {
172
		return $this->hasAction( self::ACTION_SHOW );
173
	}
174
175
	/**
176
	 * Returns if the error message should be shown, and the output not be rendered.
177
	 */
178
	public function shouldDemand(): bool {
179
		return $this->hasAction( self::ACTION_DEMAND );
180
	}
181
182
}
183