ChangedFiles::fromRevision()   A
last analyzed

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 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * This file is part of SebastianFeldmann\Git.
5
 *
6
 * (c) Sebastian Feldmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace SebastianFeldmann\Git\Command\DiffTree;
13
14
use SebastianFeldmann\Git\Command\Base;
15
16
/**
17
 * Class ChangedFiles
18
 *
19
 * @package SebastianFeldmann\Git
20
 * @author  Sebastian Feldmann <[email protected]>
21
 * @link    https://github.com/sebastianfeldmann/git
22
 * @since   Class available since Release 2.0.1
23
 */
24
class ChangedFiles extends Base
25
{
26
    /**
27
     * @var string
28
     */
29
    private $from;
30
31
    /**
32
     * @var string
33
     */
34
    private $to;
35
36
    /**
37
     * @param  string $from
38 3
     * @return \SebastianFeldmann\Git\Command\DiffTree\ChangedFiles
39
     */
40 3
    public function fromRevision(string $from): ChangedFiles
41 3
    {
42
        $this->from = $from;
43
        return $this;
44
    }
45
46
    /**
47
     * @param  string $to
48 2
     * @return \SebastianFeldmann\Git\Command\DiffTree\ChangedFiles
49
     */
50 2
    public function toRevision(string $to): ChangedFiles
51 2
    {
52
        $this->to = $to;
53
        return $this;
54
    }
55
56
    /**
57
     * Return the command to execute.
58
     *
59
     * @return string
60 2
     * @throws \RuntimeException
61
     */
62 2
    protected function getGitCommand(): string
63
    {
64
        return 'diff-tree --no-commit-id --name-only -r ' . $this->getVersionsToCompare();
65
    }
66
67
    /**
68
     * Return the from commit id to diff
69
     *
70 2
     * @return string
71
     */
72 2
    protected function getVersionsToCompare(): string
73
    {
74
        return escapeshellarg($this->from) . (empty($this->to) ? '' : ' ' . escapeshellarg($this->to));
75
    }
76
}
77