Completed
Push — master ( 266e11...aef73b )
by Sebastian
03:20
created

ChangedFiles   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 9
dl 0
loc 51
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

4 Methods

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