CopyService::copyFiles()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 0
cts 15
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 12
nc 2
nop 2
crap 6
1
<?php
2
3
namespace Zoutapps\Laravel\Backpack\Branding\Services;
4
5
use Illuminate\Filesystem\Filesystem;
6
use Zoutapps\Laravel\Backpack\Branding\Commands\BrandingCommand;
7
8
class CopyService
9
{
10
    private $command;
11
    private $filesystem;
12
    private $defaults;
0 ignored issues
show
Unused Code introduced by
The property $defaults is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
13
14
    public function __construct(BrandingCommand $command)
15
    {
16
        $this->command = $command;
17
        $this->filesystem = new Filesystem();
18
    }
19
20
    public function perform()
21
    {
22
        $copyDefinitions = collect($this->command->getDefaults('copy'));
23
24
        $this->command->info('Found <comment>' . $copyDefinitions->count() . '</comment> paths to copy');
25
26
        $copyDefinitions->each(function ($definition) {
27
            $this->copyFiles($definition['src'], $definition['dest']);
28
        });
29
    }
30
31
    private function copyFiles($src, $dest)
32
    {
33
        $source = realpath($this->command->defaultsPath.'/'.$src);
34
        $dest = base_path($dest);
35
36
        $this->command->line('Copy data:');
37
        $this->command->line('  source: <comment>'.$source.'</comment>');
38
        $this->command->line('  destination: <comment>'.$dest.'</comment>');
39
        $shouldCopy = $this->command->confirm("Do you want to copy files?");
40
41
        if ($shouldCopy) {
42
            $this->filesystem->copyDirectory($source, $dest);
43
            $this->command->info('COPIED');
44
        } else {
45
            $this->command->info('NOT COPIED');
46
        }
47
    }
48
}