Completed
Push — master ( 8affd2...f42d92 )
by Matt
07:11
created

acp_controller   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 92.31%

Importance

Changes 5
Bugs 1 Features 1
Metric Value
wmc 5
c 5
b 1
f 1
lcom 1
cbo 1
dl 0
loc 67
ccs 24
cts 26
cp 0.9231
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A handle() 0 21 3
A set_u_action() 0 5 1
1
<?php
2
/**
3
 *
4
 * Topic Preview
5
 *
6
 * @copyright (c) 2013, 2016 Matt Friedman
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace vse\topicpreview\controller;
12
13
use phpbb\request\request;
14
use phpbb\template\template;
15
use phpbb\user;
16
use vse\topicpreview\core\settings;
17
18
class acp_controller implements acp_controller_interface
19
{
20
	/** @var request */
21
	protected $request;
22
23
	/** @var settings */
24
	protected $settings;
25
26
	/** @var template */
27
	protected $template;
28
29
	/** @var user */
30
	protected $user;
31
32
	/** @var string */
33
	protected $u_action;
34
35
	/**
36
	 * Constructor
37
	 *
38
	 * @param request  $request
39
	 * @param settings $settings
40
	 * @param template $template
41
	 * @param user     $user
42
	 */
43 3
	public function __construct(request $request, settings $settings, template $template, user $user)
44
	{
45 3
		$this->request = $request;
46 3
		$this->settings = $settings;
47 3
		$this->template = $template;
48 3
		$this->user = $user;
49 3
	}
50
51
	/**
52
	 * @inheritdoc
53
	 */
54 3
	public function handle()
55
	{
56 3
		$this->user->add_lang_ext('vse/topicpreview', 'topic_preview_acp');
57
58 3
		$form_key = 'acp_topic_preview';
59 3
		add_form_key($form_key);
60
61 3
		if ($this->request->is_set_post('submit'))
62 3
		{
63 2
			if (!check_form_key($form_key))
64 2
			{
65 1
				trigger_error($this->user->lang('FORM_INVALID') . adm_back_link($this->u_action), E_USER_WARNING);
66
			}
67
68 1
			$this->settings->set_settings();
69
70 1
			trigger_error($this->user->lang('CONFIG_UPDATED') . adm_back_link($this->u_action));
71
		}
72
73 1
		$this->template->assign_vars($this->settings->display_settings($this->u_action));
74 1
	}
75
76
	/**
77
	 * @inheritdoc
78
	 */
79 2
	public function set_u_action($u_action)
80 1
	{
81 2
		$this->u_action = $u_action;
82 2
		return $this;
83 1
	}
84
}
85