Cancelled
Push — master ( 00a45e...787c73 )
by Oskar
02:12
created

autoloader.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
 * An example of a project-specific implementation.
4
 *
5
 * After registering this autoload function with SPL, the following line
6
 * would cause the function to attempt to load the \Foo\Bar\Baz\Qux class
7
 * from /path/to/project/src/Baz/Qux.php:
8
 *
9
 *      new \Foo\Bar\Baz\Qux;
10
 *
11
 * @param string $class The fully-qualified class name.
12
 * @return void
13
 */
14
spl_autoload_register(
15 View Code Duplication
    function ($class) {
0 ignored issues
show
This code seems to be duplicated across 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...
16
        // project-specific namespace prefix
17
        //$prefix = 'Foo\\Bar\\';
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...
18
        $prefix = 'Anax\\';
19
        // base directory for the namespace prefix
20
        $base_dir = __DIR__ . '/src/';
21
        // does the class use the namespace prefix?
22
        $len = strlen($prefix);
23
        if (strncmp($prefix, $class, $len) !== 0) {
24
            // no, move to the next registered autoloader
25
            return;
26
        }
27
        // get the relative class name
28
        $relative_class = substr($class, $len);
29
        // replace the namespace prefix with the base directory, replace namespace
30
        // separators with directory separators in the relative class name, append
31
        // with .php
32
        $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
33
        // if the file exists, require it
34
        if (file_exists($file)) {
35
            include $file;
36
        }
37
    }
38
);
39
40
41
// autoloader for 'Psr\'
42
spl_autoload_register(
43 View Code Duplication
    function ($class) {
0 ignored issues
show
This code seems to be duplicated across 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...
44
        // project-specific namespace prefix
45
        //$prefix = 'Foo\\Bar\\';
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...
46
        $prefix = 'Psr\\';
47
        // base directory for the namespace prefix
48
        $base_dir = __DIR__ . '/src/';
49
        // does the class use the namespace prefix?
50
        $len = strlen($prefix);
51
        if (strncmp($prefix, $class, $len) !== 0) {
52
            // no, move to the next registered autoloader
53
            return;
54
        }
55
        // get the relative class name
56
        $relative_class = substr($class, $len);
57
        // replace the namespace prefix with the base directory, replace namespace
58
        // separators with directory separators in the relative class name, append
59
        // with .php
60
        $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
61
        // if the file exists, require it
62
        if (file_exists($file)) {
63
            include $file;
64
        }
65
    }
66
);
67