Failed Conditions
Push — develop ( bf7046...18e86d )
by Maxime
18:38
created

Hg::update()   A

Complexity

Conditions 1
Paths 1

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 4
Code Lines 2

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of Rocketeer
5
 *
6
 * (c) Maxime Fabre <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 */
12
13
namespace Rocketeer\Binaries\Vcs;
14
15
use Rocketeer\Binaries\AbstractBinary;
16
17
/**
18
 * The Mercury implementation of the VcsInterface.
19
 */
20
class Hg extends AbstractBinary implements VcsInterface
21
{
22
    /**
23
     * The core binary.
24
     *
25
     * @var string
26
     */
27
    protected $binary = 'hg';
28
29
    /**
30
     * Check if the VCS is available.
31
     *
32
     * @return string
33
     */
34 1
    public function check()
35
    {
36 1
        return $this->getCommand('--version');
37
    }
38
39
    /**
40
     * Get the current state.
41
     *
42
     * @return string
43
     */
44 1
    public function currentState()
45
    {
46 1
        return $this->getCommand('identify -i');
47
    }
48
49
    /**
50
     * Get the current branch.
51
     *
52
     * @return string
53
     */
54 1
    public function currentBranch()
55
    {
56 1
        return $this->getCommand('branch');
57
    }
58
59
    /**
60
     * @return string
61
     */
62
    public function currentEndpoint()
63
    {
64
        return $this->getCommand('paths default');
65
    }
66
67
    /**
68
     * Clone a repository.
69
     *
70
     * @param string $destination
71
     *
72
     * @return string
73
     */
74 1
    public function checkout($destination)
75
    {
76 1
        $repository = $this->credentials->getCurrentRepository();
77
78
        $arguments = [
79 1
            $this->quote($repository->repository),
80 1
            '-b '.$repository->branch,
81 1
            $this->quote($destination),
82 1
        ];
83
84 1
        return $this->clone($arguments, $this->getCredentials());
0 ignored issues
show
Documentation Bug introduced by Maxime Fabre
The method clone does not exist on object<Rocketeer\Binaries\Vcs\Hg>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
85
    }
86
87
    /**
88
     * Resets the repository.
89
     *
90
     * @return string
91
     */
92 1
    public function reset()
93
    {
94 1
        return $this->getCommand('update --clean');
95
    }
96
97
    /**
98
     * Updates the repository.
99
     *
100
     * @return string
101
     */
102 1
    public function update()
103
    {
104 1
        return $this->pull();
0 ignored issues
show
Documentation Bug introduced by Maxime Fabre
The method pull does not exist on object<Rocketeer\Binaries\Vcs\Hg>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
105
    }
106
107
    /**
108
     * Checkout the repository's submodules.
109
     *
110
     * @return string|null
111
     */
112 1
    public function submodules()
113
    {
114 1
    }
115
116
    //////////////////////////////////////////////////////////////////////
117
    ////////////////////////////// HELPERS ///////////////////////////////
118
    //////////////////////////////////////////////////////////////////////
119
120
    /**
121
     * Get the credentials required for cloning.
122
     *
123
     * @return array
124
     */
125 1
    private function getCredentials()
126
    {
127 1
        $options = ['--config ui.interactive' => 'no', '--config auth.x.prefix' => 'http://'];
128
129 1
        $repository = $this->credentials->getCurrentRepository();
130 1
        if ($user = $repository->username) {
131 1
            $options['--config auth.x.username'] = $user;
132 1
        }
133 1
        if ($pass = $repository->password) {
134 1
            $options['--config auth.x.password'] = $pass;
135 1
        }
136
137 1
        return $options;
138
    }
139
}
140