Completed
Push — master ( ebff66...d47983 )
by Markus
06:38 queued 02:43
created

autoloader.php (1 issue)

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 View Code Duplication
spl_autoload_register(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...
15
    // project-specific namespace prefix
16
    //$prefix = 'Foo\\Bar\\';
17
    $prefix = 'donami\\';
18
    // base directory for the namespace prefix
19
    $base_dir = __DIR__ . '/src/';
20
    // does the class use the namespace prefix?
21
    $len = strlen($prefix);
22
    if (strncmp($prefix, $class, $len) !== 0) {
23
        // no, move to the next registered autoloader
24
        return;
25
    }
26
    // get the relative class name
27
    $relative_class = substr($class, $len);
28
    // replace the namespace prefix with the base directory, replace namespace
29
    // separators with directory separators in the relative class name, append
30
    // with .php
31
    $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
32
    // if the file exists, require it
33
    if (file_exists($file)) {
34
        require $file;
35
    }
36
});
37