AddSubCommand::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * GitElephant - An abstraction layer for git written in PHP
5
 * Copyright (C) 2013  Matteo Giachino
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program.  If not, see [http://www.gnu.org/licenses/].
19
 */
20
21
namespace GitElephant\Command\Remote;
22
23
use GitElephant\Command\SubCommandCommand;
24
use GitElephant\Repository;
25
26
/**
27
 * Class AddRemoteCommand
28
 *
29
 * remote subcommand generator for add
30
 *
31
 * @package GitElephant\Objects
32
 * @author  David Neimeyer <[email protected]>
33
 */
34
35
class AddSubCommand extends SubCommandCommand
36
{
37
    public const GIT_REMOTE_ADD = 'add';
38
    public const GIT_REMOTE_ADD_OPTION_FETCH = '-f';
39
    public const GIT_REMOTE_ADD_OPTION_TAGS = '--tags';
40
    public const GIT_REMOTE_ADD_OPTION_NOTAGS = '--no-tags';
41
    public const GIT_REMOTE_ADD_OPTION_MIRROR = '--mirror';
42
    public const GIT_REMOTE_ADD_OPTION_SETHEAD = '-m';
43
    public const GIT_REMOTE_ADD_OPTION_TRACK = '-t';
44
45
    /**
46
     * constructor
47
     *
48
     * @param \GitElephant\Repository $repo The repository object this command
49
     *                                      will interact with
50
     */
51 8
    public function __construct(Repository $repo = null)
52
    {
53 8
        parent::__construct($repo);
54 8
    }
55
56
    /**
57
     * Valid options for remote command that require an associated value
58
     *
59
     * @return array Array of all value-required options
60
     */
61 8
    public function addCmdValueOptions(): array
62
    {
63
        return [
64 8
            self::GIT_REMOTE_ADD_OPTION_TRACK => self::GIT_REMOTE_ADD_OPTION_TRACK,
65 8
            self::GIT_REMOTE_ADD_OPTION_MIRROR => self::GIT_REMOTE_ADD_OPTION_MIRROR,
66 8
            self::GIT_REMOTE_ADD_OPTION_SETHEAD => self::GIT_REMOTE_ADD_OPTION_SETHEAD,
67
        ];
68
    }
69
70
    /**
71
     * switch only options for the add subcommand
72
     *
73
     * @return array
74
     */
75 8
    public function addCmdSwitchOptions(): array
76
    {
77
        return [
78 8
            self::GIT_REMOTE_ADD_OPTION_TAGS => self::GIT_REMOTE_ADD_OPTION_TAGS,
79 8
            self::GIT_REMOTE_ADD_OPTION_NOTAGS => self::GIT_REMOTE_ADD_OPTION_NOTAGS,
80 8
            self::GIT_REMOTE_ADD_OPTION_FETCH => self::GIT_REMOTE_ADD_OPTION_FETCH,
81
        ];
82
    }
83
84
    /**
85
     * build add sub command
86
     *
87
     * @param string $name    remote name
88
     * @param string $url     URL of remote
89
     * @param array  $options options for the add subcommand
90
     *
91
     * @return AddSubCommand
92
     */
93 8
    public function prepare($name, $url, $options = []): self
94
    {
95 8
        $options = $this->normalizeOptions(
96 8
            $options,
97 8
            $this->addCmdSwitchOptions(),
98 8
            $this->addCmdValueOptions()
99
        );
100
        
101 8
        $this->addCommandName(self::GIT_REMOTE_ADD);
102 8
        $this->addCommandSubject($name);
103 8
        $this->addCommandSubject($url);
104 8
        foreach ($options as $option) {
105 1
            $this->addCommandArgument($option);
106
        }
107
108 8
        return $this;
109
    }
110
}
111