Issues (3)

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/AbstractCollection.php (1 issue)

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
 * Copyright (c) Nate Brunette.
4
 * Distributed under the MIT License (http://opensource.org/licenses/MIT)
5
 */
6
7
namespace Tebru\Collection;
8
9
/**
10
 * Class AbstractCollection
11
 *
12
 * Provides a skeletal implementation of the [@see CollectionInterface]
13
 *
14
 * @author Nate Brunette <[email protected]>
15
 */
16
abstract class AbstractCollection implements CollectionInterface
17
{
18
    /**
19
     * Ensure all elements of a collection exists in this collection
20
     *
21
     * Return true if the collection has changed, and false if it hasn't
22
     *
23
     * @param CollectionInterface $collection
24
     * @return bool
25
     */
26
    public function addAll(CollectionInterface $collection): bool
27
    {
28
        return $this->addAllArray($collection->toArray());
29
    }
30
31
    /**
32
     * Ensure all elements of an array exists in this collection
33
     *
34
     * Return true if the collection has changed, and false if it hasn't
35
     *
36
     * @param array $collection
37
     * @return bool
38
     */
39
    public function addAllArray(array $collection): bool
40
    {
41
        $size = $this->count();
42
        foreach ($collection as $element) {
43
            $this->add($element);
44
        }
45
46
        return $size !== $this->count();
47
    }
48
49
    /**
50
     * Returns true if the collection contains all elements from another collection
51
     *
52
     * @param CollectionInterface $collection
53
     * @return bool
54
     */
55
    public function containsAll(CollectionInterface $collection): bool
56
    {
57
        return $this->containsAllArray($collection->toArray());
58
    }
59
60
    /**
61
     * Returns true if the collection contains all elements from an array
62
     *
63
     * @param array $collection
64
     * @return bool
65
     */
66
    public function containsAllArray(array $collection): bool
67
    {
68
        foreach ($collection as $element) {
69
            if (!$this->contains($element)) {
70
                return false;
71
            }
72
        }
73
74
        return true;
75
    }
76
77
    /**
78
     * Returns the size of the collection
79
     *
80
     * @return int
81
     */
82
    public function count(): int
83
    {
84
        return count($this->toArray());
85
    }
86
87
    /**
88
     * Returns true if the collection is empty
89
     *
90
     * @return bool
91
     */
92
    public function isEmpty(): bool
93
    {
94
        return 0 === $this->count();
95
    }
96
97
    /**
98
     * Remove all items in a collection from this collection
99
     *
100
     * Returns true if the collection was modified
101
     *
102
     * @param CollectionInterface $collection
103
     * @return bool
104
     */
105
    public function removeAll(CollectionInterface $collection): bool
106
    {
107
        return $this->removeAllArray($collection->toArray());
108
    }
109
110
    /**
111
     * Remove all items in an array from this collection
112
     *
113
     * Returns true if the collection was modified
114
     *
115
     * @param array $collection
116
     * @return bool
117
     */
118
    public function removeAllArray(array $collection): bool
119
    {
120
        $size = $this->count();
121
        foreach ($collection as $element) {
122
            $this->remove($element);
123
        }
124
125
        return $size !== $this->count();
126
    }
127
128
    /**
129
     * Remove all items from this collection that don't exist in specified collection
130
     *
131
     * Returns true if the collection was modified
132
     *
133
     * @param CollectionInterface $collection
134
     * @return bool
135
     */
136
    public function retainAll(CollectionInterface $collection): bool
137
    {
138
        return $this->retainAllArray($collection->toArray());
139
    }
140
141
    /**
142
     * Remove all items from this collection that don't exist in specified array
143
     *
144
     * Returns true if the collection was modified
145
     *
146
     * @param array $collection
147
     * @return bool
148
     */
149
    public function retainAllArray(array $collection): bool
150
    {
151
        $size = $this->count();
152
        foreach ($this as $element) {
153
            if (!in_array($element, $collection, true)) {
154
                $this->remove($element);
155
            }
156
        }
157
158
        return $size !== $this->count();
159
    }
160
161
    /**
162
     * Find the first element in collection
163
     *
164
     * The closure will get passed each element.  Returning true will end the
165
     * loop and return that element
166
     *
167
     * @param callable $find
168
     * @return mixed
169
     */
170
    public function find(callable $find)
171
    {
172
        foreach ($this as $element) {
173
            if (true === $find($element)) {
174
                return $element;
175
            }
176
        }
177
178
        return null;
179
    }
180
181
    /**
182
     * Use a closure to determine existence in the collection
183
     *
184
     * The closure will get passed each element.  Returning true from the
185
     * closure will return true from this method.
186
     *
187
     * @param callable $exists
188
     * @return bool
189
     */
190
    public function exists(callable $exists): bool
191
    {
192
        foreach ($this as $element) {
193
            if (true === $exists($element)) {
194
                return true;
195
            }
196
        }
197
198
        return false;
199
    }
200
201
    /**
202
     * Filter the collection using closure
203
     *
204
     * The closure will get passed each element.  Returning true from the
205
     * closure will include that element in the new collection.
206
     *
207
     * @param callable $filter
208
     * @return CollectionInterface
209
     */
210
    public function filter(callable $filter): CollectionInterface
211
    {
212
        return new static(array_filter($this->toArray(), $filter));
0 ignored issues
show
The call to AbstractCollection::__construct() has too many arguments starting with array_filter($this->toArray(), $filter).

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
213
    }
214
}
215