Completed
Push — develop ( 5f7df1...9cb564 )
by Matteo
10s
created

LogRangeCommand::showLog()   C

Complexity

Conditions 8
Paths 64

Size

Total Lines 39
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 21
CRAP Score 9
Metric Value
dl 0
loc 39
ccs 21
cts 28
cp 0.75
rs 5.3846
cc 8
eloc 22
nc 64
nop 6
crap 9
1
<?php
2
/**
3
 * This file is part of the GitElephant package.
4
 *
5
 * (c) Matteo Giachino <[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
 * @package GitElephant\Command
11
 *
12
 * Just for fun...
13
 */
14
15
namespace GitElephant\Command;
16
17
use \GitElephant\Objects\TreeishInterface;
18
use \GitElephant\Repository;
19
20
/**
21
 * Log Range command generator
22
 *
23
 * @author Matteo Giachino <[email protected]>
24
 * @author John Cartwright <[email protected]>
25
 * @author Dhaval Patel <[email protected]>
26
 */
27
class LogRangeCommand extends BaseCommand
28
{
29
    const GIT_LOG = 'log';
30
31
    /**
32
     * constructor
33
     *
34
     * @param \GitElephant\Repository $repo The repository object this command 
35
     *                                      will interact with
36
     */
37 6
    public function __construct(Repository $repo = null)
38
    {
39 6
        parent::__construct($repo);
40 6
    }
41
42
    /**
43
     * Build a generic log command
44
     *
45
     * @param \GitElephant\Objects\TreeishInterface|string $refStart    the reference range start to build the log for
46
     * @param \GitElephant\Objects\TreeishInterface|string $refEnd      the reference range end to build the log for
47
     * @param string|null                                  $path        the physical path to the tree relative
48
     *                                                                  to the repository root
49
     * @param int|null                                     $limit       limit to n entries
50
     * @param int|null                                     $offset      skip n entries
51
     * @param boolean|false                                $firstParent skip commits brought in to branch by a merge
52
     *
53
     * @throws \RuntimeException
54
     * @return string
55
     */
56 6
    public function showLog($refStart, $refEnd, $path = null, $limit = null, $offset = null, $firstParent = false)
57
    {
58 6
        $this->clearAll();
59
60 6
        $this->addCommandName(self::GIT_LOG);
61 6
        $this->addCommandArgument('-s');
62 6
        $this->addCommandArgument('--pretty=raw');
63 6
        $this->addCommandArgument('--no-color');
64
65 6
        if (null !== $limit) {
66 6
            $limit = (int)$limit;
67 6
            $this->addCommandArgument('--max-count=' . $limit);
68 6
        }
69
70 6
        if (null !== $offset) {
71
            $offset = (int)$offset;
72
            $this->addCommandArgument('--skip=' . $offset);
73
        }
74
75 6
        if (true === $firstParent) {
76
            $this->addCommandArgument('--first-parent');
77
        }
78
79 6
        if ($refStart instanceof TreeishInterface) {
80 6
            $refStart = $refStart->getSha();
81 6
        }
82
83 6
        if ($refEnd instanceof TreeishInterface) {
84 6
            $refEnd = $refEnd->getSha();
85 6
        }
86
87 6
        if (null !== $path && !empty($path)) {
88
            $this->addPath($path);
89
        }
90
91 6
        $this->addCommandSubject($refStart . '..' . $refEnd);
92
93 6
        return $this->getCommand();
94
    }
95
}
96