ManipulatesPackageFolder   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 15
c 1
b 0
f 0
dl 0
loc 45
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createPackageFolder() 0 15 3
A removePackageFolder() 0 12 3
1
<?php
2
3
namespace Blok\LaravelPackageGenerator\Commands\Traits;
4
5
use Blok\LaravelPackageGenerator\Exceptions\RuntimeException;
6
use Illuminate\Support\Facades\File;
7
8
trait ManipulatesPackageFolder
9
{
10
    /**
11
     * Create package folder.
12
     *
13
     * @param string $packagePath
14
     *
15
     * @throws RuntimeException
16
     */
17
    protected function createPackageFolder($packagePath)
18
    {
19
        $this->info('Create package folder.');
0 ignored issues
show
Bug introduced by
It seems like info() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

19
        $this->/** @scrutinizer ignore-call */ 
20
               info('Create package folder.');
Loading history...
20
21
        if (File::exists($packagePath)) {
22
            $this->info('Package folder already exists. Skipping.');
23
24
            return;
25
        }
26
27
        if (!File::makeDirectory($packagePath, 0755, true)) {
28
            throw new RuntimeException('Cannot create package folder');
29
        }
30
31
        $this->info('Package folder was successfully created.');
32
    }
33
34
    /**
35
     * Remove package folder.
36
     *
37
     * @param $packagePath
38
     *
39
     * @throws RuntimeException
40
     */
41
    protected function removePackageFolder($packagePath)
42
    {
43
        $this->info('Remove package folder.');
44
45
        if (File::exists($packagePath)) {
46
            if (!File::deleteDirectory($packagePath)) {
47
                throw new RuntimeException('Cannot remove package folder');
48
            }
49
50
            $this->info('Package folder was successfully removed.');
51
        } else {
52
            $this->info('Package folder does not exists. Skipping.');
53
        }
54
    }
55
}
56