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/Autoload/LoaderTest.php (24 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\Autoload;
4
5
use Koch\Autoload\Loader;
6
7
/**
8
 * Interface and Class definition for testing
9
 * the autoload skipping, when "already loaded".
10
 */
11
interface ThisInterfaceExists
0 ignored issues
show
ThisInterfaceExists does not seem to conform to the naming convention (^[A-Z][a-zA-Z0-9]*Interface$).

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...
12
{
13
}
14
15
class ThisClassExists
0 ignored issues
show
Coding Style Compatibility introduced by
Each interface must be in a file by itself

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
16
{
17
}
18
19
class LoaderTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
20
{
21
    public $classMapFile = 'autoloader.classmap.php';
22
23
    public function setUp()
24
    {
25
        parent::setUp();
26
27
        // add Fixtures folder, only if not already on the include_path
28
        $path = realpath(__DIR__ . '/fixtures');
29
        if (strpos(get_include_path(), $path) === false) {
30
            set_include_path($path . PATH_SEPARATOR . get_include_path());
31
        }
32
33
        /*
34
         * The APC user cache needs a reset, so that the map is generated freshly each run.
35
         * APC is used by readAutoloadingMapApc() / writeAutoloadingMapApc().
36
         */
37
        self::apcClearCache();
38
39
        Loader::setClassMapFile($this->classMapFile);
40
    }
41
42
    public function tearDown()
43
    {
44
        self::apcClearCache();
45
    }
46
47
    public static function apcClearCache()
48
    {
49
        if (extension_loaded('apc') and ini_get('apc.enabled') and ini_get('apc.enable_cli')) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
50
            apc_clear_cache('user');
51
        }
52
    }
53
54
    /**
55
     * testMethodautoload().
56
     */
57
    public function testMethodautoload()
58
    {
59
        // workflow of autoloading
60
61
        // 1. existing class
62
        $this->assertFalse(Loader::autoload('ThisClassExists'));
63
        // 2. existing interface
64
        $this->assertFalse(Loader::autoload('ThisInterfaceExists'));
65
        // 3. existing trait
66
        if (PHP_VERSION_ID <= 50400) {
67
            $this->assertFalse(Loader::autoload('ClassADefinesTraitA'));
68
        }
69
        // PHP 5.4.6 Bug... trait_exists does not return anything (true|false|null).
0 ignored issues
show
Unused Code Comprehensibility introduced by
41% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
70
        // So a "cannot redeclare class TraitA" fatal error is thrown.
71
        //$this->assertFalse(Loader::autoload('ClassBDefinesTraitA'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
72
73
        // 1. autoloadExclusions()
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
74
        // 2. autoloadInclusions()
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
75
        // 3. autoloadByApcOrFileMap()
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
76
        // 4. autoloadIncludePath()
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
77
        // 5. autoloadTryPathsAndMap()
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
78
    }
79
80
    public function testMethodconstruct()
81
    {
82
        // unregister first (autoloader was registered during test setup)
83
        $r = spl_autoload_unregister(['Koch\Autoload\Loader', 'autoload']);
0 ignored issues
show
$r is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
84
85
        // registers autoloader via constructor
86
        new Loader();
87
88
         // test Koch Framework Autoloader is registered in the spl_autoloader_stack at first place
89
        $registered_autoloaders = spl_autoload_functions();
0 ignored issues
show
$registered_autoloaders 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...
90
91
        $this->assertTrue(is_string($registered_autoloaders[0][0]));
0 ignored issues
show
$registered_autoloaders 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...
92
        $this->assertFalse(is_object($registered_autoloaders[0][0]));
0 ignored issues
show
$registered_autoloaders 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...
93
94
        $this->assertEquals('Koch\Autoload\Loader', $registered_autoloaders[0][0]);
0 ignored issues
show
$registered_autoloaders 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...
95
        $this->assertEquals('autoload', $registered_autoloaders[0][1]);
0 ignored issues
show
$registered_autoloaders 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...
96
    }
97
98
    /**
99
     * testMethodautoloadExclusions().
100
     */
101
    public function testMethodautoloadExclusions()
102
    {
103
        // exclude "Smarty_Internal" classes
104
        $this->assertTrue(Loader::autoloadExclusions('Smarty_Internal_SomeClass'));
105
106
        // exclude "Doctrine" classes
107
        $this->assertTrue(Loader::autoloadExclusions('Doctrine_SomeClass'));
108
        $this->assertTrue(Loader::autoloadExclusions('Doctrine\SomeClass'));
109
110
        // but not, our own namespaced doctrine classes "Koch\Doctrine\"
111
        $this->assertFalse(Loader::autoloadExclusions('Koch\Doctrine\SomeClass'));
112
        $this->assertFalse(Loader::autoloadExclusions('Koch\Pagination\Adapter\Doctrine'));
113
114
        // exclude "Smarty" classes
115
        $this->assertTrue(Loader::autoloadExclusions('Smarty_'));
116
117
        // but not, our own smarty class "\Smarty"
118
        $this->assertFalse(Loader::autoloadExclusions('Koch\View\Renderer\Smarty'));
119
    }
120
121
    /**
122
     * testMethodautoloadInclusions().
123
     */
124
    public function testMethodautoloadInclusions()
125
    {
126
        // try to load an unknown class
127
        $this->assertFalse(Loader::autoloadInclusions('SomeUnknownClass'));
128
129
        // try to load "Application_Staging" class
130
        // no definitions atm
131
        #$this->assertTrue(Loader::autoloadInclusions('Application_Staging'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
132
    }
133
134
    /**
135
     * testMethodautoloadByApcOrFileMap.
136
     */
137
    public function testMethodautoloadByApcOrFileMap()
138
    {
139
        // try to load an unknown class
140
        $this->assertFalse(Loader::autoloadByApcOrFileMap('SomeUnknownClass'));
141
142
        Loader::addMapping('Captcha', realpath(__DIR__ . '/../../../framework/Koch/Captcha/Captcha.php'));
143
        $this->assertTrue(Loader::autoloadByApcOrFileMap('Captcha'));
144
    }
145
146
    /**
147
     * testMethodautoloadIncludePath().
148
     */
149
    public function testMethodautoloadIncludePath()
150
    {
151
        // try to load an unknown class
152
        $this->assertFalse(Loader::autoloadIncludePath('\Namespace\Library\SomeUnknownClass'));
153
154
        // set the include path to our fixtures directory, where a namespaced class exists
155
        $path = __DIR__ . '/fixtures/Application';
156
        set_include_path($path . PATH_SEPARATOR . get_include_path());
157
158
        // try to load existing namespaced class
159
        $this->assertTrue(Loader::autoloadIncludePath('NamespacedClass'));
160
    }
161
162 View Code Duplication
    public function testMethodwriteAutoloadingMapFile()
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...
163
    {
164
        if (is_file($this->classMapFile)) {
165
            unlink($this->classMapFile);
166
        }
167
168
        // file will be created
169
        $this->assertSame([], Loader::readAutoloadingMapFile());
170
        $this->assertTrue(is_file($this->classMapFile));
171
172
        $array = ['class' => 'file'];
173
        $this->assertTrue(Loader::writeAutoloadingMapFile($array));
174
        $this->assertSame($array, Loader::readAutoloadingMapFile());
175
    }
176
177 View Code Duplication
    public function testMethodreadAutoloadingMapFile()
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...
178
    {
179
        if (is_file($this->classMapFile)) {
180
            unlink($this->classMapFile);
181
        }
182
        // file will be created
183
        $this->assertSame([], Loader::readAutoloadingMapFile());
184
        $this->assertTrue(is_file($this->classMapFile));
185
186
        $array = ['class' => 'file'];
187
        $this->assertTrue(Loader::writeAutoloadingMapFile($array));
188
        $this->assertSame($array, Loader::readAutoloadingMapFile());
189
    }
190
191
    public function testMethodwriteAutoloadingMapApc()
192
    {
193
        if (!extension_loaded('apc')) {
194
            $this->markTestSkipped('This test requires the PHP extension "apc".');
195
        }
196
197
        $array = ['class' => 'file'];
198
        $this->assertTrue(Loader::writeAutoloadingMapApc($array));
199
        $this->assertSame($array, Loader::readAutoloadingMapApc());
200
    }
201
202
    public function testMethodreadAutoloadingMapApc()
203
    {
204
        if (!extension_loaded('apc')) {
205
            $this->markTestSkipped(' This test requires the PHP extension "apc".');
206
        }
207
208
        $this->assertSame(apc_fetch('KF_CLASSMAP'), Loader::readAutoloadingMapApc());
209
    }
210
211 View Code Duplication
    public function testMethodaddMapping()
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...
212
    {
213
        $class = 'addToMappingClass';
214
        $file  = realpath(__DIR__ . '/fixtures/notloaded/addToMapping.php');
215
216
        $this->assertTrue(Loader::addMapping($class, $file));
217
218
        // test if the entry was added to the autoloader class map array
219
        $map = Loader::getAutoloaderClassMap();
220
        // entry exists
221
        $this->assertTrue(true, array_key_exists($class, $map));
222
        // compare entries
223
        $this->assertEquals($map[$class], $file);
224
225
        // file not loaded, just mapped
226
        #$this->assertFalse(class_exists($class, false));
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
227
228
        // triggering autoload via class_exists
229
        // --- WARNING ---
230
        // The "Koch Framework Autoloader" needs to be registered BEFORE "Composers Autoloader".
231
        $this->assertTrue(class_exists($class, true));
232
    }
233
234 View Code Duplication
    public function testMethodincludeFileAndMap()
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...
235
    {
236
        $file  = realpath(__DIR__ . '/fixtures/includeFileAndMap.php');
237
        $class = 'includeFileAndMapClass';
238
239
        Loader::includeFileAndMap($file, $class);
240
241
        // test if the entry was added to the autoloader class map array
242
        $map = Loader::getAutoloaderClassMap();
243
244
        $this->assertTrue(true, array_key_exists($class, $map));
245
246
        $this->assertEquals($map[$class], $file);
247
248
        // file already loaded
249
        $this->assertTrue(class_exists($class, false));
250
    }
251
252
    public function testMethodincludeFile()
253
    {
254
        // a) include file
255
        $this->assertTrue(Loader::includeFile(__DIR__ . '/fixtures/ClassForRequireFile1.php'));
256
257
        // b) include class
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
258
        $this->assertTrue(Loader::includeFile(__DIR__ . '/fixtures/ClassForRequireFile2.php', 'ClassForRequireFile2'));
259
260
        // c) include class (second parameter), but class does not exist
261
        $this->assertFalse(Loader::includeFile('nonExistantFile.php'), 'ThisClassDoesNotExist');
262
263
        // d) file not found returns false
264
        $this->assertFalse(Loader::includeFile('nonExistantFile.php'));
265
    }
266
267
    public function testsetInclusionMap()
268
    {
269
        $classmap = ['class' => 'file'];
270
        Loader::setInclusionsClassMap($classmap);
271
        $this->assertEquals(Loader::$inclusionsClassmap, $classmap);
272
    }
273
}
274