Issues (66)

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/Exception/ErrorHandler.php (5 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 Buttress\Concrete\Exception;
4
5
use League\CLImate\CLImate;
6
7
class ErrorHandler
8
{
9
10
    /** @var \League\CLImate\CLImate */
11
    private $cli;
12
13
    protected $verbose = false;
14
15
    public function __construct(CLImate $cli)
16
    {
17
        $this->cli = $cli;
18
    }
19
20
    /**
21
     * Register this error handler
22
     */
23
    public function register()
24
    {
25
        set_error_handler([$this, 'handleError']);
26
        set_exception_handler([$this, 'handleException']);
27
    }
28
29
    public function setVerbose($verbose)
30
    {
31
        $this->verbose = $verbose;
32
    }
33
34
    /**
35
     * Handle an exception
36
     * @param \Exception $e
37
     */
38
    public function handleException(\Exception $e)
39
    {
40
        $cli = $this->cli;
41
42
        $cli->errorInline(sprintf('<bold>%s</bold> ', '<underline>Uncaught Exception</underline>'))
0 ignored issues
show
The method errorInline() does not exist on League\CLImate\CLImate. Did you maybe mean inline()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
43
            ->errorInline(sprintf('on line <bold><yellow>%s</yellow></bold> ', $e->getLine()))
44
            ->error(sprintf('in <bold><yellow>%s</yellow></bold>', $e->getFile()));
45
46
        $cli->out("<dim><error>>></error></dim> " . $e->getMessage());
47
48
        $this->outputStack();
49
        exit(1);
0 ignored issues
show
Coding Style Compatibility introduced by
The method handleException() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
50
    }
51
52
    /**
53
     * Handle an error
54
     * @param int $code
55
     * @param string $message
56
     * @param string $file
57
     * @param int $line
58
     * @param array $context
59
     * @return bool
60
     */
61
    public function handleError($code, $message, $file, $line, $context)
0 ignored issues
show
The parameter $context 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...
62
    {
63
        if (!(error_reporting() & $code)) {
64
            return false;
65
        }
66
67
        $cli = $this->cli;
68
69
        switch ($code) {
70
            case E_ERROR:
71
            case E_USER_ERROR:
72
                $type = '<error>Fatal Error</error>';
73
                break;
74
            case E_RECOVERABLE_ERROR:
75
            case E_WARNING:
76
            case E_USER_WARNING:
77
                $type = '<yellow>Warning</yellow>';
78
                break;
79
            case E_NOTICE:
80
            case E_USER_NOTICE:
81
                $type = '<green>Notice</green>';
82
                break;
83
            case E_DEPRECATED:
84
            case E_USER_DEPRECATED:
85
                $type = '<blue>Deprecated Alert</blue>';
86
                break;
87
            default:
88
                $type = 'Unknown Error';
89
                break;
90
        }
91
92
        $cli->errorInline(sprintf('<bold>%s</bold> ', $type))
0 ignored issues
show
The method errorInline() does not exist on League\CLImate\CLImate. Did you maybe mean inline()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
93
            ->errorInline(sprintf('on line <bold><yellow>%s</yellow></bold> ', $line))
94
            ->error(sprintf('in <bold><yellow>%s</yellow></bold>', $file));
95
96
        $cli->out("<dim><error>>></error></dim> " . $message);
97
98
        $this->outputStack();
99
        exit(1);
0 ignored issues
show
Coding Style Compatibility introduced by
The method handleError() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
100
    }
101
102
    protected function outputStack()
103
    {
104
        if (!$this->verbose) {
105
            return;
106
        }
107
108
        $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
109
        $count = count($backtrace);
110
111
        $this->cli->br();
112
        foreach ($backtrace as $key => $item) {
113
            $this->cli->dim()->inline(str_pad($count-- . '. ', 4, ' ', STR_PAD_RIGHT));
114
115
            $string = '%s()';
116
            $data = [
117
                $item['function']
118
            ];
119
120
            if (isset($item['class'])) {
121
                list($class, $namespace) = explode('\\', strrev($item['class']), 2);
122
                $string = '%s\\<green>%s</green><dim>%s</dim>%s()';
123
                $data = [
124
                    strrev($namespace),
125
                    strrev($class),
126
                    $item['type'],
127
                    $item['function']
128
                ];
129
            }
130
131
            array_unshift($data, $string);
132
            $this->cli->inline(call_user_func_array('sprintf', $data));
133
134
            if (isset($item['file'])) {
135
                $this->cli->out(
136
                    sprintf(
137
                        '<dim> >> On line <yellow>%s</yellow> in <bold>%s</bold></dim>',
138
                        $item['line'],
139
                        $item['file']
140
                    ));
141
            } else {
142
                $this->cli->br();
143
            }
144
        }
145
    }
146
147
}
148