PushCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 93.33%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A push() 0 21 4
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 PushCommand
29
 */
30
class PushCommand extends BaseCommand
31
{
32
    public const GIT_PUSH_COMMAND = 'push';
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 Remote|string $remote
47
     * @param Branch|string $branch
48
     *
49
     * @throws \RuntimeException
50
     * @return string
51
     */
52 2
    public function push($remote = 'origin', $branch = 'master', string $args = null): string
53
    {
54 2
        $this->clearAll();
55
56 2
        if ($remote instanceof Remote) {
57 1
            $remote = $remote->getName();
58
        }
59 2
        if ($branch instanceof Branch) {
60 1
            $branch = $branch->getName();
61
        }
62
63 2
        $this->addCommandName(self::GIT_PUSH_COMMAND);
64 2
        $this->addCommandSubject($remote);
65 2
        $this->addCommandSubject2($branch);
66
        
67 2
        if (!is_null($args)) {
68
            $this->addCommandArgument($args);
69
        }
70
71 2
        return $this->getCommand();
72
    }
73
}
74