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

AbstractGitHubIO::getApi()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 4
cts 4
cp 1
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 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