Issues (3098)

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/KochTest/Config/AbstractConfigTest.php (10 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 KochTest\Config;
4
5
use Koch\Config\Config;
6
use org\bovigo\vfs\vfsStream;
7
use org\bovigo\vfs\vfsStreamDirectory;
8
use org\bovigo\vfs\vfsStreamWrapper;
9
10
class AbstractConfigTest extends \PHPUnit_Framework_TestCase
11
{
12
    /**
13
     * @var AbstractConfig
14
     */
15
    protected $object;
16
17 View Code Duplication
    public function setUp()
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...
18
    {
19
        // we are using the config adapter native PHP here,
20
        // it's a class extending the abstract class
21
        // abstract classes cannot be instantiated
22
        $this->object = new Config();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Koch\Config\Config() of type object<Koch\Config\Config> is incompatible with the declared type object<KochTest\Config\AbstractConfig> of property $object.

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...
23
24
        vfsStreamWrapper::register();
25
        $this->configFileURL = vfsStream::url('root/test.config.php');
0 ignored issues
show
The property configFileURL does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
26
        $this->file          = vfsStream::newFile('test.config.php', 0777)->withContent($this->getConfigFileContent());
0 ignored issues
show
The property file does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
27
28
        $this->configFileURL2 = vfsStream::url('root/test2.config.php');
0 ignored issues
show
The property configFileURL2 does not seem to exist. Did you mean configFileURL?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
29
        $this->file2          = vfsStream::newFile('test2.config.php', 0777)->withContent('');
0 ignored issues
show
The property file2 does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
30
31
        $this->root = new vfsStreamDirectory('root');
0 ignored issues
show
The property root does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
32
        $this->root->addChild($this->file);
33
        $this->root->addChild($this->file2);
34
        vfsStreamWrapper::setRoot($this->root);
35
    }
36
37
    public function tearDown()
38
    {
39
        unset($this->object);
40
    }
41
42
    public function getConfigFileContent()
43
    {
44
        return <<<EOF
45
<?php
46
// Configuration File generated by Koch Framework.
47
return array(
48
  "oldKey" => "value"
49
);
50
EOF;
51
    }
52
53
    public function getConfigArray()
54
    {
55
        return [
56
            'oldKey' => 'value',
57
        ];
58
    }
59
60
    /**
61
     * @covers Koch\Config\Adapter\PHP::read
62
     * @covers Koch\Config\AbstractConfig::toArray
63
     */
64
    public function testToArray()
65
    {
66
        $array = $this->object->read($this->configFileURL);
67
        $this->assertEquals($this->getConfigArray(), $this->object->toArray());
68
69
       // unset, returns the array one last time
70
       $this->assertEquals($array, $this->object->toArray(true));
71
        $this->assertEquals([], $this->object->toArray());
72
    }
73
74
    /**
75
     * @covers Koch\Config\AbstractConfig::merge
76
     */
77
    public function testMerge()
78
    {
79
        // read old config
80
        $this->object->read($this->configFileURL);
81
82
        // merge new values
83
        $newConfig = ['newKey' => 'newKeyValue'];
84
        $this->object->merge($newConfig);
85
86
        $this->assertArrayHasKey('oldKey', $this->object->toArray());
87
        $this->assertArrayHasKey('newKey', $this->object->toArray());
88
    }
89
90
    /**
91
     * @covers Koch\Config\AbstractConfig::getConfigValue
92
     */
93
    public function testGetConfigValue()
94
    {
95
        // read old config
96
        $this->object->read($this->configFileURL);
97
98
        $this->assertEquals('value', $this->object->getConfigValue('oldKey'));
99
100
        // not existing key, returns null
101
        $this->assertEquals(null, $this->object->getConfigValue('notExistingKey'));
102
103
        $this->assertEquals('defaultValue', $this->object->getConfigValue('notExistingKey', 'defaultValue'));
104
105
        $this->assertEquals(
106
            'defaultValueTwo',
107
            $this->object->getConfigValue('notExistingKey', null, 'defaultValueTwo')
108
        );
109
110
        $this->assertEquals(
111
            'defaultValue',
112
            $this->object->getConfigValue('notExistingKey', 'defaultValue', 'defaultValueTwo')
113
        );
114
    }
115
116
    /**
117
     * @covers Koch\Config\AbstractConfig::__get
118
     */
119
    public function test__get()
0 ignored issues
show
function test__get() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
120
    {
121
        // read old config
122
        $this->object->read($this->configFileURL);
123
        $this->assertEquals('value', $this->object->oldKey);
124
125
        $this->assertNull($this->object->notExistingKey);
126
    }
127
128
    /**
129
     * @covers Koch\Config\AbstractConfig::__set
130
     * @covers Koch\Config\AbstractConfig::__isset
131
     * @covers Koch\Config\AbstractConfig::__unset
132
     */
133 View Code Duplication
    public function test__set()
0 ignored issues
show
function test__set() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
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...
134
    {
135
        // __set
136
        $this->object->newKey = 'someValue';
137
        $this->assertEquals('someValue', $this->object->newKey);
138
139
        // __isset
140
        $this->assertTrue(isset($this->object->newKey));
141
142
        // __unset
143
        unset($this->object->newKey);
144
        $this->assertFalse(isset($this->object->newKey));
145
    }
146
147
    /**
148
     * @covers Koch\Config\AbstractConfig::offsetExists
149
     */
150
    public function testOffsetExists()
151
    {
152
        $this->object->newKey = 'someValue';
153
154
        $this->assertFalse(empty($this->object['newKey']));
155
    }
156
157
    /**
158
     * @covers Koch\Config\AbstractConfig::offsetGet
159
     */
160
    public function testOffsetGet()
161
    {
162
        $this->object->newKey = 'someValue';
163
164
        $this->assertEquals('someValue', $this->object['newKey']);
165
    }
166
167
    /**
168
     * @covers Koch\Config\AbstractConfig::offsetSet
169
     */
170
    public function testOffsetSet()
171
    {
172
        $this->object['newKey'] = 'someValue';
173
        $this->assertEquals('someValue', $this->object['newKey']);
174
    }
175
176
    /**
177
     * @covers Koch\Config\AbstractConfig::offsetUnset
178
     *
179
     * @todo   Implement testOffsetUnset().
180
     */
181
    public function testOffsetUnset()
182
    {
183
        unset($this->object['newKey']);
184
185
        $this->assertFalse(isset($this->object->newKey));
186
    }
187
}
188