Completed
Pull Request — develop (#100)
by
unknown
03:44
created

ShowSubCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 4
c 3
b 0
f 1
lcom 1
cbo 1
dl 0
loc 46
ccs 12
cts 12
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A prepare() 0 19 3
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 ShowRemoteCommand
27
 *
28
 * remote subcommand generator for show
29
 *
30
 * @package GitElephant\Objects
31
 * @author  David Neimeyer <[email protected]>
32
 */
33
34
class ShowSubCommand extends SubCommandCommand
35
{
36
    const GIT_REMOTE_SHOW = 'show';
37
38
    /**
39
     * constructor
40
     *
41
     * @param \GitElephant\Repository $repo The repository object this command 
42
     *                                      will interact with
43
     */
44 3
    public function __construct(Repository $repo = null)
45
    {
46 3
        parent::__construct($repo);
47 3
    }
48
49
    /**
50
     * build show sub command
51
     *
52
     * NOTE: for technical reasons $name is optional, however under normal
53
     * implementation it SHOULD be passed!
54
     *
55
     * @param string $name
56
     * @param bool   $queryRemotes Fetch new information from remotes
57
     *
58
     * @return ShowSubCommand
59
     */
60 3
    public function prepare($name = null, $queryRemotes = true)
61
    {
62 3
        $this->addCommandName(self::GIT_REMOTE_SHOW);
63
        /**
64
         *  only add subject if relevant,
65
         *  otherwise on repositories without a remote defined (ie, fresh
66
         *  init'd or mock) will likely trigger warning/error condition
67
         *
68
         */
69 3
        if ($name) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $name of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
70 2
            $this->addCommandSubject($name);
71 2
        }
72
73 3
        if (!$queryRemotes) {
74 1
            $this->addCommandArgument('-n');
75 1
        }
76
77 3
        return $this;
78
    }
79
}
80