Completed
Push — master ( 1c163b...8360e1 )
by Oliver
03:25
created

CopyService   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 38
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A perform() 0 10 1
A copyFiles() 0 14 2
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
        $shouldCopy = $this->command->confirm("Do you want to copy files from <comment>{$source}</comment> to <comment>{$dest}</comment>");
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 139 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
37
38
        if ($shouldCopy) {
39
            $this->filesystem->copyDirectory($source, $dest);
40
            $this->command->info('COPIED');
41
        } else {
42
            $this->command->info('NOT COPIED');
43
        }
44
    }
45
}