Completed
Pull Request — develop (#95)
by
unknown
11:07
created

ResetCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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\Tag;
14
use GitElephant\Objects\TreeishInterface;
15
use \GitElephant\Repository;
16
17
class ResetCommand extends BaseCommand
18
{
19
    const GIT_RESET_COMMAND = 'reset';
20
21
    const OPTION_HARD  = '--hard';
22
    const OPTION_MERGE = '--merge';
23
    const OPTION_SOFT  = '--soft';
24
25
    /**
26
     * constructor
27
     *
28
     * @param \GitElephant\Repository $repo The repository object this command
29
     *                                      will interact with
30
     */
31
    public function __construct(Repository $repo = null)
32
    {
33
        parent::__construct($repo);
34
    }
35
36
    /**
37
     * @param TreeishInterface|Commit|string $arg
38
     * @param array $options
39
     *
40
     * @throws \RuntimeException
41
     * @return string
42
     */
43
    public function reset($arg = 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...
44
    {
45
        $this->clearAll();
46
        $this->addCommandName(self::GIT_RESET_COMMAND);
47
        // if there are options add them.
48
        if (! is_null($options)) {
49
            foreach ($options as $option) {
50
                $this->addCommandArgument($option);
51
            }
52
        }
53
        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...
54
            $this->addCommandSubject2($arg);
0 ignored issues
show
Bug introduced by
It seems like $arg defined by parameter $arg on line 43 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...
55
        }
56
57
        return $this->getCommand();
58
    }
59
60
    /**
61
     * @return ResetCommand
62
     */
63
    public static function getInstance()
64
    {
65
        return new self();
66
    }
67
68
69
70
}