RevParseCommand::revParse()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 8
cts 8
cp 1
rs 9.7666
c 0
b 0
f 0
cc 3
nc 4
nop 2
crap 3
1
<?php
2
3
/**
4
 * GitElephant - An abstraction layer for git written in PHP
5
 * Copyright (C) 2014  John Schlick [email protected]
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;
22
23
use GitElephant\Objects\Branch;
24
use GitElephant\Repository;
25
26
/**
27
 * Class RevParseCommand
28
 */
29
class RevParseCommand extends BaseCommand
30
{
31
    public const GIT_REV_PARSE_COMMAND = 'rev-parse';
32
33
    public const OPTION_ALL = '--all';
34
    public const OPTION_KEEP_DASHDASH = '--keep-dashdash';
35
    public const OPTION_STOP_AT_NON_OPTION = '--stop-at-non-option';
36
    public const OPTION_SQ_QUOTE = '--sq-quote';
37
    public const OPTION_REVS_ONLY = '--revs-only';
38
    public const OPTION_NO_REVS = '--no-revs';
39
    public const OPTION_FLAGS = '--flags';
40
    public const OPTION_NO_FLAGS = '--no-flags';
41
    public const OPTION_DEFAULT = '--default';
42
    public const OPTION_VERIFY = '--verify';
43
    public const OPTION_QUIET = '--quiet';
44
    public const OPTION_SQ = '--sq';
45
    public const OPTION_NOT = '--not';
46
    public const OPTION_SYMBOLIC = '--symbolic';
47
    public const OPTION_SYMBOLIC_FULL_NAME = '--symbolic-full-name';
48
    public const OPTION_ABBREV_REF = '--abbrev-ref';
49
    public const OPTION_DISAMBIGUATE = '--disambiguate';
50
    public const OPTION_BRANCHES = '--branches';
51
    public const OPTION_TAGS = '--tags';
52
    public const OPTION_REMOTES = '--remotes';
53
    public const OPTION_GLOB = '--glob';
54
    public const OPTION_SHOW_TOPLEVEL = '--show-toplevel';
55
    public const OPTION_SHOW_PREFIX = '--show-prefix';
56
    public const OPTION_SHOW_CDUP = '--show-cdup';
57
    public const OPTION_GIT_DIR = '--git-dir';
58
    public const OPTION_IS_INSIDE_GIT_DIR = '--is-inside-git-dir';
59
    public const OPTION_IS_INSIDE_WORK_TREE = '--is-inside-work-tree';
60
    public const OPTION_IS_BARE_REPOSIORY = '--is-bare-repository';
61
    public const OPTION_LCOAL_ENV_VARS = '--local-env-vars';
62
    public const OPTION_SHORT = '--short';
63
    public const OPTION_SINCE = '--since';
64
    public const OPTION_AFTER = '--after';
65
    public const OPTION_UNTIL = '--until';
66
    public const OPTION_BEFORE = '--before';
67
    public const OPTION_RESOLVE_GIT_DIR = '--resolve-git-dir';
68
69
    public const TAG_HEAD = "HEAD";
70
71
    /**
72
     * constructor
73
     *
74
     * @param \GitElephant\Repository $repo The repository object this command
75
     *                                      will interact with
76
     */
77 6
    public function __construct(Repository $repo = null)
78
    {
79 6
        parent::__construct($repo);
80 6
    }
81
82
    /**
83
     * @param array $options
84
     * @param Branch|string $arg
85
     *
86
     * @throws \RuntimeException
87
     * @return string
88
     */
89 6
    public function revParse($arg = null, array $options = []): string
90
    {
91 6
        $this->clearAll();
92 6
        $this->addCommandName(self::GIT_REV_PARSE_COMMAND);
93
        // if there are options add them.
94 6
        foreach ($options as $option) {
95 3
            $this->addCommandArgument($option);
96
        }
97
98 6
        if (!is_null($arg)) {
99 4
            $this->addCommandSubject2($arg);
0 ignored issues
show
Bug introduced by
It seems like $arg defined by parameter $arg on line 89 can also be of type object<GitElephant\Objects\Branch>; however, GitElephant\Command\Base...d::addCommandSubject2() does only seem to accept object<GitElephant\Comma...ndCommand>|array|string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
100
        }
101
102 6
        return $this->getCommand();
103
    }
104
}
105