Test Setup Failed
Pull Request — master (#35)
by Scott
02:24
created

addDir()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 13
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 19
rs 9.4285
1
<?php
2
3
$pharName = 'diffFilter.phar';
4
$pharFile = getcwd() . '/diffFilter.phar';
5
6
if (file_exists($pharFile)) {
7
    unlink($pharFile);
8
}
9
10
$phar = new Phar($pharFile, 0, $pharName);
11
12
$phar->addFile('autoload.php');
13
$phar->addFile('bin/diffFilter');
14
15
16
$dirs = [
17
    'src',
18
    'vendor',
19
];
20
21
foreach($dirs as $dir) {
22
    addDir($dir, $phar);
23
}
24
25
$phar->setStub(
26
    "#!/usr/bin/env php
27
    <?php
28
    require 'phar://$pharName/src/Runners/generic.php';
29
    __HALT_COMPILER();"
30
);
31
32
function addDir($dir, $phar)
33
{
34
    $code = realpath(__DIR__ . "/$dir/");
35
    $codeLength = strlen($code);
36
    $directory = new RecursiveDirectoryIterator(
37
        $code,
38
        RecursiveDirectoryIterator::FOLLOW_SYMLINKS
39
    );
40
    $iterator = new RecursiveIteratorIterator(
41
        $directory,
42
        0,
43
        RecursiveIteratorIterator::CATCH_GET_CHILD
44
    );
45
46
    foreach ($iterator as $file) {
47
        $fullPath = $file->getPathname();
48
        $path = $dir . substr($fullPath, $codeLength);
49
        if (is_file($path)) {
50
            $phar->addFile($path);
51
        }
52
    }
53
}
54