Completed
Push — develop ( 4961cb...5f7df1 )
by Matteo
03:22
created

MvCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 93.75%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 43
ccs 15
cts 16
cp 0.9375
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A rename() 0 19 3
1
<?php
2
/**
3
 * GitElephant - An abstraction layer for git written in PHP
4
 * Copyright (C) 2013  Matteo Giachino
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program.  If not, see [http://www.gnu.org/licenses/].
18
 */
19
20
namespace GitElephant\Command;
21
22
use \GitElephant\Objects\Object;
23
use \GitElephant\Repository;
24
25
/**
26
 * Class MvCommand
27
 *
28
 * @package GitElephant\Command
29
 */
30
class MvCommand extends BaseCommand
31
{
32
    const MV_COMMAND = 'mv';
33
34
    /**
35
     * constructor
36
     *
37
     * @param \GitElephant\Repository $repo The repository object this command 
38
     *                                      will interact with
39
     */
40 2
    public function __construct(Repository $repo = null)
41
    {
42 2
        parent::__construct($repo);
43 2
    }
44
45
    /**
46
     * @param string|Object $source source name
47
     * @param string        $target dest name
48
     *
49
     * @throws \RuntimeException
50
     * @throws \InvalidArgumentException
51
     * @return string
52
     */
53 2
    public function rename($source, $target)
54
    {
55 2
        if ($source instanceof Object) {
56 1
            if (!$source->isBlob()) {
57
                throw new \InvalidArgumentException("The given object is not a blob, it couldn't be renamed");
58
            }
59 1
            $sourceName = $source->getFullPath();
60 1
        } else {
61 2
            $sourceName = $source;
62
        }
63 2
        $this->clearAll();
64 2
        $this->addCommandName(self::MV_COMMAND);
65
        // Skip move or rename actions which would lead to an error condition
66 2
        $this->addCommandArgument('-k');
67 2
        $this->addCommandSubject($sourceName);
68 2
        $this->addCommandSubject2($target);
69
70 2
        return $this->getCommand();
71
    }
72
}
73