InteractsWithGit::cloneRepo()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 17
rs 9.9666
1
<?php
2
3
namespace Cherrypulp\LaravelPackageGenerator\Commands\Traits;
4
5
use Illuminate\Support\Facades\File;
6
use Cherrypulp\LaravelPackageGenerator\Exceptions\RuntimeException;
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
     * @param string $repoPath
41
     */
42
    protected function initRepo($repoPath)
43
    {
44
        $command = "git init $repoPath";
45
        $this->info("Run \"$command\".");
46
47
        $output = [];
48
        exec($command, $output, $returnStatusCode);
49
50
        if ($returnStatusCode !== 0) {
51
            throw RuntimeException::commandExecutionFailed(
52
                $command, $returnStatusCode
53
            );
54
        }
55
56
        $this->info("\"$command\" was successfully ran.");
57
    }
58
}
59