Completed
Push — develop ( 29df12...700ecb )
by Matteo
03:39
created

DiffCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
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;
21
22
use \GitElephant\Objects\TreeishInterface;
23
use \GitElephant\Repository;
24
25
/**
26
 * Diff command generator
27
 *
28
 * @author Matteo Giachino <[email protected]>
29
 */
30
class DiffCommand extends BaseCommand
31
{
32
    const DIFF_COMMAND = 'diff';
33
34
    /**
35
     * constructor
36
     *
37
     * @param \GitElephant\Repository $repo The repository object this command 
38
     *                                      will interact with
39
     */
40 3
    public function __construct(Repository $repo = null)
41
    {
42 3
        parent::__construct($repo);
43 3
    }
44
45
    /**
46
     * build a diff command
47
     *
48
     * @param TreeishInterface      $of   the reference to diff
49
     * @param TreeishInterface|null $with the source reference to diff with $of, if not specified is the current HEAD
50
     * @param null                  $path the path to diff, if not specified the full repository
51
     *
52
     * @throws \RuntimeException
53
     * @return string
54
     */
55 3
    public function diff($of, $with = null, $path = null)
56
    {
57 3
        $this->clearAll();
58 3
        $this->addCommandName(self::DIFF_COMMAND);
59
        // Instead of the first handful of characters, show the full pre- and post-image blob object names on the
60
        // "index" line when generating patch format output
61 3
        $this->addCommandArgument('--full-index');
62 3
        $this->addCommandArgument('--no-color');
63
        // Disallow external diff drivers
64 3
        $this->addCommandArgument('--no-ext-diff');
65
        // Detect renames
66 3
        $this->addCommandArgument('-M');
67 3
        $this->addCommandArgument('--dst-prefix=DST/');
68 3
        $this->addCommandArgument('--src-prefix=SRC/');
69
70 3
        $subject = '';
71
72 3
        if (is_null($with)) {
73 3
            $subject .= $of.'^..'.$of;
74 3
        } else {
75 1
            $subject .= $with.'..'.$of;
76
        }
77
78 3
        if (! is_null($path)) {
79 1
            if (!is_string($path)) {
80
                /** @var Object $path */
81
                $path = $path->getPath();
82
            }
83 1
            $this->addPath($path);
0 ignored issues
show
Bug introduced by
It seems like $path defined by parameter $path on line 55 can also be of type object; however, GitElephant\Command\BaseCommand::addPath() 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...
84 1
        }
85
86 3
        $this->addCommandSubject($subject);
87
88 3
        return $this->getCommand();
89
    }
90
}
91