Issues (49)

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.

test/unit/Container/ContainerTest.php (7 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
namespace Graze\DataStructure\Container;
4
5
use ArrayAccess;
6
use PHPUnit_Framework_TestCase as TestCase;
7
use Serializable;
8
use Traversable;
9
10
class ContainerTest extends TestCase
11
{
12
    public function testInterface()
13
    {
14
        $cont = new Container();
15
16
        $this->assertInstanceOf(ContainerInterface::class, $cont);
17
        $this->assertInstanceOf(Serializable::class, $cont);
18
        $this->assertInstanceOf(ArrayAccess::class, $cont);
19
    }
20
21 View Code Duplication
    public function testConstructor()
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...
22
    {
23
        $params = ['foo' => 'a', 'bar' => 'b', 'baz' => 'c'];
24
        $cont = new Container($params);
25
26
        $this->assertEquals($params, $cont->getAll());
27
    }
28
29
    public function testAdd()
30
    {
31
        $cont = new Container(['foo' => 'a', 'bar' => 'b']);
32
        $result = $cont->add('baz', 'c');
33
34
        $this->assertEquals(['foo' => 'a', 'bar' => 'b', 'baz' => 'c'], $cont->getAll());
35
        $this->assertSame($cont, $result);
36
    }
37
38
    /**
39
     * @expectedException \Graze\DataStructure\Exception\RegisteredKeyException
40
     */
41
    public function testAddDuplicate()
42
    {
43
        $cont = new Container(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
44
45
        $cont->add('baz', 'd');
46
    }
47
48 View Code Duplication
    public function testForAll()
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
        $params = ['foo' => 'a', 'bar' => 'b', 'baz' => 'c'];
51
        $seen = [];
52
53
        $cont = new Container($params);
54
        $cont->forAll(function ($value, $key) use (&$seen) {
55
            $seen[$key] = $value;
56
        });
57
58
        $this->assertEquals($params, $seen);
59
    }
60
61
    public function testGet()
62
    {
63
        $cont = new Container(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
64
65
        $this->assertEquals('a', $cont->get('foo'));
66
    }
67
68
    public function testGetMissing()
69
    {
70
        $cont = new Container();
71
72
        $this->assertNull($cont->get('foo'));
73
    }
74
75
    public function testGetIterator()
76
    {
77
        $cont = new Container();
78
79
        $this->assertInstanceOf('Iterator', $cont->getIterator());
80
        $this->assertInstanceOf(Traversable::class, $cont);
81
    }
82
83
    public function testIteration()
84
    {
85
        $cont = new Container(['a' => 'b', 'c' => 'd']);
86
87
        foreach ($cont as $key => $value) {
88
            switch ($key) {
89
                case 'a':
90
                    $this->assertEquals('b', $value);
91
                    break;
92
                case 'c':
93
                    $this->assertEquals('d', $value);
94
                    break;
95
                default:
96
                    $this->fail('unknown key, expecting `a` or `c`');
97
                    break;
98
            }
99
        }
100
    }
101
102
    public function testHasIsTrue()
103
    {
104
        $cont = new Container(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
105
106
        $this->assertTrue($cont->has('foo'));
107
    }
108
109
    public function testHasIsFalse()
110
    {
111
        $cont = new Container(['FOO' => 'a', 'bar' => 'b', 'baz' => 'c']);
112
113
        $this->assertFalse($cont->has('foo'));
114
    }
115
116 View Code Duplication
    public function testRemove()
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...
117
    {
118
        $cont = new Container(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
119
        $result = $cont->remove('bar');
120
121
        $this->assertEquals(['foo' => 'a', 'baz' => 'c'], $cont->getAll());
122
        $this->assertSame($cont, $result);
123
    }
124
125 View Code Duplication
    public function testRemoveMissing()
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...
126
    {
127
        $cont = new Container(['foo' => 'a', 'bar' => 'b']);
128
        $result = $cont->remove('baz');
129
130
        $this->assertEquals(['foo' => 'a', 'bar' => 'b'], $cont->getAll());
131
        $this->assertSame($cont, $result);
132
    }
133
134
    public function testSet()
135
    {
136
        $cont = new Container(['foo' => 'a', 'bar' => 'b']);
137
        $result = $cont->set('baz', 'c');
138
139
        $this->assertEquals(['foo' => 'a', 'bar' => 'b', 'baz' => 'c'], $cont->getAll());
140
        $this->assertSame($cont, $result);
141
    }
142
143
    public function testSetDuplicate()
144
    {
145
        $cont = new Container(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
146
        $result = $cont->set('baz', 'd');
147
148
        $this->assertEquals(['foo' => 'a', 'bar' => 'b', 'baz' => 'd'], $cont->getAll());
149
        $this->assertSame($cont, $result);
150
    }
151
152 View Code Duplication
    public function testSerialize()
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...
153
    {
154
        $cont = new Container(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
155
156
        $this->assertEquals(
157
            'C:39:"Graze\DataStructure\Container\Container":60:{a:3:{s:3:"foo";s:1:"a";s:3:"bar";s:1:"b";s:3:"baz";s:1:"c";}}',
158
            serialize($cont)
159
        );
160
    }
161
162
    public function testUnserialize()
163
    {
164
        $cont = unserialize('C:39:"Graze\DataStructure\Container\Container":60:{a:3:{s:3:"foo";s:1:"a";s:3:"bar";s:1:"b";s:3:"baz";s:1:"c";}}');
165
166
        $this->assertEquals(['foo' => 'a', 'bar' => 'b', 'baz' => 'c'], $cont->getAll());
167
    }
168
169
    public function testArrayGet()
170
    {
171
        $cont = new Container(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
172
173
        $this->assertEquals('a', $cont['foo']);
174
    }
175
176 View Code Duplication
    public function testArraySet()
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...
177
    {
178
        $cont = new Container(['foo' => 'a', 'bar' => 'b']);
179
        $cont['baz'] = 'c';
180
181
        $this->assertEquals(['foo' => 'a', 'bar' => 'b', 'baz' => 'c'], $cont->getAll());
182
    }
183
184
    public function testArrayHasIsTrue()
185
    {
186
        $cont = new Container(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
187
188
        $this->assertTrue(isset($cont['foo']));
189
    }
190
191
    public function testArrayHasIsFalse()
192
    {
193
        $cont = new Container(['FOO' => 'a', 'bar' => 'b', 'baz' => 'c']);
194
195
        $this->assertFalse(isset($cont['foo']));
196
    }
197
198 View Code Duplication
    public function testArrayRemove()
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...
199
    {
200
        $cont = new Container(['foo' => 'a', 'bar' => 'b', 'baz' => 'c']);
201
        unset($cont['bar']);
202
203
        $this->assertEquals(['foo' => 'a', 'baz' => 'c'], $cont->getAll());
204
    }
205
206
    public function testArrayRemoveMissing()
207
    {
208
        $cont = new Container(['foo' => 'a', 'bar' => 'b']);
209
        unset($cont['baz']);
210
211
        $this->assertEquals(['foo' => 'a', 'bar' => 'b'], $cont->getAll());
212
    }
213
}
214