Issues (86)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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/Trucker/Responses/Collection.php (4 issues)

1
<?php
2
3
namespace Trucker\Responses;
4
5
/**
6
 * Collection class returned from CollectionFinder when
7
 * a colleciton of results is requested.
8
 *
9
 * @author Alessandro Manno <[email protected]>
10
 */
11
class Collection implements \Iterator
12
{
13
    /**
14
     * Var to hold the actual source array collection.
15
     *
16
     * @var array
17
     */
18
    private $collection;
19
20
    /**
21
     * Associative array of metadata related to the
22
     * collection.
23
     *
24
     * @var array
25
     */
26
    public $metaData = [];
27
28
    /**
29
     * Constructor for the collection.
30
     *
31
     * @param array $givenArray array of objects
32
     */
33 14
    public function __construct($givenArray)
34
    {
35 14
        $this->collection = $givenArray;
36 14
    }
37
38
    /**
39
     * Function to conform with Iterator interface.
40
     *
41
     * @see  Iterator
42
     *
43
     * @return \Trucker\Resource\Model
44
     */
45 1
    public function rewind()
46
    {
47 1
        return reset($this->collection);
48
    }
49
50
    /**
51
     * Function to conform with Iterator interface.
52
     *
53
     * @see  Iterator
54
     *
55
     * @return \Trucker\Resource\Model
56
     */
57 1
    public function current()
58
    {
59 1
        return current($this->collection);
60
    }
61
62
    /**
63
     * Function to conform with Iterator interface.
64
     *
65
     * @see  Iterator
66
     *
67
     * @return \Trucker\Resource\Model
68
     */
69 1
    public function key()
70
    {
71 1
        return key($this->collection);
0 ignored issues
show
Bug Best Practice introduced by
The expression return key($this->collection) also could return the type integer|string which is incompatible with the documented return type Trucker\Resource\Model.
Loading history...
72
    }
73
74
    /**
75
     * Function to conform with Iterator interface.
76
     *
77
     * @see  Iterator
78
     *
79
     * @return \Trucker\Resource\Model
80
     */
81 3
    public function next()
82
    {
83 3
        return next($this->collection);
84
    }
85
86
    /**
87
     * Function to conform with Iterator interface.
88
     *
89
     * @see  Iterator
90
     *
91
     * @return bool
92
     */
93 1
    public function valid()
94
    {
95 1
        return null !== key($this->collection);
96
    }
97
98
    /**
99
     * Function to return the size of the collection.
100
     *
101
     * @return int size of collection
102
     */
103 5
    public function size()
104
    {
105 5
        return count($this->collection);
106
    }
107
108
    /**
109
     * Function to return the first item of the collection.
110
     *
111
     * @return \Trucker\Resource\Model
112
     */
113 5
    public function first()
114
    {
115 5
        return empty($this->collection) ? null : $this->collection[0];
116
    }
117
118
    /**
119
     * Function to return the last item of the collection.
120
     *
121
     * @return \Trucker\Resource\Model
122
     */
123 1
    public function last()
124
    {
125 1
        return empty($this->collection) ? null : $this->collection[count($this->collection) - 1];
126
    }
127
128
    /**
129
     * Function to convert the collection to an array using
130
     * each collection elements attributes.
131
     *
132
     * @param string $collectionKey
133
     * @param string $metaKey
134
     *
135
     * @return array
136
     */
137 3
    public function toArray($collectionKey = null, $metaKey = 'meta')
138
    {
139 3
        $entities = [];
140 3
        foreach ($this->collection as $entity) {
141 3
            $entities[] = $entity->attributes();
142
        }
143
144 3
        $col = $entities;
145 3
        if ($collectionKey) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $collectionKey of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
146 3
            $col = [$collectionKey => $entities];
147
        }
148
149 3
        $met = [];
150 3
        if ($this->metaData) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->metaData of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
151 2
            $met = [$metaKey => $this->metaData];
152
        }
153
154 3
        return array_merge($col, $met);
155
    }
156
157
    /**
158
     * Function to convert the collection to json using
159
     * each collection elements attributes as an array then
160
     * encoding the array to json.
161
     *
162
     * @param string $collectionKey
163
     * @param string $metaKey
164
     *
165
     * @return array
166
     */
167 1
    public function toJson($collectionKey = null, $metaKey = 'meta')
168
    {
169 1
        return json_encode($this->toArray($collectionKey, $metaKey));
0 ignored issues
show
Bug Best Practice introduced by
The expression return json_encode($this...llectionKey, $metaKey)) returns the type string which is incompatible with the documented return type array.
Loading history...
170
    }
171
}//end class
172