Passed
Pull Request — master (#87)
by
unknown
03:43
created

DebugBarAssetsCommand::installed()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 9
rs 10
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.8.0
13
 */
14
15
namespace Quantum\Console\Commands;
16
17
use Quantum\Libraries\Storage\FileSystem;
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 = 'install:debugbar';
32
33
    /**
34
     * Command description
35
     * @var string
36
     */
37
    protected $description = 'Publishes debugbar assets';
38
39
    /**
40
     * Command help text
41
     * @var string
42
     */
43
    protected $help = 'The command will publish debugbar assets';
44
45
    /**
46
     * Path to public debug bar resources
47
     * @var string 
48
     */
49
    private $publicDebugbarFolderPath = 'public/assets/DebugBar/Resources';
50
51
    /**
52
     * Path to vendor debug bar resources
53
     * @var string 
54
     */
55
    private $vendorDebugbarFolderPath = 'vendor/maximebf/debugbar/src/DebugBar/Resources';
56
57
    /**
58
     * Executes the command and publishes the debug bar assets
59
     */
60
    public function exec()
61
    {
62
        if (installed(assets_dir() . DS . 'DebugBar' . DS . 'Resources' . DS . 'debugbar.css')) {
63
            $this->error('The debuger already installed');
64
            return;
65
        }
66
67
        $this->recursive_copy($this->vendorDebugbarFolderPath, $this->publicDebugbarFolderPath);
68
69
        $this->info('Debugbar assets successfully published');
70
    }
71
72
    /**
73
     * Recursively copies the debug bar assets
74
     * @param string $src
75
     * @param string $dst
76
     * @throws \RuntimeException
77
     */
78
    private function recursive_copy(string $src, string $dst)
79
    {
80
        $fs = new FileSystem();
81
82
        $dir = opendir($src);
83
84
        if ($dst != $this->publicDebugbarFolderPath) {
85
            if ($fs->makeDirectory($dst, 777, true) === false) {
0 ignored issues
show
Bug introduced by
Are you sure the usage of $fs->makeDirectory($dst, 777, true) targeting Quantum\Libraries\Storag...System::makeDirectory() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
introduced by
The condition $fs->makeDirectory($dst, 777, true) === false is always true.
Loading history...
Unused Code introduced by
The call to Quantum\Libraries\Storag...System::makeDirectory() has too many arguments starting with 777. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

85
            if ($fs->/** @scrutinizer ignore-call */ makeDirectory($dst, 777, true) === false) {

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
86
                throw new \RuntimeException(t('exception.directory_cant_be_created', $dst));
87
            }
88
        }
89
90
        if (is_resource($dir)) {
91
            while (($file = readdir($dir))) {
92
                if (($file != '.') && ($file != '..')) {
93
                    if ($fs->isDirectory($src . '/' . $file)) {
94
                        $this->recursive_copy($src . '/' . $file, $dst . '/' . $file);
95
                    } else {
96
                        if ($file) {
97
                            copy($src . '/' . $file, $dst . '/' . $file);
98
                        }
99
                    }
100
                }
101
            }
102
103
            closedir($dir);
104
        }
105
    }
106
}
107