SkeletonHelper::listSkeleton()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 12
rs 10
c 0
b 0
f 0
ccs 7
cts 7
cp 1
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
/*
4
 * This file is part of the core-bundle package.
5
 *
6
 * (c) 2019 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\CoreBundle\Helper;
13
14
use InvalidArgumentException;
15
use Symfony\Component\Finder\Finder;
16
17
/**
18
 * Skeleton helper.
19
 *
20
 * @author webeweb <https://github.com/webeweb>
21
 * @package WBW\Bundle\CoreBundle\Helper
22
 */
23
class SkeletonHelper {
24
25
    /**
26
     * Copy skeleton.
27
     *
28
     * @param string $src The source directory.
29
     * @param string $dst The destination directory.
30
     * @return bool[] Returns the assets.
31
     * @throws InvalidArgumentException Throws an invalid argument exception if the directory does not exist.
32
     */
33 10
    public static function copySkeleton(string $src, string $dst): array {
34
35 10
        $files = static::listSkeleton($src);
36
37 10
        $result = [];
38
39 10
        foreach ($files as $current) {
40
41 10
            $pathname = str_replace($src, $dst, dirname($current));
42 10
            if (false === file_exists($pathname)) {
43 10
                mkdir($pathname, 0755, true);
44
            }
45
46 10
            $filename = implode("/", [$pathname, basename($current)]);
47 10
            $result[] = copy($current, $filename);
48
        }
49
50 10
        return $result;
51
    }
52
53
    /**
54
     * List skeleton.
55
     *
56
     * @param string $directory The directory.
57
     * @return string[] Returns the skeletons.
58
     * @throws InvalidArgumentException Throws an invalid argument exception if the directory does not exist.
59
     */
60 30
    public static function listSkeleton(string $directory): array {
61
62 30
        $finder = new Finder();
63 30
        $finder->sortByName()->files()->in($directory);
64
65 20
        $files = [];
66
67 20
        foreach ($finder as $current) {
68 20
            $files[] = $current->getRealPath();
69
        }
70
71 20
        return $files;
72
    }
73
}
74