Issues (38)

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/Unit/MetaTest.php (8 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
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace Symball\ReportBundle\Tests\Unit;
10
11
/* The base PHPUnit test class */
12
use PHPUnit\Framework\TestCase;
13
14
use Symball\ReportBundle\Service\Meta;
15
16
/* Extend the default PHPUnit test case */
17
class MetaTest extends TestCase
18
{
19
    /* Test that posts can be instantiated */
20
    public function testCreation()
21
    {
22
        /* Create a post */
23
        $meta = new Meta();
24
        /* Check that it is an object type */
25
        $this->assertEquals(true, is_object($meta));        
26
    }
27
    public function testOption() {
28
        $meta = new Meta();
29
        $meta->setOption('test_key', 'test_value');
30
        
31
        $this->assertEquals('test_value', $meta->getOption('test_key'));
32
        
33
        $meta->setOption('test_key', 'a new value');
34
        $this->assertEquals('a new value', $meta->getOption('test_key'));
35
    }
36
    public function testInvalidOptionKey() {
37
        $meta = new Meta();
38
        
39
        try {
40
            $meta->setOption(['invalid'], 'test_value');
0 ignored issues
show
array('invalid') is of type array<integer,string,{"0":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
41
        } catch (\Exception $ex) {
42
            // General exception
43
            $this->assertEquals(0, $ex->getCode());
44
            $this->assertEquals('Option key must be an integer or string. array given', $ex->getMessage());
45
        }        
46
    }
47
    
48
    public function testOptions() {
49
        $meta = new Meta();
50
        
51
        $meta->setOption('test_key', 'test_value');
52
        $this->assertEquals('test_value', $meta->getOption('test_key'));
53
        
54
        $meta->setOptions([
55
            'second_key' => 'a second value',
56
            'third_key' => 'a third value']);
57
        
58
        $this->assertEquals('a second value', $meta->getOption('second_key'));
59
        $this->assertEquals('test_value', $meta->getOption('test_key'));
60
        
61
        $meta->setOption('test_key', 'a new value for this option');
62
        $this->assertEquals('a new value for this option', $meta->getOption('test_key'));
63
                
64
    }
65
    
66
    public function testInvalidOptions() {
67
        $meta = new Meta();
68
        
69
        try {
70
            $meta->setOptions('invalid');
0 ignored issues
show
'invalid' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
71
        } catch (\Exception $ex) {
72
            // General exception
73
            $this->assertEquals(0, $ex->getCode());
74
            $this->assertEquals('Options must be an array. string given', $ex->getMessage());
75
        }        
76
    }
77
    
78
    public function testStringColumn() {
79
        $meta = new Meta();
80
        $meta->column('first_column');
81
        
82
        $this->assertEquals([
83
            'value' => '',
84
            'type' => 'string',
85
            'visible' => true,
86
            'title' => 'First Column'], $meta->columnInfo('first_column'));
87
    }
88
    
89 View Code Duplication
    public function testIntegerColumn() {
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...
90
        $meta = new Meta();
91
        $meta->column('first_column', 0);
92
        
93
        $this->assertEquals([
94
            'value' => 0,
95
            'type' => 'integer',
96
            'visible' => true,
97
            'title' => 'First Column'], $meta->columnInfo('first_column'));
98
        
99
        $this->assertEquals(1, $meta->columnCount());
100
    }
101
    
102
    public function testMultipleColumns() {
103
        $meta = new Meta();
104
        $meta->column('first_column');
105
        $meta->column('second_column');
106
        
107
        $this->assertEquals(2, $meta->columnCount());
108
    }
109 View Code Duplication
    public function testInvisibleColumn() {
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...
110
        $meta = new Meta();
111
        $meta->column('first_column', '', ['visible' => false]);
112
        
113
        $this->assertEquals([
114
            'value' => '',
115
            'type' => 'string',
116
            'visible' => false], $meta->columnInfo('first_column'));
117
        
118
        $this->assertEquals(1, $meta->columnCount());
119
    }
120
    public function testColumnWithOptions() {
121
        $meta = new Meta();
122
        $meta->column('first_column', '', ['extra_option' => true]);
123
        
124
        $this->assertEquals([
125
            'value' => '',
126
            'type' => 'string',
127
            'visible' => true,
128
            'title' => 'First Column',
129
            'extra_option' => true], $meta->columnInfo('first_column'));
130
        
131
        $this->assertEquals(1, $meta->columnCount());        
132
    }
133
    public function testAddDataPoint() {
134
        $meta = new Meta();
135
        $meta->addPoint('test');
136
        
137
        $this->assertEquals(1, $meta->dataCount());
138
        
139
        $meta->addPoint('another');
140
        $this->assertEquals(2, $meta->dataCount());
141
    }
142
    
143
    public function testSetPoint() {
144
        $meta = new Meta();
145
        $meta->setPoint('test');
146
        $this->assertEquals('test', $meta->getPointKey());        
147
        
148
    }
149
    
150 View Code Duplication
    public function testSetPointData() {
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...
151
        $meta = new Meta();
152
        $meta
153
        ->column('first_column')
154
        ->setPoint('test')
155
        ->set('first_column', 'test value');
156
        
157
        $this->assertEquals(['first_column' => [
158
            'value' => 'test value',
159
            'type' => 'string',
160
            'visible' => true,
161
            'title' => 'First Column'
162
        ]], $meta->getPoint());
163
    }
164
    
165 View Code Duplication
    public function testSetInvalidPointData() {
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...
166
        $meta = new Meta();
167
        
168
        try {
169
            $meta
170
            ->setPoint('test')
171
            ->set('first_column', 'test value');
172
        } catch (\Exception $ex) {
173
            // General exception
174
            $this->assertEquals(0, $ex->getCode());
175
            $this->assertEquals('first_column has not been defined', $ex->getMessage());
176
        }  
177
    }
178
    
179
    public function testRetrievePointDataValue() {
180
        $meta = new Meta();
181
        $meta
182
        ->column('first_column')
183
        ->setPoint('test')
184
        ->set('first_column', 'test value');
185
        
186
        $this->assertEquals('test value', $meta->getPointValue('first_column'));
187
    }
188
    
189
    public function testIncrementPointData() {
190
        $meta = new Meta();
191
        $meta
192
        ->column('first_column', 0)
193
        ->setPoint('test')
194
        ->increment('first_column', 1);
195
        
196
        $this->assertEquals(1, $meta->getPointValue('first_column'));
197
        
198
        $meta->increment('first_column', 100);
199
        $this->assertEquals(101, $meta->getPointValue('first_column'));
200
        
201
    }
202
    
203 View Code Duplication
    public function testIncrementStringPointdata() {
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...
204
        $meta = new Meta();
205
        
206
        try {
207
            $meta
208
            ->column('first_column')
209
            ->setPoint('test')
210
            ->increment('first_column', 100);
211
        } catch (\Exception $ex) {
212
            // General exception
213
            $this->assertEquals(0, $ex->getCode());
214
            $this->assertEquals('first_column is not a numeric column', $ex->getMessage());
215
        } 
216
    }
217
    
218 View Code Duplication
    public function testIncrementWithStringPointdata() {
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...
219
        $meta = new Meta();
220
        
221
        try {
222
            $meta
223
            ->column('first_column', 0)
224
            ->setPoint('test')
225
            ->increment('first_column', 'SOME_STRING');
226
        } catch (\Exception $ex) {
227
            // General exception
228
            $this->assertEquals(0, $ex->getCode());
229
            $this->assertEquals('Can only increment using a numeric value', $ex->getMessage());
230
        } 
231
    }
232
    
233
    public function testGetData() {
234
        $meta = new Meta();
235
        $meta
236
        ->column('first_column')
237
        ->setPoint('test')
238
        ->set('first_column', 'test value');
239
        
240
        $this->assertEquals([
241
            'test' => [
242
                'first_column' => [
243
                    'value' => 'test value',
244
                    'type' => 'string',
245
                    'visible' => true,
246
                    'title' => 'First Column']]], $meta->getDataSet());
247
        
248
        $meta
249
        ->setPoint('second_point')
250
        ->set('first_column', 'test value');
251
        
252
        $this->assertEquals([
253
            'test' => [
254
                'first_column' => [
255
                    'value' => 'test value',
256
                    'type' => 'string',
257
                    'visible' => true,
258
                    'title' => 'First Column']],
259
            'second_point' => [
260
                'first_column' => [
261
                    'value' => 'test value',
262
                    'type' => 'string',
263
                    'visible' => true,
264
                    'title' => 'First Column']]], $meta->getDataSet());
265
        
266
        
267
    }
268
    
269
    public function testClear() {
270
        $meta = new Meta();
271
        
272
        $meta->clear();        
273
        $this->assertEquals([], $meta->getDataSet());
274
        
275
        $meta
276
        ->column('first_column')
277
        ->setPoint('test')
278
        ->set('first_column', 'test value')
279
        ->setPoint('second_point')
280
        ->set('first_column', 'test value')
281
        ->clear();
282
        
283
        $this->assertEquals([
284
            'test' => [
285
                'first_column' => [
286
                    'value' => '',
287
                    'type' => 'string',
288
                    'visible' => true,
289
                    'title' => 'First Column']],
290
            'second_point' => [
291
                'first_column' => [
292
                    'value' => '',
293
                    'type' => 'string',
294
                    'visible' => true,
295
                    'title' => 'First Column']]], $meta->getDataSet());
296
        
297
        
298
       
299
    }
300
}
301