Passed
Pull Request — master (#25)
by Arman
03:02
created

DebugBarAssetsCommand::recursive_copy()   B

Complexity

Conditions 8
Paths 7

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 12
c 3
b 0
f 0
dl 0
loc 21
rs 8.4444
cc 8
nc 7
nop 2
1
<?php
2
3
/**
4
 * Quantum PHP Framework
5
 *
6
 * An open source software development framework for PHP
7
 *
8
 * @package Quantum
9
 * @author Arman Ag. <[email protected]>
10
 * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
11
 * @link http://quantum.softberg.org/
12
 * @since 2.0.0
13
 */
14
15
namespace Quantum\Console\Commands;
16
17
use Quantum\Exceptions\ExceptionMessages;
18
use Quantum\Console\QtCommand;
19
20
/**
21
 * Class DebugBarAssetsCommand
22
 * @package Quantum\Console\Commands
23
 */
24
class DebugBarAssetsCommand extends QtCommand
25
{
26
27
    /**
28
     * Command name
29
     * @var string
30
     */
31
    protected $name = 'core:debugbar';
32
33
    /**
34
     * Command description
35
     * @var string
36
     */
37
    protected $description = 'Publishing debugbar assets';
38
39
    /**
40
     * Command help text
41
     * @var string
42
     */
43
    protected $help = 'The command will published debugbar assets';
44
45
    /**
46
     * Executes the command and publishes the debugbar assets
47
     * @return mixed|void
48
     */
49
    public function exec()
50
    {
51
        $vendorDebugbarAssetsPath = 'vendor/maximebf/debugbar/src/DebugBar/Resources';
52
        $publicDebugbarPath = 'public/assets/DebugBar/Resources';
53
        $this->recursive_copy($vendorDebugbarAssetsPath, $publicDebugbarPath);
54
55
        $this->info('Debugbar assets successfully published');
56
    }
57
58
    /**
59
     * Recursively copies the debugbar assets
60
     * @param string $src
61
     * @param string $dst
62
     * @throws \RuntimeException
63
     */
64
    private function recursive_copy($src, $dst)
65
    {
66
        $dir = opendir($src);
67
68
        if (@mkdir($dst) === false) {
69
            throw new \RuntimeException(_message(ExceptionMessages::DIRECTORY_CANT_BE_CREATED, $dst));
70
        }
71
72
        if (is_resource($dir)) {
73
            while (($file = readdir($dir))) {
74
                if (($file != '.') && ($file != '..')) {
75
                    if (is_dir($src . '/' . $file)) {
76
                        $this->recursive_copy($src . '/' . $file, $dst . '/' . $file);
77
                    } else {
78
                        if ($file)
79
                            copy($src . '/' . $file, $dst . '/' . $file);
80
                    }
81
                }
82
            }
83
            
84
            closedir($dir);
85
        }
86
    }
87
88
}
89