mcp_listener   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 77
Duplicated Lines 38.96 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 1
dl 30
loc 77
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getSubscribedEvents() 0 10 1
A assign_topic_attributes_mcp() 10 10 2
A mcp_main_modify_fork_sql() 10 10 1
A mcp_main_modify_shadow_sql() 10 10 1
A mcp_select_assign_attributes() 0 12 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
*
4
* @package Quick Title Edition Extension
5
* @copyright (c) 2015 ABDev
6
* @copyright (c) 2015 PastisD
7
* @copyright (c) 2015 Geolim4 <http://geolim4.com>
8
* @copyright (c) 2015 Zoddo <[email protected]>
9
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
10
*
11
*/
12
13
namespace ernadoo\qte\event;
14
15
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
16
17
class mcp_listener implements EventSubscriberInterface
18
{
19
	/** @var \phpbb\request\request */
20
	protected $request;
21
22
	/** @var \ernadoo\qte\qte */
23
	protected $qte;
24
25
	/**
26
	* Constructor
27
	*
28
	* @param \phpbb\request\request					$request			Request object
29
	* @param \ernadoo\qte\qte						$qte				QTE object
30
	*/
31
	public function __construct(\phpbb\request\request $request, \ernadoo\qte\qte $qte)
32
	{
33
		$this->request	= $request;
34
		$this->qte		= $qte;
35
	}
36
37
	static public function getSubscribedEvents()
38
	{
39
		return array(
40
			// MCP
41
			'core.mcp_main_modify_fork_sql'			=> 'mcp_main_modify_fork_sql',
42
			'core.mcp_main_modify_shadow_sql'		=> 'mcp_main_modify_shadow_sql',
43
			'core.mcp_view_forum_modify_topicrow'	=> 'assign_topic_attributes_mcp',
44
			'core.mcp_forum_view_before'			=> 'mcp_select_assign_attributes',
45
		);
46
	}
47
48 View Code Duplication
	public function assign_topic_attributes_mcp($event)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
	{
50
		if (!empty($event['row']['topic_attr_id']))
51
		{
52
			$this->qte->get_users_by_user_id($event['row']['topic_attr_user']);
53
			$topic_row = $event['topic_row'];
54
			$topic_row['MCP_TOPIC_ATTRIBUTE'] = $this->qte->attr_display($event['row']['topic_attr_id'], $event['row']['topic_attr_user'], $event['row']['topic_attr_time']);
55
			$event['topic_row'] = $topic_row;
56
		}
57
	}
58
59 View Code Duplication
	public function mcp_main_modify_fork_sql($event)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
60
	{
61
		$sql_ary = $event['sql_ary'];
62
63
		$sql_ary['topic_attr_id']	= $event['topic_row']['topic_attr_id'];
64
		$sql_ary['topic_attr_user'] = $event['topic_row']['topic_attr_user'];
65
		$sql_ary['topic_attr_time'] = $event['topic_row']['topic_attr_time'];
66
67
		$event['sql_ary'] = $sql_ary;
68
	}
69
70 View Code Duplication
	public function mcp_main_modify_shadow_sql($event)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
71
	{
72
		$shadow = $event['shadow'];
73
74
		$shadow['topic_attr_id']	= $event['row']['topic_attr_id'];
75
		$shadow['topic_attr_user']	= $event['row']['topic_attr_user'];
76
		$shadow['topic_attr_time']	= $event['row']['topic_attr_time'];
77
78
		$event['shadow'] = $shadow;
79
	}
80
81
	public function mcp_select_assign_attributes($event)
82
	{
83
		$attr_id	= (int) $this->request->variable('attr_id', 0);
84
		$forum_id	= (int) $event['forum_info']['forum_id'];
85
86
		if ($attr_id)
87
		{
88
			$this->qte->mcp_attr_apply($attr_id, $forum_id, $event['topic_id_list']);
89
		}
90
91
		$this->qte->attr_select($forum_id);
92
	}
93
}
94