preview   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 124
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 15
eloc 28
dl 0
loc 124
rs 10
c 2
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A viewforum_row() 0 3 1
A getSubscribedEvents() 0 13 1
A searchresults_tpl() 0 5 3
A searchresults_row() 0 5 3
A similartopics_tpl() 0 5 2
A similartopics_row() 0 5 2
A viewforum_tpl() 0 3 1
A __construct() 0 5 1
A init_tpl_vars() 0 5 1
1
<?php
2
/**
3
 *
4
 * Topic Image Preview. An extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2017, 2020, Matt Friedman
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace vse\topicimagepreview\event;
12
13
use 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...
14
use 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...
15
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...
16
17
/**
18
 * Topic Image Preview Event listener.
19
 */
20
class preview implements EventSubscriberInterface
21
{
22
	/** @var config */
23
	protected $config;
24
25
	/** @var helper */
26
	protected $helper;
27
28
	/** @var template */
29
	protected $template;
30
31
	/**
32
	 * {@inheritdoc}
33
	 */
34
	public static function getSubscribedEvents()
35
	{
36
		return [
37
			'core.page_footer'						=> 'init_tpl_vars',
38
			// Viewforum events
39
			'core.viewforum_modify_topics_data'		=> 'viewforum_row',
40
			'core.viewforum_modify_topicrow'		=> 'viewforum_tpl',
41
			// Search events
42
			'core.search_modify_rowset'				=> 'searchresults_row',
43
			'core.search_modify_tpl_ary'			=> 'searchresults_tpl',
44
			// Precise Similar Topics events
45
			'vse.similartopics.modify_rowset'		=> 'similartopics_row',
46
			'vse.similartopics.modify_topicrow'		=> 'similartopics_tpl',
47
		];
48
	}
49
50
	/**
51
	 * Constructor
52
	 *
53
	 * @param config   $config
54
	 * @param helper   $helper
55
	 * @param template $template
56
	 */
57
	public function __construct(config $config, helper $helper, template $template)
58
	{
59
		$this->config = $config;
60
		$this->helper = $helper;
61
		$this->template = $template;
62
	}
63
64
	/**
65
	 * Set some template variables for T.I.P.
66
	 */
67
	public function init_tpl_vars()
68
	{
69
		$this->template->assign_vars([
70
			'S_TOPIC_IMAGE_PREVIEW'		=> $this->helper->is_preview(),
71
			'TOPIC_IMAGE_PREVIEW_DIM'	=> $this->config['vse_tip_dim'],
72
		]);
73
	}
74
75
	/**
76
	 * Update viewforum row
77
	 *
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 viewforum_row($event)
81
	{
82
		$this->helper->update_row_data($event);
83
	}
84
85
	/**
86
	 * Update viewforum template
87
	 *
88
	 * @param \phpbb\event\data $event The event object
89
	 */
90
	public function viewforum_tpl($event)
91
	{
92
		$this->helper->update_tpl_data($event);
93
	}
94
95
	/**
96
	 * Update search results topics row
97
	 *
98
	 * @param \phpbb\event\data $event The event object
99
	 */
100
	public function searchresults_row($event)
101
	{
102
		if ($event['show_results'] === 'topics' && $this->config->offsetGet('vse_tip_srt'))
103
		{
104
			$this->helper->update_row_data($event);
105
		}
106
	}
107
108
	/**
109
	 * Update search results topics template
110
	 *
111
	 * @param \phpbb\event\data $event The event object
112
	 */
113
	public function searchresults_tpl($event)
114
	{
115
		if ($event['show_results'] === 'topics' && $this->config->offsetGet('vse_tip_srt'))
116
		{
117
			$this->helper->update_tpl_data($event);
118
		}
119
	}
120
121
	/**
122
	 * Update similar topics row
123
	 *
124
	 * @param \phpbb\event\data $event The event object
125
	 */
126
	public function similartopics_row($event)
127
	{
128
		if ($this->config->offsetGet('vse_tip_pst'))
129
		{
130
			$this->helper->update_row_data($event);
131
		}
132
	}
133
134
	/**
135
	 * Update similar topics template
136
	 *
137
	 * @param \phpbb\event\data $event The event object
138
	 */
139
	public function similartopics_tpl($event)
140
	{
141
		if ($this->config->offsetGet('vse_tip_pst'))
142
		{
143
			$this->helper->update_tpl_data($event);
144
		}
145
	}
146
}
147