Issues (345)

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.

performance/run.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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 8 and the first side effect is on line 112.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/**
4
 * Returns the list of scripts to compare.
5
 *
6
 * @return array
7
 */
8
function scripts() {
9
    return [
10
        __DIR__ . '/scripts/imperative.php',
11
        __DIR__ . '/scripts/functional.php',
12
        __DIR__ . '/scripts/object-oriented.php',
13
    ];
14
}
15
16
/**
17
 * Returs the list of tests to run.
18
 *
19
 * @return array
20
 */
21
function tests() {
22
    static $tests = null;
23
    if (null == $tests) {
24
        $tests = [
25
            (object) [
26
                'input' => __DIR__ . '/tests/1k-words.input.txt',
27
                'output' => trim(file_get_contents(__DIR__ . '/tests/1k-words.output.txt'))
28
            ],
29
            (object) [
30
                'input' => __DIR__ . '/tests/10k-words.input.txt',
31
                'output' => trim(file_get_contents(__DIR__ . '/tests/10k-words.output.txt'))
32
            ],
33
            (object) [
34
                'input' => __DIR__ . '/tests/100k-words.input.txt',
35
                'output' => trim(file_get_contents(__DIR__ . '/tests/100k-words.output.txt'))
36
            ],
37
        ];
38
    }
39
    return $tests;
40
}
41
42
/**
43
 * Runs the scripts with the tests and shows the results.
44
 *
45
 * @return void
46
 */
47
function main() {
48
    foreach (scripts() as $path) {
49
        echo nameOf($path), ":\n";
50
        foreach (tests() as $test) {
0 ignored issues
show
The expression tests() of type array<integer,?>|null is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
51
            echo "  ", nameOf($test->input), ": ";
52
            if (!passes($path, $test)) {
53
                echo "Failed!\n";
54
            } else {
55
                echo averageTime(3, $path, $test), "\n";
56
            }
57
        }
58
    }
59
}
60
61
/**
62
 * Gets the name of a file without extension from its path.
63
 *
64
 * @param  string $path
65
 * @return string
66
 */
67
function nameOf($path) {
68
    $name = substr($path, strrpos($path, '/') + 1);
69
    return substr($name, 0, strpos($name, '.'));
70
}
71
72
/**
73
 * Runs the given script `$n` times and returns the average running time.
74
 *
75
 * @param  int $n
76
 * @param  string $path
77
 * @param  object $test
78
 * @return int
79
 */
80
function averageTime($n, $path, $test) {
81
    $s = 0;
82
    for ($i=0; $i < $n; $i++) {
83
        $s =+ execute($path, $test->input);
84
    }
85
    return $s / $n;
86
}
87
88
/**
89
 * Checks if running a PHP script with some input returns the expected output.
90
 *
91
 * @param  string $path
92
 * @param  array $test
93
 * @return bool
94
 */
95
function passes($path, $test) {
96
    return $test->output == trim(shell_exec("php {$path} < \"{$test->input}\""));
97
}
98
99
/**
100
 * Runs a PHP file with specific standard input
101
 * and returns its running time in miliseconds.
102
 *
103
 * @param  string $path
104
 * @return array
105
 */
106
function execute($path, $input) {
107
    $start = microtime(true);
108
    shell_exec("php {$path} < \"{$input}\"");
109
    return 1000 * (microtime(true) - $start);
110
}
111
112
main();
113