RedmineClientAdapter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * File part of the Redmine User Provider bundle
4
 *
5
 * @category  SymfonyBundle
6
 * @package   GMaissa.RedmineUserProviderBundle
7
 * @author    Guillaume Maïssa <[email protected]>
8
 * @copyright 2017 Guillaume Maïssa
9
 * @license   https://opensource.org/licenses/MIT The MIT License (MIT)
10
 */
11
12
namespace GMaissa\RedmineUserProviderBundle\ApiClient\Adapter;
13
14
use GMaissa\RedmineUserProviderBundle\ApiClient\RedmineApiClientInterface;
15
16
/**
17
 * AWS Ec2 client adapter class
18
 */
19
class RedmineClientAdapter implements RedmineApiClientInterface
20
{
21
    /**
22
     * Redmine API Client Class
23
     * @var string
24
     */
25
    private $clientClass;
26
27
    /**
28
     * @var Object
29
     */
30
    private $client;
31
32
    /**
33
     * @var string
34
     */
35
    private $url;
36
37
    /**
38
     * Class constructor.
39
     *
40
     * @param string $url
41
     */
42 3
    public function __construct(string $url)
43
    {
44 3
        $this->url = $url;
45 3
    }
46
47
    /**
48
     * Set the Redmine client Class
49
     *
50
     * @param string $clientClass
51
     */
52 3
    public function setClientClass(string $clientClass)
53
    {
54 3
        $this->clientClass = $clientClass;
55 3
    }
56
57
    /**
58
     * Connect to Redmine API
59
     *
60
     * @param string $login
61
     * @param string $password
62
     */
63
    public function connect(string $login, string $password)
64
    {
65
        $this->client = new $this->clientClass($this->url, $login, $password);
66
    }
67
68
    /**
69
     * Retrieve a specific API
70
     *
71
     * @param string $apiName
72
     *
73
     * @return Object
74
     * @throws \Exception if not connected
75
     */
76
    public function api(string $apiName)
77
    {
78
        if (!$this->client instanceof $this->clientClass) {
79
            throw new \Exception('Connection to server not instantiated');
80
        }
81
82
        return $this->client->api($apiName);
83
    }
84
}
85