build.php ➔ findFiles()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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