Completed
Push — master ( f3da9e...84ee94 )
by arto
18:33
created

developmentAutoloader.php ➔ netBazzlineComponentRequirementDevelopmentAutoloader()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 38
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 26
nc 4
nop 1
dl 0
loc 38
rs 8.5806
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 8 and the first side effect is on line 47.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * @param string $className - the name of the class the autoloader should load
4
 * @return bool
5
 * @author stev leibelt <[email protected]>
6
 * @since 2013-06-25
7
 */
8
function netBazzlineComponentRequirementDevelopmentAutoloader($className)
9
{
10
    $namespace = 'Net\\Bazzline\\Component\\Requirement\\';
11
    $lengthOfNamespace = strlen($namespace);
12
    $expectedNamespace = substr($className, 0, $lengthOfNamespace);
13
14
    $isSupportedClassnameByNamespace = ($namespace == $expectedNamespace);
15
16
    if ($isSupportedClassnameByNamespace) {
17
        $classNameWithRemovedNamespace = str_replace($namespace, '', $className);
18
        $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $classNameWithRemovedNamespace) . '.php';
19
        $includePaths = array(
20
            realpath(__DIR__ . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR
21
        );
22
23
        foreach ($includePaths as $includePath) {
24
            $filePath = realpath($includePath . DIRECTORY_SEPARATOR . $fileName);
25
26
            if (file_exists($filePath)) {
27
                require $filePath;
28
29
                break;
30
            } else {
31
                echo var_export(
32
                        array(
33
                            'classname' => $className,
34
                            'filename' => $fileName,
35
                            'filepath' => $filePath,
36
                            'includedPath' => $includePath
37
                        ),
38
                        true
39
                    ) . PHP_EOL;
40
            }
41
        }
42
    } else {
43
        return false;
44
    }
45
}
46
47
spl_autoload_register('netBazzlineComponentRequirementDevelopmentAutoloader');
48