ucp_listener   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 25
c 3
b 0
f 0
dl 0
loc 90
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A ucp_prefs_set_data() 0 4 1
A ucp_prefs_get_data() 0 14 3
A getSubscribedEvents() 0 5 1
1
<?php
2
/**
3
 *
4
 * Precise Similar Topics
5
 *
6
 * @copyright (c) 2014 Matt Friedman
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace vse\similartopics\event;
12
13
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\EventD...ventSubscriberInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
15
/**
16
 * Event listener
17
 */
18
class ucp_listener implements EventSubscriberInterface
19
{
20
	/** @var \phpbb\auth\auth */
0 ignored issues
show
Bug introduced by
The type phpbb\auth\auth was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
	protected $auth;
22
23
	/** @var \phpbb\config\config */
0 ignored issues
show
Bug introduced by
The type phpbb\config\config was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
	protected $config;
25
26
	/** @var \phpbb\language\language */
0 ignored issues
show
Bug introduced by
The type phpbb\language\language was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
	protected $language;
28
29
	/** @var \phpbb\request\request */
0 ignored issues
show
Bug introduced by
The type phpbb\request\request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
	protected $request;
31
32
	/** @var \phpbb\template\template */
0 ignored issues
show
Bug introduced by
The type phpbb\template\template was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
33
	protected $template;
34
35
	/** @var \phpbb\user */
0 ignored issues
show
Bug introduced by
The type phpbb\user was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
36
	protected $user;
37
38
	/**
39
	 * Constructor
40
	 *
41
	 * @access public
42
	 * @param \phpbb\auth\auth         $auth
43
	 * @param \phpbb\config\config     $config
44
	 * @param \phpbb\language\language $language
45
	 * @param \phpbb\request\request   $request
46
	 * @param \phpbb\template\template $template
47
	 * @param \phpbb\user              $user
48
	 */
49
	public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\language\language $language, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user)
50
	{
51
		$this->auth = $auth;
52
		$this->config = $config;
53
		$this->language = $language;
54
		$this->request = $request;
55
		$this->template = $template;
56
		$this->user = $user;
57
	}
58
59
	/**
60
	 * Assign functions defined in this class to event listeners in the core
61
	 *
62
	 * @static
63
	 * @access public
64
	 * @return array
65
	 */
66
	public static function getSubscribedEvents()
67
	{
68
		return [
69
			'core.ucp_prefs_view_data'				=> 'ucp_prefs_get_data',
70
			'core.ucp_prefs_view_update_data'		=> 'ucp_prefs_set_data',
71
		];
72
	}
73
74
	/**
75
	 * Get user's Similar Topics option and display it in UCP Prefs View page
76
	 *
77
	 * @access public
78
	 * @param \phpbb\event\data $event The event object
0 ignored issues
show
Bug introduced by
The type phpbb\event\data was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
79
	 */
80
	public function ucp_prefs_get_data($event)
81
	{
82
		// Request the user option vars and add them to the data array
83
		$event['data'] = array_merge($event['data'], [
84
			'similar_topics'	=> $this->request->variable('similar_topics', (int) $this->user->data['user_similar_topics']),
85
		]);
86
87
		// Output the data vars to the template (except on form submit)
88
		if (!$event['submit'])
89
		{
90
			$this->language->add_lang('similar_topics', 'vse/similartopics');
91
			$this->template->assign_vars([
92
				'S_SIMILAR_TOPICS'			=> $this->config['similar_topics'] && $this->auth->acl_get('u_similar_topics'),
93
				'S_DISPLAY_SIMILAR_TOPICS'	=> $event['data']['similar_topics'],
94
			]);
95
		}
96
	}
97
98
	/**
99
	 * Add user's Similar Topics option state into the sql_array
100
	 *
101
	 * @access public
102
	 * @param \phpbb\event\data $event The event object
103
	 */
104
	public function ucp_prefs_set_data($event)
105
	{
106
		$event['sql_ary'] = array_merge($event['sql_ary'], [
107
			'user_similar_topics' => $event['data']['similar_topics'],
108
		]);
109
	}
110
}
111