Issues (29)

Security Analysis    not enabled

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/JSONTextBasicTest.php (4 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
 * @package silverstripe-jsontext
5
 * @subpackage fields
6
 * @author Russell Michell <[email protected]>
7
 * @todo Add 'object' fixture to each
8
 */
9
10
use PhpTek\JSONText\ORM\FieldType\JSONText;
11
use SilverStripe\Dev\SapphireTest;
12
use SilverStripe\ORM\FieldType\DBVarchar;
13
14
class JSONTextBasicTest extends SapphireTest
15
{
16
    /**
17
     * @var array
18
     */
19
    protected $fixtures = [
20
        'array'     => 'fixtures/json/array.json',
21
        'object'    => 'fixtures/json/object.json'
22
    ];
23
24
    /**
25
     * @var \JSONText\ORM\FieldType\JSONText
26
     */
27
    protected $sut;
28
29
    /**
30
     * JSONTextTest constructor.
31
     *
32
     * Modifies fixtures property to be able to run on PHP <5.6 without use of constant in class property which 5.6+ allows
33
     */
34 View Code Duplication
    public function __construct()
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...
35
    {
36
        foreach($this->fixtures as $name => $path) {
37
            $this->fixtures[$name] = realpath(__DIR__) . '/' . $path;
38
        }
39
        
40
        parent::__construct();
41
    }
42
43
    /**
44
     * Setup the System Under Test for this test suite.
45
     */
46
    public function setUp()
47
    {
48
        parent::setUp();
49
50
        $this->sut = JSONText::create('MyJSON');
0 ignored issues
show
Documentation Bug introduced by
It seems like \PhpTek\JSONText\ORM\Fie...NText::create('MyJSON') of type object<PhpTek\JSONText\ORM\FieldType\JSONText> is incompatible with the declared type object<JSONText\ORM\FieldType\JSONText> of property $sut.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
51
    }
52
53
    public function testGetValueAsJSONStore()
54
    {
55
        $field = $this->sut;
56
57
        $field->setValue('');
58
        $this->assertEquals([], $field->getStoreAsArray());
59
    }
60
61 View Code Duplication
    public function testFirst()
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...
62
    {
63
        $field = $this->sut;
64
65
        // Test: Source data is simple JSON array
66
        // Return type: Array
67
        $field->setReturnType('array');
68
        $field->setValue($this->getFixture('array'));
69
        $this->assertInternalType('array', $field->first());
70
        $this->assertCount(1, $field->first());
71
        $this->assertEquals([0 => 'great wall'], $field->first());
72
73
        // Test: Source data is simple JSON array
74
        // Return type: JSON
75
        $field->setReturnType('json');
76
        $field->setValue($this->getFixture('array'));
77
        $this->assertInternalType('string', $field->first());
78
        $this->assertEquals('["great wall"]', $field->first());
79
80
        // Test: Source data is simple JSON array
81
        // Return type: SilverStripe
82
        $field->setReturnType('silverstripe');
83
        $field->setValue($this->getFixture('array'));
84
        $this->assertInternalType('array', $field->first());
85
        $this->assertInstanceOf('\SilverStripe\ORM\FieldType\DBVarchar', $field->first()[0]);
86
        $this->assertEquals('great wall', $field->first()[0]->getValue());
87
88
        // Test: Empty
89
        $field->setReturnType('array');
90
        $field->setValue('');
91
        $this->assertInternalType('array', $field->first());
92
        $this->assertCount(0, $field->first());
93
    }
94
95 View Code Duplication
    public function testLast()
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...
96
    {
97
        $field = $this->sut;
98
99
        // Test: Source data is simple JSON array
100
        // Return type: Array
101
        $field->setReturnType('array');
102
        $field->setValue($this->getFixture('array'));
103
        $this->assertInternalType('array', $field->last());
104
        $this->assertCount(1, $field->last());
105
        $this->assertEquals([6 => 33.3333], $field->last());
106
107
        // Test: Source data is simple JSON array
108
        // Return type: JSON
109
        $field->setReturnType('json');
110
        $field->setValue($this->getFixture('array'));
111
        $this->assertInternalType('string', $field->last());
112
        $this->assertEquals('{"6":33.3333}', $field->last());
113
114
        // Test: Source data is simple JSON array
115
        // Return type: SilverStripe
116
        $field->setReturnType('silverstripe');
117
        $field->setValue($this->getFixture('array'));
118
        $this->assertInternalType('array', $field->last());
119
        $this->assertInstanceOf('\SilverStripe\ORM\FieldType\DBFloat', $field->last()[6]);
120
        $this->assertEquals(33.3333, $field->last()[6]->getValue());
121
122
        // Test: Empty
123
        $field->setReturnType('array');
124
        $field->setValue('');
125
        $this->assertInternalType('array', $field->last());
126
        $this->assertCount(0, $field->last());
127
    }
128
129
    public function testNth()
130
    {
131
        $field = $this->sut;
132
133
        // Test: Source data is simple JSON array
134
        // Return type: Array
135
        $field->setReturnType('array');
136
        $field->setValue($this->getFixture('array'));
137
        $this->assertInternalType('array', $field->nth(1));
138
        $this->assertCount(1, $field->nth(1));
139
        $this->assertEquals([1 => true], $field->nth(1));
140
141
        // Test: Source data is simple JSON array
142
        // Return type: JSON
143
        $field->setReturnType('json');
144
        $field->setValue($this->getFixture('array'));
145
        $this->assertInternalType('string', $field->nth(1));
146
        $this->assertEquals('{"1":true}', $field->nth(1));
147
148
        // Test: Source data is simple JSON array
149
        // Return type: SilverStripe
150
        $field->setReturnType('silverstripe');
151
        $field->setValue($this->getFixture('array'));
152
        $this->assertInternalType('array', $field->nth(1));
153
        $this->assertInstanceOf('\SilverStripe\ORM\FieldType\DBBoolean', $field->nth(1)[1]);
154
        $this->assertEquals(true, $field->nth(1)[1]->getValue());
155
156
        // Test: Empty
157
        $field->setReturnType('array');
158
        $field->setValue('');
159
        $this->assertInternalType('array', $field->nth(1));
160
        $this->assertCount(0, $field->nth(1));
161
    }
162
163
    /**
164
     * Get the contents of a fixture
165
     *
166
     * @param string $fixture
167
     * @return string
168
     */
169
    private function getFixture($fixture)
170
    {
171
        $files = $this->fixtures;
172
        return file_get_contents($files[$fixture]);
173
    }
174
175
}
176