InteractsWithGit   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 18
c 1
b 0
f 0
dl 0
loc 50
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A cloneRepo() 0 17 2
A initRepo() 0 15 2
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 InteractsWithGit
9
{
10
    /**
11
     * Clone repo.
12
     *
13
     * @param $url
14
     * @param $dest
15
     * @param $branch
16
     *
17
     * @throws RuntimeException
18
     */
19
    protected function cloneRepo($url, $dest, $branch)
20
    {
21
        $command = "git clone --branch=$branch $url $dest";
22
        $this->info("Run \"$command\".");
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

22
        $this->/** @scrutinizer ignore-call */ 
23
               info("Run \"$command\".");
Loading history...
23
24
        File::makeDirectory($dest, 0755, true);
25
26
        $output = [];
27
        exec($command, $output, $returnStatusCode);
28
29
        if ($returnStatusCode !== 0) {
30
            throw RuntimeException::commandExecutionFailed(
31
                $command, $returnStatusCode
32
            );
33
        }
34
35
        $this->info("\"$command\" was successfully ran.");
36
    }
37
38
    /**
39
     * Init git repo.
40
     *
41
     * @param string $repoPath
42
     */
43
    protected function initRepo($repoPath)
44
    {
45
        $command = "git init $repoPath";
46
        $this->info("Run \"$command\".");
47
48
        $output = [];
49
        exec($command, $output, $returnStatusCode);
50
51
        if ($returnStatusCode !== 0) {
52
            throw RuntimeException::commandExecutionFailed(
53
                $command, $returnStatusCode
54
            );
55
        }
56
57
        $this->info("\"$command\" was successfully ran.");
58
    }
59
}
60