Issues (88)

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.

Tests/Asserters/CollectionAsserter.php (5 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 Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Cubiche\Core\Collections\Tests\Asserters;
13
14
use Cubiche\Core\Collections\CollectionInterface;
15
use Cubiche\Core\Comparable\Comparator;
16
use Cubiche\Core\Comparable\ComparatorInterface;
17
use Cubiche\Core\Specification\SpecificationInterface;
18
use mageekguy\atoum\asserters\phpObject as ObjectAsserter;
19
use mageekguy\atoum\exceptions\logic as LogicException;
20
21
/**
22
 * CollectionAsserter class.
23
 *
24
 * @author Ivannis Suárez Jerez <[email protected]>
25
 */
26
class CollectionAsserter extends ObjectAsserter
27
{
28
    /**
29
     * @var bool
30
     */
31
    protected $assertAll;
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function __get($asserter)
37
    {
38
        switch (strtolower($asserter)) {
39
            case 'size':
40
                return $this->size();
41
            case 'isempty':
42
                return $this->isEmpty();
43
            case 'isnotempty':
44
                return $this->isNotEmpty();
45
            case 'hasallelements':
46
                return $this->hasAllElements();
47
            case 'hasnoelements':
48
                return $this->hasNoElements();
49
            case 'issorted':
50
                return $this->isSorted();
51
            case 'isnotsorted':
52
                return $this->isNotSorted();
53
            default:
54
                return parent::__get($asserter);
55
        }
56
    }
57
58
    /**
59
     * @return \mageekguy\atoum\stubs\asserters\integer
60
     */
61
    public function size()
62
    {
63
        return $this->generator->__call(
64
            'integer',
65
            array($this->valueAsCollection()->count())
66
        );
67
    }
68
69
    /**
70
     * @param string $failMessage
71
     *
72
     * @return $this
73
     */
74 View Code Duplication
    public function isEmpty($failMessage = null)
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...
75
    {
76
        if (($actual = $this->valueAsCollection()->isEmpty()) === true) {
77
            $this->pass();
78
        } else {
79
            $this->fail($failMessage ?: $this->getLocale()->_('%s is not empty', $this, $actual));
80
        }
81
82
        return $this;
83
    }
84
85
    /**
86
     * @param string $failMessage
87
     *
88
     * @return $this
89
     */
90
    public function isNotEmpty($failMessage = null)
91
    {
92
        if (!$this->valueAsCollection()->isEmpty()) {
93
            $this->pass();
94
        } else {
95
            $this->fail($failMessage ?: $this->_('%s is empty', $this));
96
        }
97
98
        return $this;
99
    }
100
101
    /**
102
     * @return $this
103
     */
104
    public function hasAllElements()
105
    {
106
        $this->assertAll = true;
107
108
        return $this;
109
    }
110
111
    /**
112
     * @return $this
113
     */
114
    public function hasNoElements()
115
    {
116
        $this->assertAll = false;
117
118
        return $this;
119
    }
120
121
    /**
122
     * {@inheritdoc}
123
     */
124
    public function setWith($value, $checkType = true)
125
    {
126
        parent::setWith($value, $checkType);
127
128
        if ($checkType === true) {
129
            if ($this->value instanceof CollectionInterface) {
130
                $this->pass();
131
            } else {
132
                $this->fail($this->getLocale()->_('%s is not a collection', $this));
133
            }
134
        }
135
136
        return $this;
137
    }
138
139
    /**
140
     * @param SpecificationInterface $criteria
141
     *
142
     * @return $this
143
     */
144
    public function thatMatchToCriteria(SpecificationInterface $criteria)
145
    {
146
        $collection = $this->valueAsCollection();
147
        foreach ($collection as $item) {
148
            if (!$this->checkMatchResult($criteria->evaluate($item))) {
149
                return $this;
150
            }
151
        }
152
153
        $this->pass();
154
155
        return $this;
156
    }
157
158
    /**
159
     * @param bool $result
160
     *
161
     * @return bool
162
     */
163
    private function checkMatchResult($result)
164
    {
165 View Code Duplication
        if ($result === true && $this->assertAll === false) {
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...
166
            $this->fail($this->_('At least one items that match with the given criteria'));
167
168
            return false;
169
        }
170 View Code Duplication
        if ($result === false && $this->assertAll === true) {
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...
171
            $this->fail($this->_('At least one items that not match with the given criteria'));
172
173
            return false;
174
        }
175
176
        return true;
177
    }
178
179
    /**
180
     * @return $this
181
     */
182
    public function isSorted()
183
    {
184
        return $this->isSortedUsing(new Comparator());
185
    }
186
187
    /**
188
     * @param ComparatorInterface $comparator
189
     *
190
     * @return $this
191
     */
192 View Code Duplication
    public function isSortedUsing(ComparatorInterface $comparator)
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...
193
    {
194
        list($item1, $item2) = $this->checkIsSorted($comparator);
195
        if ($item1 !== null && $item2 !== null) {
196
            $this->fail(
197
                $this->_("There are items [%s, %s] that aren't ordered in the given collection", $item1, $item2)
198
            );
199
        } else {
200
            $this->pass();
201
        }
202
203
        return $this;
204
    }
205
206
    /**
207
     * @return $this
208
     */
209
    public function isNotSorted()
210
    {
211
        return $this->isNotSortedUsing(new Comparator());
212
    }
213
214
    /**
215
     * @param ComparatorInterface $comparator
216
     *
217
     * @return $this
218
     */
219 View Code Duplication
    public function isNotSortedUsing(ComparatorInterface $comparator)
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...
220
    {
221
        list($item1, $item2) = $this->checkIsSorted($comparator);
222
        if ($item1 !== null && $item2 !== null) {
223
            $this->fail($this->_('The given collection is sorted'));
224
        } else {
225
            $this->pass();
226
        }
227
228
        return $this;
229
    }
230
231
    /**
232
     * @param ComparatorInterface $comparator
233
     *
234
     * @return array
235
     */
236
    private function checkIsSorted(ComparatorInterface $comparator)
237
    {
238
        $collection = $this->valueAsCollection();
239
        $last = null;
240
        foreach ($collection as $item) {
241
            if ($last !== null && $comparator->compare($last, $item) > 0) {
242
                return array($last, $item);
243
            }
244
        }
245
246
        return array(null, null);
247
    }
248
249
    /**
250
     * {@inheritdoc}
251
     */
252
    protected function valueIsSet($message = 'Collection is undefined')
253
    {
254
        return parent::valueIsSet($message);
255
    }
256
257
    /**
258
     * @throws LogicException
259
     *
260
     * @return \Cubiche\Core\Collections\CollectionInterface
261
     */
262
    protected function valueAsCollection()
263
    {
264
        $value = $this->valueIsSet()->getValue();
265
        if ($value instanceof CollectionInterface) {
266
            return $value;
267
        }
268
269
        throw new LogicException('Collection is undefined');
270
    }
271
}
272