Passed
Pull Request — master (#8)
by
unknown
12:51
created

akismet_factory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
/**
3
 *
4
 * Akismet. An extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2018 Jakub Senko <[email protected]>
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace senky\akismet\utility;
12
13
/**
14
 * The Akismet Factory class is used to create a new vendor Akismet
15
 * API wrapper class using our configured API key and board URL. These
16
 * need to be passed into the constructor, so a factory seemed a good
17
 * approach that would allow us to unit test easily.
18
 */
19
class akismet_factory
20
{
21
	/** @var \phpbb\config\config */
22
	protected $config;
23
24
	/**
25
	 * Constructor
26
	 *
27
	 * Lightweight initialisation of the API key and user ID.
28
	 * Heavy lifting is done only if the user actually tries
29
	 * to post a message, new user tries to register or moderator
30
	 * approves post (we submit ham to Akismet service).
31
	 *
32
	 * @param \phpbb\config\config		$config	phpBB Config class
33
	 */
34 2
	public function __construct(\phpbb\config\config $config)
35
	{
36 2
		$this->config = $config;
37 2
	}
38
39
	/**
40
	 * Initialize Akismet client with board-specific data
41
	 *
42
	 * @return \Gothick\AkismetClient\Client
43
	 * @throws \Gothick\AkismetClient\AkismetException
44
	 */
45 2
	public function create_akismet()
46
	{
47 2
		return new \Gothick\AkismetClient\Client(generate_board_url(), 'phpBB', $this->config['version'], $this->config['senky_akismet_api_key']);
48
	}
49
}
50