Completed
Pull Request — develop (#119)
by
unknown
03:16
created

AddSubCommand::addCmdSwitchOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

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