Issues (6)

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/Event.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
namespace Yep\Stopwatch;
3
4
class Event {
5
	protected $name;
6
	protected $group;
7
8
	/** @var int|float */
9
	protected $start_time = 0;
10
11
	/** @var int|float */
12
	protected $stop_time = 0;
13
14
	/** @var int */
15
	protected $memory_usage = 0;
16
	protected $started_laps = [];
17
18
	/** @var Lap[] */
19
	protected $stopped_laps = [];
20
21
	/**
22
	 * Event constructor
23
	 *
24
	 * @param string      $name
25
	 * @param null|string $group
26
	 */
27 7
	public function __construct($name, $group = null) {
28 7
		$this->name = $name;
29 7
		$this->group = $group;
30 7
	}
31
32
	/**
33
	 * Returns the event name
34
	 *
35
	 * @return string
36
	 */
37 2
	public function getName() {
38 2
		return $this->name;
39
	}
40
41
	/**
42
	 * Returns the event group
43
	 *
44
	 * @return null|string
45
	 */
46 2
	public function getGroup() {
47 2
		return $this->group;
48
	}
49
50
	/**
51
	 * Starts new lap in the event
52
	 *
53
	 * @return Event
54
	 */
55 6
	public function startLap() {
56 6
		$start_time = microtime(true);
57
58 6
		if ($this->start_time === 0) {
59 6
			$this->start_time = $start_time;
60 6
		}
61
62 6
		$this->started_laps[] = $start_time;
63
64 6
		return $this;
65
	}
66
67
	/**
68
	 * Stops latest lap in the event
69
	 *
70
	 * @return Event
71
	 */
72 7
	public function stopLap() {
73 7
		if (empty($this->started_laps)) {
74 3
			throw new StopwatchLapNotStartedException('You must call startLap() before stopLap()');
75
		}
76
77 6
		$this->memory_usage = memory_get_usage(true);
78 6
		$this->stop_time = microtime(true);
79
80 6
		$this->stopped_laps[] = new Lap(array_pop($this->started_laps), $this->stop_time, $this->memory_usage);
81
82 6
		return $this;
83
	}
84
85
	/**
86
	 * Stops started laps
87
	 */
88 1
	public function stopStartedLaps() {
89 1
		while (!empty($this->started_laps)) {
90 1
			$this->stopLap();
91 1
		}
92 1
	}
93
94
	/**
95
	 * Returns true if some started lap exists, or false if not
96
	 *
97
	 * @return bool
98
	 */
99 3
	public function hasStartedLaps() {
100 3
		return !empty($this->started_laps);
101
	}
102
103
	/**
104
	 * Returns the start time of the first lap
105
	 *
106
	 * @return int|float Time in seconds
107
	 */
108 1
	public function getStartTime() {
109 1
		return $this->start_time;
110
	}
111
112
	/**
113
	 * Returns the stop time of the last stopped lap
114
	 *
115
	 * @return int|float Time in seconds
116
	 */
117 1
	public function getStopTime() {
118 1
		return $this->stop_time;
119
	}
120
121
	/**
122
	 * Returns the duration of all laps durations
123
	 *
124
	 * @return float|int Time in seconds
125
	 */
126 1
	public function getDuration() {
127 1
		return $this->stop_time - $this->start_time;
128
	}
129
130
	/**
131
	 * Returns the memory usage
132
	 *
133
	 * @return int Memory in bytes
134
	 */
135 2
	public function getMemoryUsage() {
136 2
		return $this->memory_usage;
137
	}
138
139
	/**
140
	 * Returns the stopped laps
141
	 *
142
	 * @return Lap[]
143
	 */
144 2
	public function getStoppedLaps() {
145 2
		return $this->stopped_laps;
146
	}
147
148
	/**
149
	 * Returns the lowest duration of all laps
150
	 *
151
	 * @return float|int Time in seconds
152
	 */
153 2
	public function getMinDuration() {
154 2
		if (empty($this->stopped_laps)) {
155 1
			return 0;
156
		}
157
158 1
		$duration = 0;
159
160 1
		foreach ($this->stopped_laps as $lap) {
161 1
			$lap_duration = $lap->getDuration();
162
163 1
			if ($duration === 0 || $lap_duration < $duration) {
164 1
				$duration = $lap_duration;
165 1
			}
166 1
		}
167
168 1
		return $duration;
169
	}
170
171
	/**
172
	 * Returns the highest duration of all laps
173
	 *
174
	 * @return float|int Time in seconds
175
	 */
176 2 View Code Duplication
	public function getMaxDuration() {
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...
177 2
		if (empty($this->stopped_laps)) {
178 1
			return 0;
179
		}
180
181 1
		$duration = 0;
182
183 1
		foreach ($this->stopped_laps as $lap) {
184 1
			if (($lap_duration = $lap->getDuration()) > $duration) {
185 1
				$duration = $lap_duration;
186 1
			}
187 1
		}
188
189 1
		return $duration;
190
	}
191
192
	/**
193
	 * Returns the average duration of all laps
194
	 *
195
	 * @return float|int Time in seconds
196
	 */
197 2 View Code Duplication
	public function getAverageDuration() {
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...
198 2
		if (empty($this->stopped_laps)) {
199 1
			return 0;
200
		}
201
202 1
		$duration = 0;
203 1
		$count = 0;
204
205 1
		foreach ($this->stopped_laps as $lap) {
206 1
			$duration += $lap->getDuration();
207 1
			$count++;
208 1
		}
209
210 1
		return $duration / $count;
211
	}
212
}
213