Completed
Push — master ( ab52d1...9096b6 )
by Mahmoud
52:23
created

DownloadContainersCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 68
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B handle() 0 35 4
1
<?php
2
3
namespace App\Port\Command\Commands;
4
5
use App\Port\Console\Abstracts\ConsoleCommand;
6
use Symfony\Component\Process\Exception\ProcessFailedException;
7
use Symfony\Component\Process\Process;
8
9
/**
10
 * Class DownloadContainersCommand
11
 *
12
 * @author  Mahmoud Zalt  <[email protected]>
13
 */
14
class DownloadContainersCommand extends ConsoleCommand
15
{
16
17
    /**
18
     * The name and signature of the console command.
19
     *
20
     * @var string
21
     */
22
    protected $signature = "container:download {repository-name*}"; // {--skip-update=false}
23
24
    /**
25
     * The console command description.
26
     *
27
     * @var string
28
     */
29
    protected $description = "select existing container to download";
30
31
    /**
32
     * Create a new command instance.
33
     *
34
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
35
     */
36
    public function __construct()
37
    {
38
        parent::__construct();
39
    }
40
41
    /**
42
     * Execute the console command.
43
     *
44
     * @return mixed
45
     */
46
    public function handle()
47
    {
48
        $ContainersPath = "app/Containers";
49
50
        foreach ($this->argument("repository-name") as $repoName) {
0 ignored issues
show
Bug introduced by
The expression $this->argument('repository-name') of type string|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
51
            $repoName = ucfirst(strtolower($repoName));
52
53
            // TODO: find a way to validate the repo!
54
            $process = new Process("git clone [email protected]:Porto-SAP/" . $repoName . ".git " . $ContainersPath . "/" . $repoName);
55
            $process->run();
56
57
            if (!$process->isSuccessful()) {
58
                throw new ProcessFailedException($process);
59
            }
60
61
            echo "Downloading " . $repoName . " completed successfully.\n";
62
        }
63
64
        // TODO: add skip update option
65
66
//        if (!$this->option('skip-update')) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
67
68
            echo "Running 'Composer Update'..\n";
69
            $process = new Process("composer update");
70
            $process->run();
71
72
            if (!$process->isSuccessful()) {
73
                throw new ProcessFailedException($process);
74
            }
75
76
            echo $process->getOutput();
77
//        }
78
79
        echo "Congratulation :)\n";
80
    }
81
}
82