GitLabAuthenticator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 43
ccs 10
cts 10
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A authenticate() 0 13 3
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Laravel GitLab.
7
 *
8
 * (c) Graham Campbell <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace GrahamCampbell\GitLab\Authenticators;
15
16
use InvalidArgumentException;
17
18
/**
19
 * This is the gitlab authenticator class.
20
 *
21
 * @author Graham Campbell <[email protected]>
22
 */
23
class GitLabAuthenticator extends AbstractAuthenticator
24
{
25
    /**
26
     * The auth method to use.
27
     *
28
     * @var string
29
     */
30
    protected $method;
31
32
    /**
33
     * Create a new gitlab authenticator instance.
34
     *
35
     * @param string $method
36
     *
37
     * @return void
38
     */
39 228
    public function __construct(string $method)
40
    {
41 228
        $this->method = $method;
42 228
    }
43
44
    /**
45
     * Authenticate the client, and return it.
46
     *
47
     * @param string[] $config
48
     *
49
     * @throws \InvalidArgumentException
50
     *
51
     * @return \Gitlab\Client
52
     */
53 204
    public function authenticate(array $config)
54
    {
55 204
        if (!$this->client) {
56 24
            throw new InvalidArgumentException('The client instance was not given to the authenticator.');
57
        }
58
59 180
        if (!array_key_exists('token', $config)) {
60 24
            throw new InvalidArgumentException('The gitlab authenticator requires a token.');
61
        }
62
63 156
        $this->client->authenticate($config['token'], $this->method, $config['sudo'] ?? null);
64
65 156
        return $this->client;
66
    }
67
}
68