Issues (15)

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/Response/Response.php (3 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
 * This file is part of the GestPayWS library.
5
 *
6
 * (c) Manuel Dalla Lana <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace EndelWar\GestPayWS\Response;
13
14
use Exception;
15
use InvalidArgumentException;
16
17
/**
18
 * Class Response
19
 * @package EndelWar\GestPayWS\Response
20
 */
21
abstract class Response implements \ArrayAccess
22
{
23
    protected $data = array();
24
    protected $parametersName = array();
25
26
    /**
27
     * @param \SimpleXMLElement $xml
28
     * @throws Exception
29
     */
30 21
    public function __construct($xml)
31
    {
32 21
        $array = json_decode(json_encode($xml), true);
33
        $array = array_map(function ($value) {
34 21
            if (is_array($value) && empty($value)) {
35 21
                return '';
36
            }
37
38 21
            return $value;
39 21
        }, $array);
40 21
        $this->fromArray($array);
41 21
    }
42
43
    /**
44
     * @param string $key
45
     * @param mixed $value
46
     * @throws InvalidArgumentException
47
     */
48 21 View Code Duplication
    public function set($key, $value)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
    {
50 21
        if (!in_array($key, $this->parametersName, true)) {
51 1
            throw new InvalidArgumentException(sprintf('%s is not a valid parameter name.', $key));
52
        }
53 21
        $this->data[$key] = $value;
54 21
    }
55
56
    /**
57
     * @param string $key
58
     *
59
     * @return mixed|null The value at the specified index or null.
60
     */
61 11
    public function get($key)
62
    {
63 11
        if (array_key_exists($key, $this->data)) {
64 9
            return $this->data[$key];
65
        }
66
67 2
        return;
68
    }
69
70
    /**
71
     * @param array $data
72
     */
73 21
    public function fromArray($data)
74
    {
75 21
        foreach ($data as $key => $value) {
76 21
            $this->set($key, $value);
77 21
        }
78 21
    }
79
80
    /**
81
     * @return array
82
     */
83 4
    public function toArray()
84
    {
85 4
        return $this->data;
86
    }
87
88
    /**
89
     * @return mixed
90
     */
91 2
    public function toXML()
92
    {
93 2
        $data = $this->toArray();
94 2
        $xml = new \SimpleXMLElement('<GestPayCryptDecrypt/>');
95 2
        array_walk_recursive($data, function ($value, $key) use ($xml) {
96 2
            $xml->addChild($key, $value);
97 2
        });
98
99 2
        $dom = new \DOMDocument('1.0');
100 2
        $dom->preserveWhiteSpace = false;
101 2
        $dom->formatOutput = true;
102 2
        $dom->loadXML($xml->asXML());
103
104 2
        return $dom->saveXML(null, LIBXML_NOEMPTYTAG);
105
    }
106
107 5
    public function isOK()
108
    {
109 5
        return ($this->get('TransactionResult') === 'OK');
110
    }
111
112
    /**
113
     * Returns whether the requested index exists
114
     *
115
     * @param string $key
116
     *
117
     * @return bool
118
     */
119 1
    public function offsetExists($key)
120
    {
121 1
        return array_key_exists($key, $this->data);
122
    }
123
124
    /**
125
     * Returns the value at the specified index
126
     *
127
     * @param string $key The index with the value.
128
     *
129
     * @return mixed|null The value at the specified index or null.
130
     */
131 1
    public function offsetGet($key)
132
    {
133 1
        return $this->get($key);
134
    }
135
136
    /**
137
     * Sets the value at the specified index to $value
138
     *
139
     * @param string $key The index being set.
140
     * @param mixed $value The new value for the index
141
     */
142 1
    public function offsetSet($key, $value)
143
    {
144 1
        $this->set($key, $value);
145 1
    }
146
147
    /**
148
     * Unsets the value at the specified index
149
     *
150
     * @param string $key
151
     */
152 1
    public function offsetUnset($key)
153
    {
154 1
        unset($this->data[$key]);
155 1
    }
156
157
    /**
158
     * Magic getter, calls getXXX if exists.
159
     *
160
     * @param string $key
161
     *
162
     * @return mixed
163
     */
164 1 View Code Duplication
    public function __get($key)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
165
    {
166 1
        $getter = 'get' . $this->classify($key);
167 1
        if (method_exists($this, $getter)) {
168
            return call_user_func(array($this, $getter));
169
        }
170
171 1
        return $this->get($key);
172
    }
173
174
    /**
175
     * Magic setter, calls setXXX if exists.
176
     * @param $key
177
     * @param $value
178
     *
179
     * @return mixed
180
     */
181 1 View Code Duplication
    public function __set($key, $value)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
182
    {
183 1
        $setter = 'set' . $this->classify($key);
184 1
        if (method_exists($this, $setter)) {
185
            return call_user_func_array(array($this, $setter), array($value));
186
        }
187 1
        $this->set($key, $value);
188 1
    }
189
190
    /**
191
     * Converts a string into a CamelCase word.
192
     *
193
     * @param string $string The string to classify.
194
     *
195
     * @return string The classified word.
196
     */
197 2
    private function classify($string)
198
    {
199 2
        return str_replace(' ', '', ucwords(strtr($string, '_-', ' ')));
200
    }
201
202
    /**
203
     * Returns whether the requested index exists
204
     *
205
     * @param string $key
206
     *
207
     * @return bool
208
     */
209 1
    public function __isset($key)
210
    {
211 1
        return isset($this->data[$key]);
212
    }
213
214
    /**
215
     * Unsets the value at the specified index
216
     *
217
     * @param string $key
218
     */
219 1
    public function __unset($key)
220
    {
221 1
        unset($this->data[$key]);
222 1
    }
223
}
224