Completed
Push — master ( 5c40ca...712b76 )
by WEBEWEB
01:59
created

SkeletonHelper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 51
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A copySkeleton() 0 20 3
A listSkeleton() 0 13 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 Symfony\Component\Finder\Exception\DirectoryNotFoundException;
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
     */
32
    public static function copySkeleton($src, $dst) {
33
34
        $files = static::listSkeleton($src);
35
36
        $result = [];
37
38
        /** @var string $current */
39
        foreach ($files as $current) {
40
41
            $pathname = str_replace($src, $dst, dirname($current));
42
            if (false === file_exists($pathname)) {
43
                mkdir($pathname, 0755, true);
44
            }
45
46
            $filename = implode("/", [$pathname, basename($current)]);
47
            $result[] = copy($current, $filename);
48
        }
49
50
        return $result;
51
    }
52
53
    /**
54
     * List skeleton.
55
     *
56
     * @param string $directory The directory.
57
     * @return string[] Returns the skeletons.
58
     * @throws DirectoryNotFoundException Throws a directory not found exception if the directory does not exist.
59
     */
60
    public static function listSkeleton($directory) {
61
62
        $finder = new Finder();
63
        $finder->sortByName()->files()->in($directory);
64
65
        $files = [];
66
67
        foreach ($finder as $current) {
68
            $files[] = $current->getRealPath();
69
        }
70
71
        return $files;
72
    }
73
}
74