This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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
|
|||
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
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.. ![]() |
|||
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;
![]() |
|||
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;
![]() |
|||
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. ![]() |
|||
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;
![]() |
|||
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;
![]() |
|||
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. ![]() |
|||
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. ![]() 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. ![]() |
|||
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 |
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.