Issues (2)

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/Benchmark.php (2 issues)

Labels
Severity

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 Asad\Bench;
4
5
use LogicException;
6
7
class Benchmark
8
{
9
    protected $start_time;
10
11
    protected $end_time;
12
13
    protected $memory_usage;
14
15
    /**
16
     * Sets start microtime
17
     *
18
     * @return void
19
     */
20
    public function start()
21
    {
22
        $this->start_time = microtime(true);
23
    }
24
25
    /**
26
     * Sets end microtime
27
     *
28
     * @return $this
29
     * @throws Exception
30
     */
31
    public function end()
32
    {
33
        if (!$this->hasStarted()) {
34
            throw new LogicException("You must call start()");
35
        }
36
37
        $this->end_time = microtime(true);
38
        $this->memory_usage = memory_get_usage(true);
39
        return $this;
40
    }
41
42
    /**
43
     * Returns the elapsed time, readable or not
44
     *
45
     * @param bool $raw
46
     * @param  string $format The format to display (printf format)
47
     * @return float|string
48
     * @throws Exception
49
     */
50
    public function getTime($raw = false, $format = null)
51
    {
52
        if (!$this->hasStarted()) {
53
            throw new LogicException("You must call start()");
54
        }
55
56
        if (!$this->hasEnded()) {
57
            throw new LogicException("You must call end()");
58
        }
59
60
        $elapsed = $this->end_time - $this->start_time;
61
62
        return $raw ? $elapsed : self::readableElapsedTime($elapsed, $format);
63
    }
64
65
    /**
66
     * Returns the memory usage at the end checkpoint
67
     *
68
     * @param  boolean $readable Whether the result must be human readable
0 ignored issues
show
There is no parameter named $readable. 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...
69
     * @param  string  $format   The format to display (printf format)
70
     * @return string|float
71
     */
72
    public function getMemoryUsage($raw = false, $format = null)
73
    {
74
        return $raw ? $this->memory_usage : self::readableSize($this->memory_usage, $format);
75
    }
76
77
    /**
78
     * Returns the memory peak, readable or not
79
     *
80
     * @param  boolean $readable Whether the result must be human readable
0 ignored issues
show
There is no parameter named $readable. 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...
81
     * @param  string  $format   The format to display (printf format)
82
     * @return string|float
83
     */
84
    public function getMemoryPeak($raw = false, $format = null)
85
    {
86
        $memory = memory_get_peak_usage(true);
87
88
        return $raw ? $memory : self::readableSize($memory, $format);
89
    }
90
91
    /**
92
     * Wraps a callable with start() and end() calls
93
     *
94
     * Additional arguments passed to this method will be passed to
95
     * the callable.
96
     *
97
     * @param callable $callable
98
     * @return mixed
99
     */
100
    public function run(callable $callable)
101
    {
102
        $arguments = func_get_args();
103
        array_shift($arguments);
104
105
        $this->start();
106
        $result = call_user_func_array($callable, $arguments);
107
        $this->end();
108
109
        return $result;
110
    }
111
112
    /**
113
     * Returns a human readable memory size
114
     *
115
     * @param   int    $size
116
     * @param   string $format   The format to display (printf format)
117
     * @param   int    $round
118
     * @return  string
119
     */
120
    public static function readableSize($size, $format = null, $round = 3)
121
    {
122
        $mod = 1024;
123
124
        if (is_null($format)) {
125
            $format = '%.2f%s';
126
        }
127
128
        $units = explode(' ', 'B Kb Mb Gb Tb');
129
130
        for ($i = 0; $size > $mod; $i++) {
131
            $size /= $mod;
132
        }
133
134
        if (0 === $i) {
135
            $format = preg_replace('/(%.[\d]+f)/', '%d', $format);
136
        }
137
138
        return sprintf($format, round($size, $round), $units[$i]);
139
    }
140
141
    /**
142
     * Returns a human readable elapsed time
143
     *
144
     * @param  float $microtime
145
     * @param  string  $format   The format to display (printf format)
146
     * @return string
147
     */
148
    public static function readableElapsedTime($microtime, $format = null, $round = 3)
149
    {
150
        if (is_null($format)) {
151
            $format = '%.3f%s';
152
        }
153
154
        if ($microtime >= 1) {
155
            $unit = 's';
156
            $time = round($microtime, $round);
157
        } else {
158
            $unit = 'ms';
159
            $time = round($microtime * 1000);
160
161
            $format = preg_replace('/(%.[\d]+f)/', '%d', $format);
162
        }
163
164
        return sprintf($format, $time, $unit);
165
    }
166
167
    public function hasEnded()
168
    {
169
        return isset($this->end_time);
170
    }
171
172
    public function hasStarted()
173
    {
174
        return isset($this->start_time);
175
    }
176
}
177