Issues (8)

Security Analysis    not enabled

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.

code/Flash.php (8 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
/**
4
 * Class Flash
5
 * @method static void info(string $message, bool $closable = null, bool $fadeOut = null)
6
 * @method static void success(string $message, bool $closable = null, bool $fadeOut = null)
7
 * @method static void warning(string $message, bool $closable = null, bool $fadeOut = null)
8
 * @method static void danger(string $message, bool $closable = null, bool $fadeOut = null)
9
 * @method static void alert(string $message, bool $closable = null, bool $fadeOut = null)
10
 * @method static void modal(string $message, bool $closable = null, bool $fadeOut = null)
11
 */
12
class Flash extends ViewableData implements TemplateGlobalProvider
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
13
{
14
    /**
15
     * @config
16
     * @var array
17
     */
18
    private static $defaults = [
0 ignored issues
show
The property $defaults is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
19
        'Type'     => 'success',
20
        'IsModal'  => false,
21
        'Closable' => true,
22
        'FadeOut'  => false
23
    ];
24
25
    /**
26
     * @config
27
     * @var array
28
     */
29
    private static $supported_methods = [
0 ignored issues
show
The property $supported_methods is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
30
        'info',
31
        'success',
32
        'warning',
33
        'danger',
34
        'alert',
35
        'modal'
36
    ];
37
38
    /**
39
     * @config
40
     * @var string
41
     */
42
    private static $template = 'FlashMessage';
0 ignored issues
show
The property $template is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
43
44
    /**
45
     * @config
46
     * @var string
47
     */
48
    private static $session_name = 'FlashMessage';
0 ignored issues
show
The property $session_name is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
49
50
    /**
51
     * @config
52
     * @var bool
53
     */
54
    private static $load_javascript = true;
0 ignored issues
show
The property $load_javascript is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
55
56
    /**
57
     * The Flash Message data
58
     *
59
     * @var array
60
     */
61
    protected $data = [];
62
63
    /**
64
     * @param array $data
65
     */
66
    public function __construct($data)
67
    {
68
        $this->data = (array)$data + (array)self::config()->defaults;
69
70
        parent::__construct();
71
    }
72
73
    /**
74
     * @return array
75
     */
76
    public static function get_template_global_variables()
77
    {
78
        return [
79
            'FlashMessage'
80
        ];
81
    }
82
83
    /**
84
     * @return Flash
85
     */
86
    public static function FlashMessage()
87
    {
88
        return Flash::get();
89
    }
90
91
    /**
92
     * @param $message
93
     * @param string $type
94
     * @param null $closable
95
     * @param null $fadeOut
96
     */
97
    public static function set($message, $type = 'success', $closable = null, $fadeOut = null)
98
    {
99
        $data = [
100
            'Message' => $message,
101
            'Type'    => $type
102
        ];
103
104
        if (null !== $closable) {
105
            $data['Closable'] = $closable;
106
        }
107
108
        if (null !== $fadeOut) {
109
            $data['FadeOut'] = $fadeOut;
110
        }
111
112
        if('modal' === $type) {
113
            $data['IsModal'] = true;
114
        }
115
116
        Session::set(Flash::config()->session_name, $data);
0 ignored issues
show
$data is of type array<string,?>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
117
    }
118
119
    /**
120
     * @return Flash
121
     */
122
    public static function get()
123
    {
124
        $key  = Flash::config()->session_name;
125
        $data = Session::get($key);
126
        Session::clear($key);
127
128
        return (new Flash($data));
129
    }
130
131
    /**
132
     * @return string
0 ignored issues
show
Should the return type not be HTMLText?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
133
     */
134
    public function forTemplate()
135
    {
136
        if (self::config()->load_javascript) {
137
            Requirements::javascript('flashmessage/javascript/flashmessage.js');
138
        }
139
        return $this->customise($this->data)->renderWith(self::config()->template);
140
    }
141
142
    /**
143
     * @param $method
144
     * @param $args
145
     * @throws BadMethodCallException
146
     */
147
    public static function __callStatic($method, $args)
148
    {
149
        if (in_array($method, self::config()->supported_methods)) {
150
            self::set($args[0], $method, isset($args[1]) ? $args[1] : null, isset($args[2]) ? $args[2] : null);
151
        } else {
152
            throw new BadMethodCallException("Method '$method' does not exist on " . __CLASS__);
153
        }
154
    }
155
156
}
157