Completed
Pull Request — master (#586)
by Greg
03:26
created

CreateProject::target()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
namespace Robo\Task\Composer;
3
4
/**
5
 * Composer CreateProject
6
 *
7
 * ``` php
8
 * <?php
9
 * // simple execution
10
 * $this->taskComposerCreateProject()->source('foo/bar')->target('myBar')->run();
11
 * ?>
12
 * ```
13
 */
14
class CreateProject extends Base
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    protected $action = 'create-project';
20
21
    protected $source;
22
    protected $target = '';
23
    protected $version = '';
24
25
    /**
26
     * @return $this
27
     */
28
    public function source($source)
29
    {
30
        $this->source = $source;
31
        return $this;
32
    }
33
34
    /**
35
     * @return $this
36
     */
37
    public function target($target)
38
    {
39
        $this->target = $target;
40
        return $this;
41
    }
42
43
    /**
44
     * @return $this
45
     */
46
    public function version($version)
47
    {
48
        $this->version = $version;
49
        return $this;
50
    }
51
52
    public function keepVcs($keep = true)
53
    {
54
        if ($keep) {
55
            $this->option('--keep-vcs');
56
        }
57
        return $this;
58
    }
59
60
    public function noInstall($noInstall = true)
61
    {
62
        if ($noInstall) {
63
            $this->option('--no-install');
64
        }
65
        return $this;
66
    }
67
68
    /**
69
     * @return $this
70
     */
71
    public function repository($repository)
72
    {
73
        if (!empty($repository)) {
74
            $this->option('repository', $repository);
75
        }
76
        return $this;
77
    }
78
79
    /**
80
     * @return $this
81
     */
82
    public function stability($stability)
83
    {
84
        if (!empty($stability)) {
85
            $this->option('stability', $stability);
86
        }
87
        return $this;
88
    }
89
90
    public function buildCommand()
91
    {
92
        $this->arg($this->source);
93
        if (!empty($this->target)) {
94
            $this->arg($this->target);
95
        }
96
        if (!empty($this->version)) {
97
            $this->arg($this->version);
98
        }
99
100
        return parent::buildCommand();
101
    }
102
103
    /**
104
     * {@inheritdoc}
105
     */
106
    public function run()
107
    {
108
        $command = $this->getCommand();
109
        $this->printTaskInfo('Creating project: {command}', ['command' => $command]);
110
        return $this->executeCommand($command);
111
    }
112
}
113