Issues (1752)

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.

class/benchmark.php (6 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
 * @package		fwolflib
4
 * @subpackage	class
5
 * @copyright	Copyright 2009-2010, Fwolf
6
 * @author		Fwolf <[email protected]>
7
 * @since		2009-11-17
8
 */
9
10
11
require_once(dirname(__FILE__) . '/fwolflib.php');
12
13
14
/**
15
 * Program execute time benchmark toosl.
16
 *
17
 * Time is mesured by microtime.
18
 *
19
 * Reference:
20
 * http://pear.php.net/package/Benchmark/docs/latest/__filesource/fsource_Benchmark__Benchmark-1.2.7doctimer_example.php.html
21
 * http://www.mdsjack.bo.it/index.php?page=kwikemark
22
 * http://www.phpclasses.org/browse/package/2244.html
23
 *
24
 * @deprecated  Use Fwlib\Test\Benchmark
25
 * @package		fwolflib
26
 * @subpackage	class
27
 * @copyright	Copyright 2009, Fwolf
28
 * @author		Fwolf <[email protected]>
29
 * @since		2009-11-17
30
 */
31
class Benchmark extends Fwolflib {
0 ignored issues
show
Deprecated Code introduced by
The class Fwolflib has been deprecated with message: Use classes in Fwlib namespace, see PSR-0/1/2

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
32
33
	/**
34
	 * Define color group
35
	 *
36
	 * Seq: fast to slow
37
	 *
38
	 * @var array
39
	 */
40
	public $aColor = array(
41
		"#00FF00",
42
		"#CCFFCC",
43
		"#77FF77",
44
		"#FFCCCC",
45
		"#FF7777",
46
		"#FF0000"
47
	);
48
49
	/**
50
	 * Group data
51
	 *
52
	 * array(
53
	 * 	iGroup => array(
54
	 * 		desc
55
	 * 		time_start
56
	 * 		time_stop
57
	 * 	)
58
	 * )
59
	 * @var	array
60
	 */
61
	protected $aGroup = array();
62
63
	/**
64
	 * Marker data
65
	 *
66
	 * array(
67
	 * 	iGroup => array(
68
	 * 		iMark => array(
69
	 * 			desc
70
	 * 			time
71
	 * 			dur
72
	 * 			color
73
	 * 			pct
74
	 * 		)
75
	 * 	)
76
	 * )
77
	 * @var	array
78
	 */
79
	protected $aMark = array();
80
81
	/**
82
	 * Current mark group no.
83
	 *
84
	 * 1 group meas start->stop, another start will be group 2.
85
	 * @var	int
86
	 */
87
	protected $iGroup = 0;
88
89
	/**
90
	 * Seq of marker in group, start from 1
91
	 * @var	int
92
	 */
93
	protected $iMark = 1;
94
95
96
	/**
97
	 * Constructor
98
	 *
99
	 * @param	string	$options	Eg: autostart
100
	 */
101
	public function __construct($options = '') {
102
		// Auto start
103
		if (!(false === strpos($options, 'autostart'))) {
104
			$this->Start();
105
		}
106
	} // end of func construct
107
108
109
	/**
110
	 * Display benchmark result
111
	 *
112
	 * @param	string	$options
113
	 */
114
	public function Display($options = '') {
115
		echo $this->Result($options);
116
	} // end of func Display
117
118
119
	/**
120
	 * Format cell bg color
121
	 *
122
	 * Split max/min marker dur by color number, and put each mark in it's color
123
	 * @param	int	$i_group
124
	 */
125
	protected function FormatColor($i_group) {
126
		// Find max/min marker dur
127
		$dur_min = $this->aMark[$i_group][1]['dur'];
128
		$dur_max = $dur_min;
129
		foreach ($this->aMark[$i_group] as $i_mark => &$ar_mark) {
130
			if ($ar_mark['dur'] > $dur_max)
131
				$dur_max = $ar_mark['dur'];
132
			if ($ar_mark['dur'] < $dur_min)
133
				$dur_min = $ar_mark['dur'];
134
		}
135
		$dur = $dur_max - $dur_min;
136
		// Only 1 marker
137
		if (0 == $dur)
138
			$dur = $dur_max;
139
140
		// Amount of color
141
		$i_color = count($this->aColor);
142
		if (1 > $i_color) return;
143
144
		// Split dur
145
		$step = $dur / $i_color;
146
		$ar_dur = array();
147
		// 6 color need 7 bound value
148
		for ($i=0; $i<($i_color + 1); $i++)
149
			$ar_dur[$i] = $step * $i;
150
151
		// Compare, assign color
152
		foreach ($this->aMark[$i_group] as $i_mark => &$ar_mark) {
153
			for ($i=1; $i<($i_color + 1); $i++) {
154
				if (($ar_mark['dur'] - $dur_min) <= $ar_dur[$i]) {
155
					// 5.5 < 6, assign color[5]/color no.6
156
					$ar_mark['color'] = $this->aColor[$i - 1];
157
158
					// Compute dur percent
159
					$ar_mark['pct'] = round(100 * $ar_mark['dur'] / $this->aGroup[$i_group]['dur']);
160
161
					// Quit for
162
					$i = $i_color + 1;
163
				}
164
			}
165
		}
166
	} // end of func FormatColor
167
168
169
	/**
170
	 * Format time to output
171
	 *
172
	 * @param	float	$time
173
	 * @return	string
174
	 */
175 View Code Duplication
	protected function FormatTime($time) {
0 ignored issues
show
This method seems to be duplicated in 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.

Loading history...
176
		// Split dur by '.' to make solid width
177
		$sec = floor($time);
178
		$usec = substr(strval(round($time - $sec, 3)), 2);
179
		$html = <<<EOF
180
181
<div style="float: left; width: 4em; text-align: right;">
182
	{$sec}
183
</div>
184
<div style="float: left;">.</div>
185
<div style="float: left; width: 3em; text-align: left;">
186
	{$usec}
187
</div>
188
189
EOF;
190
		return $html;
191
	} // end of func FormatTime
192
193
194
	/**
195
	 * Get current time, mesured by microsecond
196
	 *
197
	 * @return	float
198
	 */
199
	protected function GetTime() {
200
		list($usec, $sec) = explode(" ", microtime());
201
		return ((float)$usec + (float)$sec) * 1000;
202
	} // end of func GetTime
203
204
205
	/**
206
	 * Set a marker
207
	 *
208
	 * @param	string	$desc	Marker description
209
	 * @param	string	$color	Specific color like '#FF0000' or 'red'
210
	 */
211
	public function Mark($desc = '', $color = '') {
212
		if (1 == $this->iMark)
213
			$this->aMark[$this->iGroup] = array();
214
		$ar = &$this->aMark[$this->iGroup][$this->iMark];
215
216
		if (empty($desc))
217
			$desc = "Group #{$this->iGroup}, Mark #{$this->iMark}";
218
219
		$ar['desc'] = $desc;
220
		$ar['time'] = $this->GetTime();
221
		if (1 == $this->iMark)
222
			$ar['dur'] = $ar['time'] - $this->aGroup[$this->iGroup]['time_start'];
223
		else
224
			$ar['dur'] = $ar['time'] - $this->aMark[$this->iGroup][$this->iMark - 1]['time'];
225
		if (!empty($color))
226
			$ar['color'] = $color;
227
228
		$this->iMark ++;
229
	} // end of func Mark
230
231
232
	/**
233
	 * Get html result
234
	 *
235
	 * @param	string	$options
236
	 * @return	string
237
	 */
238
	public function Result($options = '') {
0 ignored issues
show
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
239
		// Stop last group if it's not stopped
240 View Code Duplication
		if (!isset($this->aGroup[$this->iGroup]['time_stop'])
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.

Loading history...
241
			&& isset($this->aGroup[$this->iGroup]['time_start']))
242
			$this->Stop();
243
244
		$html = '';
245
246
		if (0 <= $this->iGroup) {
247
			$html .= <<<EOF
248
249
<style type="text/css" media="screen, print">
250
<!--
251
	#fl-bm table, #fl-bm td {
252
		border: 1px solid #999;
253
		border-collapse: collapse;
254
		padding-left: 0.2em;
255
	}
256
	#fl-bm table caption, #fl-bm-m {
257
		margin-top: 0.5em;
258
	}
259
	#fl-bm tr.total {
260
		background-color: #E5E5E5;
261
	}
262
-->
263
</style>
264
265
EOF;
266
			$html .= "<div id='fl-bm'>\n";
267
			foreach ($this->aGroup as $i_group => $ar_group) {
268
				$this->FormatColor($i_group);
269
270
				// Stop will create mark, so no 0=mark
271
				$html .= "\t<table id='fl-bm-g{$i_group}'>\n";
272
				$html .= "\t\t<caption>{$ar_group['desc']}</caption>\n";
273
274
				// Th
275
				$html .= <<<EOF
276
277
<thead>
278
<tr>
279
	<th>Dur Time</th>
280
	<th>Mark Description</th>
281
	<th>%</th>
282
</tr>
283
</thead>
284
285
EOF;
286
				// Markers
287
				if (0 < count($this->aMark[$i_group])) {
288
					$html .= "<tbody>\n";
289
					foreach ($this->aMark[$i_group] as $i_mark => $ar_mark) {
290
						$time = $this->FormatTime($ar_mark['dur']);
291
						// Bg color
292
						if (!empty($ar_mark['color']))
293
							$color = ' style="background-color: ' . $ar_mark['color'] . ';"';
294
						else
295
							$color = '';
296
						$html .= <<<EOF
297
298
<tr>
299
	<td{$color}>{$time}</td>
300
	<td>{$ar_mark['desc']}</td>
301
	<td style="text-align: right">{$ar_mark['pct']}%</td>
302
</tr>
303
304
EOF;
305
					}
306
					$html .= "</tbody>\n";
307
				}
308
309
				// Stop has already set marker
310
311
				// Total
312
				$time = $this->FormatTime($ar_group['dur']);
313
				$html .= <<<EOF
314
315
<tr class="total">
316
	<td>{$time}</td>
317
	<td>Total</td>
318
	<td>-</td>
319
</tr>
320
321
EOF;
322
323
				$html .= "\t</table>\n";
324
			}
325
326
			// Memory usage
327
			if (function_exists('memory_get_usage')) {
328
				$memory = number_format(memory_get_usage());
329
				$html .= <<<EOF
330
331
<div id="fl-bm-m">
332
	Memory Usage: $memory
333
</div>
334
335
EOF;
336
			}
337
338
			$html .= "</div>\n";
339
		}
340
341
		return $html;
342
	} // end of func Result
343
344
345
	/**
346
	 * Start the timer
347
	 *
348
	 * @param	string	$desc	Group description
349
	 */
350
	public function Start($desc = '') {
351
		// Stop last group if it's not stopped
352 View Code Duplication
		if (!isset($this->aGroup[$this->iGroup]['time_stop'])
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.

Loading history...
353
			&& isset($this->aGroup[$this->iGroup]['time_start']))
354
			$this->Stop();
355
356
		if (empty($desc))
357
			$desc = "Group #{$this->iGroup}";
358
359
		$this->aGroup[$this->iGroup]['time_start'] = $this->GetTime();
360
		$this->aGroup[$this->iGroup]['desc'] = $desc;
361
	} // end of func Start
362
363
364
	/**
365
	 * Stop the timer
366
	 */
367
	public function Stop() {
368
		$this->Mark('Stop');
369
370
		$time = $this->GetTime();
371
		$ar = &$this->aGroup[$this->iGroup];
372
		$ar['time_stop'] = $time;
373
		$ar['dur'] = $time - $ar['time_start'];
374
375
		$this->iGroup ++;
376
		$this->iMark = 1;
377
	} // end of func Stop
378
379
380
} // end of class Benchmark
381
?>
0 ignored issues
show
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
382