CreateProject   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 133
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 1

Importance

Changes 0
Metric Value
wmc 15
lcom 3
cbo 1
dl 0
loc 133
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A source() 0 5 1
A target() 0 5 1
A version() 0 5 1
A keepVcs() 0 7 2
A noInstall() 0 7 2
A repository() 0 7 2
A stability() 0 7 2
A buildCommand() 0 12 3
A run() 0 6 1
1
<?php
2
3
namespace Robo\Task\Composer;
4
5
/**
6
 * Composer CreateProject
7
 *
8
 * ``` php
9
 * <?php
10
 * // simple execution
11
 * $this->taskComposerCreateProject()->source('foo/bar')->target('myBar')->run();
12
 * ?>
13
 * ```
14
 */
15
class CreateProject extends Base
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20
    protected $action = 'create-project';
21
22
    /**
23
     * @var
24
     */
25
    protected $source;
26
27
    /**
28
     * @var string
29
     */
30
    protected $target = '';
31
32
    /**
33
     * @var string
34
     */
35
    protected $version = '';
36
37
    /**
38
     * @param string $source
39
     *
40
     * @return $this
41
     */
42
    public function source($source)
43
    {
44
        $this->source = $source;
45
        return $this;
46
    }
47
48
    /**
49
     * @param string $target
50
     *
51
     * @return $this
52
     */
53
    public function target($target)
54
    {
55
        $this->target = $target;
56
        return $this;
57
    }
58
59
    /**
60
     * @param string $version
61
     *
62
     * @return $this
63
     */
64
    public function version($version)
65
    {
66
        $this->version = $version;
67
        return $this;
68
    }
69
70
    /**
71
     * @param bool $keep
72
     *
73
     * @return $this
74
     */
75
    public function keepVcs($keep = true)
76
    {
77
        if ($keep) {
78
            $this->option('--keep-vcs');
79
        }
80
        return $this;
81
    }
82
83
    /**
84
     * @param bool $noInstall
85
     *
86
     * @return $this
87
     */
88
    public function noInstall($noInstall = true)
89
    {
90
        if ($noInstall) {
91
            $this->option('--no-install');
92
        }
93
        return $this;
94
    }
95
96
    /**
97
     * @param string $repository
98
     *
99
     * @return $this
100
     */
101
    public function repository($repository)
102
    {
103
        if (!empty($repository)) {
104
            $this->option('repository', $repository);
105
        }
106
        return $this;
107
    }
108
109
    /**
110
     * @param string $stability
111
     *
112
     * @return $this
113
     */
114
    public function stability($stability)
115
    {
116
        if (!empty($stability)) {
117
            $this->option('stability', $stability);
118
        }
119
        return $this;
120
    }
121
122
    /**
123
     * {@inheritdoc}
124
     */
125
    public function buildCommand()
126
    {
127
        $this->arg($this->source);
128
        if (!empty($this->target)) {
129
            $this->arg($this->target);
130
        }
131
        if (!empty($this->version)) {
132
            $this->arg($this->version);
133
        }
134
135
        return parent::buildCommand();
136
    }
137
138
    /**
139
     * {@inheritdoc}
140
     */
141
    public function run()
142
    {
143
        $command = $this->getCommand();
144
        $this->printTaskInfo('Creating project: {command}', ['command' => $command]);
145
        return $this->executeCommand($command);
146
    }
147
}
148