Completed
Push — master ( 1f1432...de8229 )
by Jean
18:29 queued 09:40
created

scandir_r()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 16
rs 9.9666
cc 3
nc 3
nop 1
1
<?php
2
/**
3
 */ 
4
function scandir_r($directory) {
5
    // $files = array_slice(scandir($directory, SCANDIR_SORT_NONE), 2);
6
    $files = array_slice(scandir($directory), 2);
0 ignored issues
show
Bug introduced by
It seems like scandir($directory) can also be of type false; however, parameter $array of array_slice() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

6
    $files = array_slice(/** @scrutinizer ignore-type */ scandir($directory), 2);
Loading history...
7
8
    $map = [];
9
    foreach ($files as $file) {
10
        if (is_dir( $directory . '/' . $file)) {
11
            $submap = scandir_r($directory . '/' . $file);
12
            $map = array_merge($map, $submap);
13
        }
14
        else {
15
            $map[] = $directory . '/' . $file;
16
        }
17
    }
18
    
19
    return $map;
20
}
21
22
if (PHP_VERSION_ID >= 70000) {
23
    $root = 'src';
24
}
25
else {
26
    $root = 'src_5.6';
27
}
28
29
$map = scandir_r($root);
30
foreach ($map as &$map_entry) {
31
    $map_entry = preg_replace("/^src(_\d+\.\d+)?\//", '', $map_entry);
32
}
33
// var_export($map); exit;
34
35
/**
36
 * Dependency map has to be ordered to declare dependencies before
37
 * the code needing it.
38
 */
39
$sorted_map = [
40
  'ArrayAccessTrait.php',
41
  'FunctionCallTrait.php',
42
  'ExportTrait.php',
43
  'DeferredCallChain.php',
44
  'Exceptions/BadTargetClassException.php',
45
  'Exceptions/BadTargetInterfaceException.php',
46
  'Exceptions/BadTargetTypeException.php',
47
  'Exceptions/TargetAlreadyDefinedException.php',
48
  'Exceptions/UndefinedTargetClassException.php',
49
  'functions.php',
50
];
51
52
if ($missing = array_diff($sorted_map, $map)) {
53
    throw new \Exception(
54
        "Missing file in your classmap. Please add it manually to "
55
        . __FILE__ . "\n"
56
        . var_export($missing, true)
57
    );
58
}
59
60
foreach ($sorted_map as $filepath) {
61
    require_once($root . '/' . $filepath);
62
}
63