Completed
Push — master ( be0de5...43298b )
by Damian
02:17
created

build.php ➔ findFiles()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 3
eloc 7
nc 3
nop 1
dl 0
loc 13
rs 9.4285
1
<?php
2
3
/*
4
 * This file is part of the Behat/SilverStripeExtension
5
 *
6
 * (c) Michał Ochman <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
$filename = 'silverstripe_extension.phar';
13
14
if (file_exists($filename)) {
15
    unlink($filename);
16
}
17
18
$phar = new \Phar($filename, 0, 'extension.phar');
19
$phar->setSignatureAlgorithm(\Phar::SHA1);
20
$phar->startBuffering();
21
22
foreach (findFiles('src') as $path) {
23
    $phar->addFromString($path, file_get_contents(__DIR__ . '/' . $path));
24
}
25
26
$phar->addFromString('init.php', file_get_contents(__DIR__ . '/init.php'));
27
28
$phar->setStub(<<<STUB
29
<?php
30
31
/*
32
 * This file is part of the SilverStripe-Behaviour-Testing-Framework
33
 *
34
 * (c) Michał Ochman <[email protected]>
35
 *
36
 * This source file is subject to the MIT license that is bundled
37
 * with this source code in the file LICENSE.
38
 */
39
40
Phar::mapPhar('extension.phar');
41
42
return require 'phar://extension.phar/init.php';
43
44
__HALT_COMPILER();
45
STUB
46
);
47
$phar->stopBuffering();
48
49
function findFiles($dir)
50
{
51
    $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::CHILD_FIRST);
52
53
    $files = array();
54
    foreach ($iterator as $path) {
55
        if ($path->isFile()) {
56
            $files[] = $path->getPath() . DIRECTORY_SEPARATOR . $path->getFilename();
57
        }
58
    }
59
60
    return $files;
61
}