Skip to content

Commit 0b848c4

Browse files
committed
Amendments
1 parent e35f6d7 commit 0b848c4

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

lib/Gitlab/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function api($name)
119119
* @param string $token Gitlab private token
120120
* @param null|string $authMethod One of the AUTH_* class constants
121121
*/
122-
public function authenticate($token, $authMethod = null, $sudo=null)
122+
public function authenticate($token, $authMethod = null, $sudo = null)
123123
{
124124
$this->httpClient->addListener(
125125
new AuthListener(

lib/Gitlab/HttpClient/Listener/AuthListener.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ class AuthListener implements ListenerInterface
1919
* @var string
2020
*/
2121
private $method;
22+
2223
/**
2324
* @var string
2425
*/
2526
private $token;
27+
2628
/**
2729
* @var string|null
2830
*/
@@ -32,7 +34,7 @@ class AuthListener implements ListenerInterface
3234
* @param string $method
3335
* @param string $token
3436
*/
35-
public function __construct($method, $token, $sudo=null)
37+
public function __construct($method, $token, $sudo = null)
3638
{
3739
$this->method = $method;
3840
$this->token = $token;
@@ -54,17 +56,19 @@ public function preSend(RequestInterface $request)
5456
switch ($this->method) {
5557
case Client::AUTH_HTTP_TOKEN:
5658
$request->addHeader('private_token: '.$this->token);
57-
if(!is_null($this->sudo)){
59+
if (!is_null($this->sudo)) {
5860
$request->addHeader('SUDO: '.$this->sudo);
5961
}
6062
break;
6163

6264
case Client::AUTH_URL_TOKEN:
6365
$url = $request->getUrl();
64-
$url .= (false === strpos($url, '?') ? '?' : '&').utf8_encode(http_build_query(array('private_token' => $this->token), '', '&'));
65-
if(!is_null($this->sudo)){
66-
$url.="&".utf8_encode(http_build_query(array('sudo' => $this->sudo), '', '&'));
66+
$query=array('private_token' => $this->token);
67+
if (!is_null($this->sudo)) {
68+
$query['sudo'] = $this->sudo;
6769
}
70+
$url .= (false === strpos($url, '?') ? '?' : '&').utf8_encode(http_build_query($query, '', '&'));
71+
6872
$request->fromUrl(new Url($url));
6973
break;
7074
}

0 commit comments

Comments
 (0)