Issues (108)

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.

src/Support/Attribute.php (2 issues)

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 EntWeChat\Support;
4
5
use EntWeChat\Core\Exceptions\InvalidArgumentException;
6
7
/**
8
 * Class Attributes.
9
 */
10
abstract class Attribute extends Collection
11
{
12
    /**
13
     * Attributes alias.
14
     *
15
     * @var array
16
     */
17
    protected $aliases = [];
18
19
    /**
20
     * Auto snake attribute name.
21
     *
22
     * @var bool
23
     */
24
    protected $snakeable = true;
25
26
    /**
27
     * Required attributes.
28
     *
29
     * @var array
30
     */
31
    protected $requirements = [];
32
33
    /**
34
     * Constructor.
35
     *
36
     * @param array $attributes
37
     */
38
    public function __construct(array $attributes = [])
39
    {
40
        parent::__construct($attributes);
41
    }
42
43
    /**
44
     * Set attribute.
45
     *
46
     * @param string $attribute
47
     * @param string $value
48
     *
49
     * @return Attribute
50
     */
51
    public function setAttribute($attribute, $value)
52
    {
53
        $this->set($attribute, $value);
54
55
        return $this;
56
    }
57
58
    /**
59
     * Get attribute.
60
     *
61
     * @param string $attribute
62
     * @param mixed  $default
63
     *
64
     * @return mixed
65
     */
66
    public function getAttribute($attribute, $default)
67
    {
68
        return $this->get($attribute, $default);
69
    }
70
71
    /**
72
     * Set attribute.
73
     *
74
     * @param string $attribute
75
     * @param mixed  $value
76
     *
77
     * @throws \EntWeChat\Core\Exceptions\InvalidArgumentException
78
     *
79
     * @return Attribute
80
     */
81
    public function with($attribute, $value)
82
    {
83
        $this->snakeable && $attribute = Str::snake($attribute);
84
85
        if (!$this->validate($attribute, $value)) {
86
            throw new InvalidArgumentException("Invalid attribute '{$attribute}'.");
87
        }
88
89
        $this->set($attribute, $value);
90
91
        return $this;
92
    }
93
94
    /**
95
     * Attribute validation.
96
     *
97
     * @param string $attribute
98
     * @param mixed  $value
99
     *
100
     * @return bool
101
     */
102
    protected function validate($attribute, $value)
0 ignored issues
show
The parameter $attribute 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...
The parameter $value 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...
103
    {
104
        return true;
105
    }
106
107
    /**
108
     * Override parent set() method.
109
     *
110
     * @param string $attribute
111
     * @param mixed  $value
112
     */
113
    public function set($attribute, $value = null)
114
    {
115
        parent::set($this->getRealKey($attribute), $value);
116
    }
117
118
    /**
119
     * Override parent get() method.
120
     *
121
     * @param string $attribute
122
     * @param mixed  $default
123
     *
124
     * @return mixed
125
     */
126
    public function get($attribute, $default = null)
127
    {
128
        return parent::get($this->getRealKey($attribute), $default);
129
    }
130
131
    /**
132
     * Magic call.
133
     *
134
     * @param string $method
135
     * @param array  $args
136
     *
137
     * @return Attribute
138
     */
139
    public function __call($method, $args)
140
    {
141
        if (stripos($method, 'with') === 0) {
142
            $method = substr($method, 4);
143
        }
144
145
        return $this->with($method, array_shift($args));
146
    }
147
148
    /**
149
     * Magic set.
150
     *
151
     * @param string $property
152
     * @param mixed  $value
153
     *
154
     * @return Attribute
155
     */
156
    public function __set($property, $value)
157
    {
158
        return $this->with($property, $value);
159
    }
160
161
    /**
162
     * Whether or not an data exists by key.
163
     *
164
     * @param string $key
165
     *
166
     * @return bool
167
     */
168
    public function __isset($key)
169
    {
170
        return parent::__isset($this->getRealKey($key));
171
    }
172
173
    /**
174
     * Return the raw name of attribute.
175
     *
176
     * @param string $key
177
     *
178
     * @return string
179
     */
180
    protected function getRealKey($key)
181
    {
182
        if ($alias = array_search($key, $this->aliases, true)) {
183
            $key = $alias;
184
        }
185
186
        return $key;
187
    }
188
189
    /**
190
     * Check required attributes.
191
     *
192
     * @throws InvalidArgumentException
193
     */
194
    protected function checkRequiredAttributes()
195
    {
196
        foreach ($this->requirements as $attribute) {
197
            if (!isset($this->$attribute)) {
198
                throw new InvalidArgumentException(" '{$attribute}' cannot be empty.");
199
            }
200
        }
201
    }
202
203
    /**
204
     * Return all items.
205
     *
206
     * @throws InvalidArgumentException
207
     *
208
     * @return array
209
     */
210
    public function all()
211
    {
212
        $this->checkRequiredAttributes();
213
214
        return parent::all();
215
    }
216
}
217