Completed
Pull Request — master (#3325)
by Emanuele
11:19
created

Verification_PersonalMessage_Module   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 67
Duplicated Lines 47.76 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 32
loc 67
ccs 0
cts 39
cp 0
rs 10
c 0
b 0
f 0
wmc 9
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A before_sending() 0 17 4
A hooks() 0 17 4
A prepare_send_context() 0 12 1

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
 *
5
 *
6
 * @name      ElkArte Forum
7
 * @copyright ElkArte Forum contributors
8
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause
9
 *
10
 * This file contains code covered by:
11
 * copyright:	2011 Simple Machines (http://www.simplemachines.org)
12
 * license:  	BSD, See included LICENSE.TXT for terms and conditions.
13
 *
14
 * @version 1.1
15
 *
16
 */
17
18
/**
19
 * Class Verification_PersonalMessage_Module
20
 *
21
 * Adds Visual Verification controls to the PM page for those that need it.
22
 */
23
class Verification_PersonalMessage_Module extends ElkArte\sources\modules\Abstract_Module
24
{
25
	/**
26
	 * {@inheritdoc }
27
	 */
28
	public static function hooks(\Event_Manager $eventsManager)
29
	{
30
		global $user_info, $modSettings;
31
32
		// Are controls required?
33
		if (!$user_info['is_admin'] && !empty($modSettings['pm_posts_verification']) && $user_info['posts'] < $modSettings['pm_posts_verification'])
34
		{
35
			require_once(SUBSDIR . '/VerificationControls.class.php');
36
37
			// Add the events to call for the verification
38
			return array(
39
				array('prepare_send_context', array('Verification_PersonalMessage_Module', 'prepare_send_context'), array()),
40
				array('before_sending', array('Verification_PersonalMessage_Module', 'before_sending'), array('post_errors')),
41
			);
42
		}
43
		else
44
			return array();
45
	}
46
47
	/**
48
	 * Prepare $context for the PM page.
49
	 */
50
	public function prepare_send_context()
51
	{
52
		global $context;
53
54
		// Verification control needed for this PM?
55
		$context['require_verification'] = true;
56
57
		$verificationOptions = array(
58
			'id' => 'pm',
59
		);
60
		$context['require_verification'] = create_control_verification($verificationOptions);
61
		$context['visual_verification_id'] = $verificationOptions['id'];
62
	}
63
64
	/**
65
	 * Checks the user passed the verifications on the PM page.
66
	 *
67
	 * @param \ErrorContext $post_errors
0 ignored issues
show
Bug introduced by
The type ErrorContext 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...
68
	 * @throws Elk_Exception
69
	 */
70
	public function before_sending($post_errors)
71
	{
72
		global $context;
73
74
		if (isset($_REQUEST['xml']))
75
			return;
76
77
		// Wrong verification code?
78
		$verificationOptions = array(
79
			'id' => 'pm',
80
		);
81
		$context['require_verification'] = create_control_verification($verificationOptions, true);
82
83
		if (is_array($context['require_verification']))
84
		{
85
			foreach ($context['require_verification'] as $error)
86
				$post_errors->addError($error);
87
		}
88
	}
89
}
90