GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( d364f9...6c3f28 )
by Albert
01:57
created

CopyToRemoteCommand::ignoredFile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Elimuswift\DbExporter\Commands;
4
5
use Config;
6
use Storage;
7
use Symfony\Component\Console\Input\InputOption;
8
9
class CopyToRemoteCommand extends GeneratorCommand
10
{
11
    protected $name = 'db-exporter:backup';
12
13
    protected $description = 'Command to copy the migrations and/or the seeds to a remote host.';
14
15
    protected $ignoredFiles = [
16
                               '..',
17
                               '.',
18
                               '.gitkeep',
19
                              ];
20
21
    protected $uploadedFiles;
22
23
    protected static $filesCount;
24
25
    public function __construct()
26
    {
27
        parent::__construct();
28
    }
29
30
//end __construct()
31
32
    public function fire()
33
    {
34
        $succes = $this->handleOptions();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $succes is correct as $this->handleOptions() (which targets Elimuswift\DbExporter\Co...ommand::handleOptions()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

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

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

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

Loading history...
Unused Code introduced by
$succes is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
35
        foreach ($this->uploadedFiles as $type => $files) {
36
            $this->line("\n");
37
            $this->info(ucfirst($type));
38
            foreach ($files as $file) {
39
                $this->sectionMessage($type, $file.' uploaded.');
40
            }
41
        }
42
43
        $disk = $this->getDiskName();
44
        $this->blockMessage('Success!', "Everything uploaded to $disk filesystem!");
45
    }
46
47
//end fire()
48
49
    protected function getOptions()
50
    {
51
        return [
52
                [
53
                 'migrations',
54
                 'm',
55
                 InputOption::VALUE_NONE,
56
                 'Upload the migrations to a storage.',
57
                 null,
58
                ],
59
                [
60
                 'seeds',
61
                 's',
62
                 InputOption::VALUE_NONE,
63
                 'Upload the seeds to the remote host.',
64
                 null,
65
                ],
66
               ];
67
    }
68
69
//end getOptions()
70
71
    protected function handleOptions()
72
    {
73
        $options = $this->option();
74
        foreach ($options as $key => $value) {
75
            if ($value) {
76
                $this->upload($key);
77
            }
78
        }
79
    }
80
81
    protected function upload($what)
82
    {
83
        $localPath = Config::get('db-exporter.export_path.'.$what);
84
        $dir = scandir($localPath);
85
        $remotePath = Config::get('db-exporter.remote.'.$what);
86
        $this->line("\n");
87
        $this->info(ucfirst($what));
88
        // Reset file coounter
89
        static::$filesCount = 0;
90
        // Prepare the progress bar
91
        array_walk($dir, function ($file) {
92
            if ($this->ignoredFile($file)) {
93
                return;
94
            }
95
            ++static::$filesCount;
96
        });
97
        $progress = $this->output->createProgressBar(static::$filesCount);
98
        foreach ($dir as $file) {
99
            if ($this->ignoredFile($file)) {
100
                $this->comment("---> ignoring $file ");
101
                continue;
102
            }
103
104
            // Capture the uploaded files for displaying later
105
            $this->uploadedFiles[$what][] = $remotePath.$file;
106
107
            // Copy the files
108
            Storage::disk($this->getDiskName())->put(
109
                $remotePath.$file,
110
                $localPath.'/'.$file
111
            );
112
            $progress->advance();
113
        }
114
115
        $progress->finish();
116
117
        return true;
118
    }
119
120
//end upload()
121
122
    protected function getDiskName()
123
    {
124
        // For now static from he config file.
125
        return Config::get('db-exporter.backup.disk');
126
    }
127
128
    /**
129
     * Determine if a file should be ignored.
130
     *
131
     * @param string $file filename
132
     *
133
     * @return bool
134
     **/
135
    protected function ignoredFile($file)
136
    {
137
        if (in_array($file, $this->ignoredFiles)) {
138
            return true;
139
        }
140
141
        return false;
142
    }
143
144
//end getDiskName()
145
}//end class
146