Completed
Push — master ( 751a3d...b7ca33 )
by Sebastian
17:18 queued 15:56
created

Compare   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 83
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A revisions() 0 5 1
A statsOnly() 0 5 1
A ignoreWhitespacesAtEndOfLine() 0 5 1
A ignoreWhitespaces() 0 5 1
A getGitCommand() 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\Diff;
11
12
use SebastianFeldmann\Git\Command\Base;
13
14
/**
15
 * Class Between
16
 *
17
 * @package SebastianFeldmann\Git
18
 * @author  Sebastian Feldmann <[email protected]>
19
 * @link    https://github.com/sebastianfeldmann/git
20
 * @since   Class available since Release 1.2.0
21
 */
22
class Compare extends Base
23
{
24
    /**
25
     * Compare A/B command snippet.
26
     *
27
     * @var string
28
     */
29
    protected $compare = '';
30
31
    /**
32
     * Ignore line endings.
33
     *
34
     * @var bool
35
     */
36
    protected $ignoreEOL = '';
37
38
    /**
39
     * Show statistics only.
40
     *
41
     * @var string
42
     */
43
    protected $stats = '';
44
45
    /**
46
     * Compare two given revisions.
47
     *
48
     * @param  string $from
49
     * @param  string $to
50
     * @return \SebastianFeldmann\Git\Command\Diff\Compare
51
     */
52 4
    public function revisions(string $from, string $to) : Compare
53
    {
54 4
        $this->compare = escapeshellarg($from) . ' ' . escapeshellarg($to);
55 4
        return $this;
56
    }
57
58
    /**
59
     * Set diff statistics option.
60
     *
61
     * @param  bool $bool
62
     * @return \SebastianFeldmann\Git\Command\Diff\Compare
63
     */
64 1
    public function statsOnly(bool $bool = true) : Compare
65
    {
66 1
        $this->stats = $this->useOption('--numstat', $bool);
67 1
        return $this;
68
    }
69
70
    /**
71
     * Set ignore spaces at end of line.
72
     *
73
     * @param  bool $bool
74
     * @return \SebastianFeldmann\Git\Command\Diff\Compare
75
     */
76 1
    public function ignoreWhitespacesAtEndOfLine(bool $bool = true) : Compare
77
    {
78 1
        $this->ignoreEOL = $this->useOption('--ignore-space-at-eol', $bool);
0 ignored issues
show
Documentation Bug introduced by
The property $ignoreEOL was declared of type boolean, but $this->useOption('--ignore-space-at-eol', $bool) is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
79 1
        return $this;
80
    }
81
82
    /**
83
     * Set ignore all whitespaces.
84
     *
85
     * @param  bool $bool
86
     * @return \SebastianFeldmann\Git\Command\Diff\Compare
87
     */
88 1
    public function ignoreWhitespaces(bool $bool = true) : Compare
89
    {
90 1
        $this->ignoreEOL = $this->useOption('-w', $bool);
0 ignored issues
show
Documentation Bug introduced by
The property $ignoreEOL was declared of type boolean, but $this->useOption('-w', $bool) is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
91 1
        return $this;
92
    }
93
94
    /**
95
     * Return the command to execute.
96
     *
97
     * @return string
98
     * @throws \RuntimeException
99
     */
100 4
    protected function getGitCommand(): string
101
    {
102 4
        return 'diff' . $this->ignoreEOL . $this->stats . ' ' . $this->compare;
103
    }
104
}
105