Completed
Push — master ( c51e3e...e345c0 )
by Emlyn
01:58
created

AbstractGitHubIO   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 43
ccs 8
cts 12
cp 0.6667
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getApi() 0 9 2
A createApiInstance() 0 13 2
1
<?php
2
/**
3
 * PHP Version 5.6
4
 * @category Library
5
 * @package ChangeLog
6
 * @author Emlyn West <[email protected]>
7
 * @license MIT http://opensource.org/licenses/MIT
8
 * @link https://github.com/emlynwest/changelog
9
 */
10
11
namespace ChangeLog\IO;
12
13
use ChangeLog\AbstractIO;
14
use InvalidArgumentException;
15
use Milo\Github\Api;
16
use Milo\Github\OAuth\Token;
17
18
abstract class AbstractGitHubIO extends AbstractIO
19
{
20
21
	/**
22
	 * @var Api
23
	 */
24
	protected $api;
25
26
	/**
27
	 * Gets an active connection to the GitHub api.
28
	 *
29
	 * @return Api
30
	 */
31 4
	protected function getApi()
32
	{
33 4
		if ($this->api === null)
34
		{
35 1
			$this->createApiInstance();
36
		}
37
38 3
		return $this->api;
39
	}
40
41
	/**
42
	 * Creates a new instance of the API library to use later.
43
	 *
44
	 * @throws InvalidArgumentException
45
	 */
46 1
	protected function createApiInstance()
47
	{
48 1
		$configToken = $this->getConfig('token');
49
50 1
		if ($configToken === null)
51
		{
52 1
			throw new InvalidArgumentException('API token has not been set in the config.');
53
		}
54
55
		$token = new Token($configToken);
56
		$this->api = new Api();
57
		$this->api->setToken($token);
58
	}
59
60
}
61