listener::getSubscribedEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 5
Bugs 0 Features 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 23
rs 9.8666
c 5
b 0
f 0
ccs 12
cts 12
cp 1
crap 1
1
<?php
2
/**
3
 *
4
 * Topic Preview
5
 *
6
 * @copyright (c) 2013 Matt Friedman
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace vse\topicpreview\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
use vse\topicpreview\core\data;
15
use vse\topicpreview\core\display;
16
17
/**
18
 * Event listener
19
 */
20
class listener implements EventSubscriberInterface
21
{
22
	/** @var data */
23
	protected $preview_data;
24
25
	/** @var display */
26
	protected $preview_display;
27
28
	/**
29
	 * Constructor
30
	 *
31
	 * @param data    $preview_data    Topic Preview data object
32
	 * @param display $preview_display Topic Preview display object
33
	 */
34 5
	public function __construct(data $preview_data, display $preview_display)
35
	{
36 5
		$this->preview_data = $preview_data;
37 5
		$this->preview_display = $preview_display;
38 5
	}
39
40
	/**
41
	 * Assign functions defined in this class to event listeners in the core
42
	 *
43
	 * @return array
44
	 */
45 1
	public static function getSubscribedEvents()
46
	{
47
		return array(
48
			// viewforum.php events
49 1
			'core.viewforum_get_topic_data'			=> 'modify_sql_array',
50 1
			'core.viewforum_get_shadowtopic_data'	=> 'modify_sql_array',
51 1
			'core.viewforum_modify_topicrow'		=> 'display_topic_previews',
52
53
			// search.php events
54 1
			'core.search_get_topic_data'			=> 'modify_sql_string',
55 1
			'core.search_modify_tpl_ary'			=> 'display_topic_previews',
56
57
			// Custom events for integration with Precise Similar Topics
58 1
			'vse.similartopics.get_topic_data'		=> 'modify_sql_array',
59 1
			'vse.similartopics.modify_topicrow'		=> 'display_topic_previews',
60
61
			// Custom events for integration with Recent Topics
62 1
			'paybas.recenttopics.sql_pull_topics_data'	=> 'modify_sql_array',
63 1
			'paybas.recenttopics.modify_tpl_ary'		=> 'display_topic_previews',
64
65
			// Custom events for integration with Top Five
66 1
			'rmcgirr83.topfive.sql_pull_topics_data'	=> 'modify_sql_array',
67 1
			'rmcgirr83.topfive.modify_tpl_ary'			=> 'display_topic_previews',
68 1
		);
69
	}
70
71
	/**
72
	 * Modify an SQL array to get post text for topic previews
73
	 *
74
	 * @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...
75
	 */
76 1
	public function modify_sql_array($event)
77
	{
78 1
		$event['sql_array'] = $this->preview_data->modify_sql($event['sql_array'], 'SELECT');
79 1
	}
80
81
	/**
82
	 * Modify SQL strings to get post text for topic previews (search results)
83
	 *
84
	 * @param \phpbb\event\data $event The event object
85
	 */
86 1
	public function modify_sql_string($event)
87
	{
88 1
		$event['sql_select'] = $this->preview_data->modify_sql($event['sql_select'], 'SELECT');
89 1
		$event['sql_from'] = $this->preview_data->modify_sql($event['sql_from'], 'JOIN');
90 1
	}
91
92
	/**
93
	 * Modify template vars to display topic previews
94
	 *
95
	 * @param \phpbb\event\data $event The event object
96
	 */
97 2
	public function display_topic_previews($event)
98
	{
99 2
		$block = $event['topic_row'] ? 'topic_row' : 'tpl_ary';
100 2
		$event[$block] = $this->preview_display->display_topic_preview($event['row'], $event[$block]);
101 2
	}
102
}
103