Issues (45)

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/Throwable/ErrorHandler.php (11 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 Dazzle\Throwable;
4
5
use Dazzle\Throwable\Error\FatalError;
6
use Dazzle\Throwable\Error\NoticeError;
7
use Dazzle\Throwable\Error\WarningError;
8
9
abstract class ErrorHandler
10
{
11
    /**
12
     * @var int
13
     */
14
    const E_UNSUPPORTED = 8;
15
16
    /**
17
     * @var int
18
     */
19
    const E_ERROR = 4;
20
21
    /**
22
     * @var int
23
     */
24
    const E_WARNING = 2;
25
26
    /**
27
     * @var int
28
     */
29
    const E_NOTICE = 1;
30
31
    /**
32
     * @var string
33
     */
34
    protected static $errHandler = '\Dazzle\Throwable\Error::toString';
35
36
    /**
37
     * @var string
38
     */
39
    protected static $excHandler = '\Dazzle\Throwable\Exception::toString';
40
41
    /**
42
     * Invoke default Error Handler.
43
     *
44
     * @param int $code
45
     * @param string $message
46
     * @param string $file
47
     * @param int $line
48
     * @throws FatalError
49
     * @throws NoticeError
50
     * @throws WarningError
51
     */
52 16
    public static function handleError($code, $message, $file, $line)
53
    {
54 16
        $list = static::getSystemError($code);
0 ignored issues
show
Since getSystemError() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of getSystemError() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
55 16
        $name = $list[0];
0 ignored issues
show
$name is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
56 16
        $type = $list[1];
57
58 16
        $message = "\"$message\" in $file:$line";
59
60
        switch ($type)
61
        {
62 16
            case static::E_NOTICE:  throw new NoticeError($message);
0 ignored issues
show
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
63 12
            case static::E_WARNING: throw new WarningError($message);
0 ignored issues
show
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
64 7
            case static::E_ERROR:   throw new FatalError($message);
0 ignored issues
show
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
65 1
            default:                return;
0 ignored issues
show
The default body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a default statement must start on the line immediately following the statement.

switch ($expr) {
    default:
        doSomething(); //right
        break;
}


switch ($expr) {
    default:

        doSomething(); //wrong
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
66
        }
67
    }
68
69
    /**
70
     * Invoke default Shutdown Handler.
71
     *
72
     * @param bool $forceKill
73
     */
74
    public static function handleShutdown($forceKill = false)
75
    {
76
        $err = error_get_last();
77
78
        try
79
        {
80
            static::handleError($err['type'], $err['message'], $err['file'], $err['line']);
81
        }
82
        catch (\Error $ex)
0 ignored issues
show
The class Error does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
83
        {
84
            echo call_user_func(static::$errHandler, $ex) . PHP_EOL;
85
        }
86
        catch (\Exception $ex)
87
        {
88
            echo call_user_func(static::$excHandler, $ex) . PHP_EOL;
89
        }
90
91
        if ($forceKill)
92
        {
93
            posix_kill(posix_getpid(), 9);
94
        }
95
    }
96
97
    /**
98
     * @param int $type
99
     * @return array
100
     */
101 16
    private static function getSystemError($type)
102
    {
103
        switch($type)
104
        {
105 16
            case E_ERROR: // 1 //
106 1
                return [ 'E_ERROR',             static::E_ERROR ];
107
108 15
            case E_WARNING: // 2 //
109 1
                return [ 'E_WARNING',           static::E_WARNING ];
110
111 14
            case E_PARSE: // 4 //
112 1
                return [ 'E_PARSE',             static::E_ERROR ];
113
114 13
            case E_NOTICE: // 8 //
115 1
                return [ 'E_NOTICE',            static::E_NOTICE ];
116
117 12
            case E_CORE_ERROR: // 16 //
118 1
                return [ 'E_CORE_ERROR',        static::E_ERROR ];
119
120 11
            case E_CORE_WARNING: // 32 //
121 1
                return [ 'E_CORE_WARNING',      static::E_WARNING ];
122
123 10
            case E_COMPILE_ERROR: // 64 //
124 1
                return [ 'E_COMPILE_ERROR',     static::E_ERROR ];
125
126 9
            case E_COMPILE_WARNING: // 128 //
127 1
                return [ 'E_COMPILE_WARNING',   static::E_WARNING ];
128
129 8
            case E_USER_ERROR: // 256 //
130 1
                return [ 'E_USER_ERROR',        static::E_ERROR ];
131
132 7
            case E_USER_WARNING: // 512 //
133 1
                return [ 'E_USER_WARNING',      static::E_WARNING ];
134
135 6
            case E_USER_NOTICE: // 1024 //
136 1
                return [ 'E_USER_NOTICE',       static::E_NOTICE ];
137
138 5
            case E_STRICT: // 2048 //
139 1
                return [ 'E_STRICT',            static::E_ERROR ];
140
141 4
            case E_RECOVERABLE_ERROR: // 4096 //
142 1
                return [ 'E_RECOVERABLE_ERROR', static::E_WARNING ];
143
144 3
            case E_DEPRECATED: // 8192 //
145 1
                return [ 'E_DEPRECATED',        static::E_NOTICE ];
146
147 2
            case E_USER_DEPRECATED: // 16384 //
148 1
                return [ 'E_USER_DEPRECATED',   static::E_NOTICE ];
149
150
            default:
151 1
                return [ 'E_UNKNOWN',           static::E_UNSUPPORTED ];
152
        }
153
    }
154
}
155