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

Diff::compare()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 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\Operator;
11
12
use SebastianFeldmann\Git\Command\Diff\Compare;
13
use SebastianFeldmann\Git\Command\DiffTree\ChangedFiles;
14
15
/**
16
 * Diff operator
17
 *
18
 * @package SebastianFeldmann\Git
19
 * @author  Sebastian Feldmann <[email protected]>
20
 * @link    https://github.com/sebastianfeldmann/git
21
 * @since   Class available since Release 1.2.0
22
 */
23
class Diff extends Base
24
{
25
    /**
26
     * Returns a list of files and their changes.
27
     *
28
     * @param  string $from
29
     * @param  string $to
30
     * @return \SebastianFeldmann\Git\Diff\File[]
31
     */
32 1
    public function compare(string $from, string $to): array
33
    {
34 1
        $compare = (new Compare($this->repo->getRoot()))->revisions($from, $to)
35 1
                                                        ->ignoreWhitespacesAtEndOfLine();
36
37 1
        $result = $this->runner->run($compare, new Compare\FullDiffList());
38
39 1
        return $result->getFormattedOutput();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $result->getFormattedOutput() returns the type iterable which is incompatible with the type-hinted return array.
Loading history...
40
    }
41
42
    /**
43
     * Uses 'diff-tree' to list the files that changed between two revisions
44
     *
45
     * @param  string $from
46
     * @param  string $to
47
     * @return string[]
48
     */
49 1
    public function getChangedFiles(string $from, string $to): array
50
    {
51 1
        $cmd    = (new ChangedFiles($this->repo->getRoot()))->fromRevision($from)->toRevision($to);
52 1
        $result = $this->runner->run($cmd);
53
54 1
        return $result->getBufferedOutput();
55
    }
56
}
57