Issues (59)

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/EntryCollection.php (2 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
 * Directus – <http://getdirectus.com>
5
 *
6
 * @link      The canonical repository – <https://github.com/directus/directus>
7
 * @copyright Copyright 2006-2016 RANGER Studio, LLC – <http://rangerstudio.com>
8
 * @license   GNU General Public License (v3) – <http://www.gnu.org/copyleft/gpl.html>
9
 */
10
11
namespace Directus\SDK\Response;
12
13
use Directus\Util\ArrayUtils;
14
15
/**
16
 * Entry Collection
17
 *
18
 * @author Welling Guzmán <[email protected]>
19
 */
20
class EntryCollection implements ResponseInterface, \IteratorAggregate, \ArrayAccess, \Countable
21
{
22
    /**
23
     * @var array
24
     */
25
    protected $items = [];
26
27
    /**
28
     * @var array
29
     */
30
    protected $rawData = [];
31
32
    /**
33
     * @var Entry
34
     */
35
    protected $metadata = [];
36
37
    /**
38
     * EntryCollection constructor.
39
     *
40
     * @param $data
41
     */
42 22
    public function __construct($data)
43
    {
44 22
        $this->rawData = $data;
45 22
        $this->metadata = $this->pickMetadata($data);
46
47 22
        $rows = $this->pickRows($data);
48 22
        $items = [];
49 22
        foreach($rows as $row) {
50 22
            $items[] = new Entry($row);
51 11
        }
52
53 22
        $this->items = $items;
54 22
    }
55
56
    /**
57
     * Pick the metadata out of the raw data
58
     *
59
     * @param $data
60
     *
61
     * @return Entry
62
     */
63 22
    protected function pickMetadata($data)
64
    {
65 22
        $metadata = [];
66 22 View Code Duplication
        if (ArrayUtils::has($data, 'rows')) {
0 ignored issues
show
This code seems to be duplicated across 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...
67 22
            $metadata = ArrayUtils::omit($data, 'rows');
68 19
        } else if (ArrayUtils::has($data, 'meta')) {
69 16
            $metadata = ArrayUtils::get($data, 'meta');
70 8
        }
71
72 22
        return new Entry($metadata);
73
    }
74
75
    /**
76
     * Pick the "rows" (items) out of the raw data
77
     *
78
     * @param $data
79
     *
80
     * @return array
81
     */
82 22
    protected function pickRows($data)
83
    {
84 22
        $rows = [];
85 22 View Code Duplication
        if (ArrayUtils::has($data, 'rows')) {
0 ignored issues
show
This code seems to be duplicated across 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...
86 22
            $rows = ArrayUtils::get($data, 'rows', []);
87 19
        } else if (ArrayUtils::has($data, 'data')) {
88 16
            $rows = ArrayUtils::get($data, 'data', []);
89 8
        }
90
91 22
        return $rows;
92
    }
93
94
    /**
95
     * Get the response raw data
96
     *
97
     * @return array
98
     */
99 4
    public function getRawData()
100
    {
101 4
        return $this->rawData;
102
    }
103
104
    /**
105
     * Get the response entries
106
     *
107
     * @return array
108
     */
109 2
    public function getData()
110
    {
111 2
        return $this->items;
112
    }
113
114
    /**
115
     * Get the response metadata
116
     *
117
     * @return Entry
118
     */
119 4
    public function getMetaData()
120
    {
121 4
        return $this->metadata;
122
    }
123
124
    /**
125
     * Create a new iterator based on this collection
126
     *
127
     * @return \ArrayIterator
128
     */
129 2
    public function getIterator()
130
    {
131 2
        return new \ArrayIterator($this->items);
132
    }
133
134 2
    public function offsetExists($offset)
135
    {
136 2
        return array_key_exists($offset, $this->items);
137
    }
138
139 2
    public function offsetGet($offset)
140
    {
141 2
        return $this->items[$offset];
142
    }
143
144 2
    public function offsetSet($offset, $value)
145
    {
146 2
        throw new \BadMethodCallException('EntryCollection is read only');
147
    }
148
149 2
    public function offsetUnset($offset)
150
    {
151 2
        throw new \BadMethodCallException('EntryCollection is read only');
152
    }
153
154
    /**
155
     * Gets the number of entries in this collection
156
     *
157
     * @return int
158
     */
159 4
    public function count()
160
    {
161 4
        return count($this->items);
162
    }
163
164
    /**
165
     * @inheridoc
166
     */
167 2
    public function toArray()
168
    {
169 2
        return $this->getRawData();
170
    }
171
172
    /**
173
     * Gets an object representation of this collection
174
     *
175
     * @return object
176
     */
177 2
    public function jsonSerialize()
178
    {
179
        return (object) [
180 2
            'meta' => $this->metadata,
181 2
            'data' => $this->items
182 1
        ];
183
    }
184
}
185