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

CreateProject::source()   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 install($install = true)
61
    {
62
        if (!$install) {
63
            return $this->noInstall();
64
        }
65
        return $this;
66
    }
67
68
    public function noInstall()
69
    {
70
        $this->option('--no-install');
71
        return $this;
72
    }
73
74
    /**
75
     * @return $this
76
     */
77
    public function repository($repository)
78
    {
79
        $this->option('repository', $repository);
80
        return $this;
81
    }
82
83
    public function buildCommand()
84
    {
85
        $this->arg($this->source);
86
        $this->arg($this->target);
87
        $this->arg($this->version);
88
89
        return parent::buildCommand();
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95
    public function run()
96
    {
97
        $command = $this->getCommand();
98
        $this->printTaskInfo('Creating project: {command}', ['command' => $command]);
99
        return $this->executeCommand($command);
100
    }
101
}
102