Completed
Pull Request — master (#139)
by
unknown
02:03
created

ResetCommand::getInstance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: christian
5
 * Date: 3/2/16
6
 * Time: 11:29 AM
7
 */
8
9
namespace GitElephant\Command;
10
11
12
use GitElephant\Objects\Commit;
13
use GitElephant\Objects\TreeishInterface;
14
use \GitElephant\Repository;
15
16
class ResetCommand extends BaseCommand
17
{
18
    const GIT_RESET_COMMAND = 'reset';
19
20
    const OPTION_HARD  = '--hard';
21
    const OPTION_MERGE = '--merge';
22
    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 = array())
43
    {
44 3
        $this->clearAll();
45 3
        $this->addCommandName(self::GIT_RESET_COMMAND);
46
        // if there are options add them.
47 3
        if (! is_null($options)) {
48 3
            foreach ($options as $option) {
49 3
                $this->addCommandArgument($option);
50
            }
51
        }
52 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...
Coding Style introduced by
Expected 1 space after IF keyword; 0 found
Loading history...
53 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 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...
54
        }
55
56 3
        return $this->getCommand();
57
    }
58
59
    /**
60
     * @param Repository $repository
61
     * @return ResetCommand
62
     */
63 3
    public static function getInstance(Repository $repository=null)
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$repository" and equals sign; expected 1 but found 0
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$repository"; expected 1 but found 0
Loading history...
64
    {
65 3
        return new self($repository);
66
    }
67
68
69
70
}
71