ResetCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 51
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getInstance() 0 4 1
A reset() 0 15 3
1
<?php
2
3
/**
4
 * Created by PhpStorm.
5
 * User: christian
6
 * Date: 3/2/16
7
 * Time: 11:29 AM
8
 */
9
10
namespace GitElephant\Command;
11
12
use GitElephant\Objects\Commit;
13
use GitElephant\Objects\TreeishInterface;
14
use GitElephant\Repository;
15
16
class ResetCommand extends BaseCommand
17
{
18
    public const GIT_RESET_COMMAND = 'reset';
19
20
    public const OPTION_HARD = '--hard';
21
    public const OPTION_MERGE = '--merge';
22
    public const OPTION_SOFT = '--soft';
23
24
    /**
25
     * constructor
26
     *
27
     * @param \GitElephant\Repository $repo The repository object this command
28
     *                                      will interact with
29
     */
30 3
    public function __construct(Repository $repo = null)
31
    {
32 3
        parent::__construct($repo);
33 3
    }
34
35
    /**
36
     * @param TreeishInterface|Commit|string $arg
37
     * @param array $options
38
     *
39
     * @throws \RuntimeException
40
     * @return string
41
     */
42 3
    public function reset($arg = null, array $options = []): string
43
    {
44 3
        $this->clearAll();
45 3
        $this->addCommandName(self::GIT_RESET_COMMAND);
46
        // if there are options add them.
47 3
        foreach ($options as $option) {
48 3
            $this->addCommandArgument($option);
49
        }
50
51 3
        if ($arg != null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $arg of type GitElephant\Objects\TreeishInterface|string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
52 3
            $this->addCommandSubject2($arg);
0 ignored issues
show
Bug introduced by
It seems like $arg defined by parameter $arg on line 42 can also be of type object<GitElephant\Objects\TreeishInterface>; 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...
53
        }
54
55 3
        return $this->getCommand();
56
    }
57
58
    /**
59
     * @param Repository $repository
60
     * @return ResetCommand
61
     */
62 3
    public static function getInstance(Repository $repository = null): \GitElephant\Command\ResetCommand
63
    {
64 3
        return new self($repository);
65
    }
66
}
67