Completed
Push — develop ( 5f7df1...9cb564 )
by Matteo
10s
created

FetchCommand::fetchCmdSwitchOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
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
21
namespace GitElephant\Command;
22
23
use \GitElephant\Objects\Branch;
24
use \GitElephant\Objects\Remote;
25
use \GitElephant\Repository;
26
27
/**
28
 * Class FetchCommand
29
 */
30
class FetchCommand extends BaseCommand
31
{
32
    const GIT_FETCH_COMMAND = 'fetch';
33
    const GIT_FETCH_OPTION_TAGS = '--tags';
34
35
    /**
36
     * constructor
37
     *
38
     * @param \GitElephant\Repository $repo The repository object this command 
39
     *                                      will interact with
40
     */
41 2
    public function __construct(Repository $repo = null)
42
    {
43 2
        parent::__construct($repo);
44 2
    }
45
46
    /**
47
     * @param Remote|string $remote
48
     * @param Branch|string $branch
49
     * @param array         $options
50
     *
51
     * @throws \RuntimeException
52
     * @return string
53
     */
54 2
    public function fetch($remote = null, $branch = null, Array $options = array())
0 ignored issues
show
Coding Style introduced by
As per coding-style, PHP keywords should be in lowercase; expected array, but found Array.
Loading history...
55
    {
56 2
        if ($remote instanceof Remote) {
57 1
            $remote = $remote->getName();
58 1
        }
59 2
        if ($branch instanceof Branch) {
60 1
            $branch = $branch->getName();
61 1
        }
62 2
        $normalizedOptions = $this->normalizeOptions($options, $this->fetchCmdSwitchOptions());
63
64 2
        $this->clearAll();
65 2
        $this->addCommandName(self::GIT_FETCH_COMMAND);
66
67 2
        foreach ($normalizedOptions as $value) {
68 2
            $this->addCommandArgument($value);
69 2
        }
70
71 2
        if (!is_null($remote)) {
72 1
            $this->addCommandSubject($remote);
73 1
        }
74 2
        if (!is_null($branch)) {
75 1
            $this->addCommandSubject2($branch);
76 1
        }
77
78 2
        return $this->getCommand();
79
    }
80
81
    /**
82
     * Valid options for remote command that do not require an associated value
83
     *
84
     * @return array Associative array mapping all non-value options and their respective normalized option
85
     */
86 2
    public function fetchCmdSwitchOptions()
87
    {
88
        return array(
89 2
            self::GIT_FETCH_OPTION_TAGS => self::GIT_FETCH_OPTION_TAGS,
90 2
        );
91
    }
92
}
93