DiffTreeCommand::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * GitElephant - An abstraction layer for git written in PHP
5
 * Copyright (C) 2013  Matteo Giachino
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program.  If not, see [http://www.gnu.org/licenses/].
19
 */
20
21
namespace GitElephant\Command;
22
23
use GitElephant\Objects\Commit;
24
use GitElephant\Repository;
25
26
/**
27
 * DiffTreeCommand
28
 *
29
 * diff-tree command generator
30
 *
31
 * @author Matteo Giachino <[email protected]>
32
 */
33
class DiffTreeCommand extends BaseCommand
34
{
35
    public const DIFF_TREE_COMMAND = 'diff-tree';
36
37
    /**
38
     * constructor
39
     *
40
     * @param \GitElephant\Repository $repo The repository object this command
41
     *                                      will interact with
42
     */
43 1
    public function __construct(Repository $repo = null)
44
    {
45 1
        parent::__construct($repo);
46 1
    }
47
48
    /**
49
     * get a diff of a root commit with the empty repository
50
     *
51
     * @param \GitElephant\Objects\Commit $commit the root commit object
52
     *
53
     * @throws \RuntimeException
54
     * @throws \InvalidArgumentException
55
     * @return string
56
     */
57 1
    public function rootDiff(Commit $commit): string
58
    {
59 1
        if (!$commit->isRoot()) {
60 1
            throw new \InvalidArgumentException('rootDiff method accepts only root commits');
61
        }
62 1
        $this->clearAll();
63 1
        $this->addCommandName(static::DIFF_TREE_COMMAND);
64 1
        $this->addCommandArgument('--cc');
65 1
        $this->addCommandArgument('--root');
66 1
        $this->addCommandArgument('--dst-prefix=DST/');
67 1
        $this->addCommandArgument('--src-prefix=SRC/');
68 1
        $this->addCommandSubject($commit);
69
70 1
        return $this->getCommand();
71
    }
72
}
73