PullCommand   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 46
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B pull() 0 22 6
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\Branch;
24
use GitElephant\Objects\Remote;
25
use GitElephant\Repository;
26
27
/**
28
 * Class PullCommand
29
 */
30
class PullCommand extends BaseCommand
31
{
32
    public const GIT_PULL_COMMAND = 'pull';
33
34
    /**
35
     * constructor
36
     *
37
     * @param \GitElephant\Repository $repo The repository object this command
38
     *                                      will interact with
39
     */
40 3
    public function __construct(Repository $repo = null)
41
    {
42 3
        parent::__construct($repo);
43 3
    }
44
45
    /**
46
     * @param Remote|string $remote
47
     * @param Branch|string $branch
48
     * @param bool          $rebase
49
     *
50
     * @throws \RuntimeException
51
     * @return string
52
     */
53 3
    public function pull($remote = null, $branch = null, $rebase = false): string
54
    {
55 3
        if ($remote instanceof Remote) {
56 1
            $remote = $remote->getName();
57
        }
58 3
        if ($branch instanceof Branch) {
59 1
            $branch = $branch->getName();
60
        }
61 3
        $this->clearAll();
62 3
        $this->addCommandName(self::GIT_PULL_COMMAND);
63 3
        if ($rebase) {
64 3
            $this->addCommandArgument('--rebase');
65
        }
66 3
        if (!is_null($remote)) {
67 3
            $this->addCommandSubject($remote);
68
        }
69 3
        if (!is_null($branch)) {
70 3
            $this->addCommandSubject2($branch);
71
        }
72
73 3
        return $this->getCommand();
74
    }
75
}
76