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

akismet_factory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 29
rs 10
c 0
b 0
f 0
ccs 5
cts 5
cp 1
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create_akismet() 0 3 1
A __construct() 0 3 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