DirectadminChangePasswordPlugin   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 53
loc 53
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A Init() 4 4 1
A MainFabrica() 22 22 4
A configMapping() 15 15 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 View Code Duplication
class DirectadminChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin
0 ignored issues
show
Duplication introduced by
This class 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...
4
{
5
	public function Init()
6
	{
7
		$this->addHook('main.fabrica', 'MainFabrica');
8
	}
9
10
	/**
11
	 * @param string $sName
12
	 * @param mixed $oProvider
13
	 */
14
	public function MainFabrica($sName, &$oProvider)
15
	{
16
		switch ($sName)
17
		{
18
			case 'change-password':
19
20
				$sHost = \trim($this->Config()->Get('plugin', 'direct_admin_host', ''));
21
				$iPort = (int) $this->Config()->Get('plugin', 'direct_admin_port', 2222);
22
23
				if (!empty($sHost) && 0 < $iPort)
24
				{
25
					include_once __DIR__.'/DirectAdminChangePasswordDriver.php';
26
27
					$oProvider = new DirectAdminChangePasswordDriver();
28
					$oProvider->SetLogger($this->Manager()->Actions()->Logger());
29
					$oProvider->SetConfig($sHost, $iPort);
30
					$oProvider->SetAllowedEmails(\strtolower(\trim($this->Config()->Get('plugin', 'allowed_emails', ''))));
31
				}
32
33
				break;
34
		}
35
	}
36
37
	/**
38
	 * @return array
39
	 */
40
	public function configMapping()
41
	{
42
		return array(
43
			\RainLoop\Plugins\Property::NewInstance('direct_admin_host')->SetLabel('DirectAdmin Host')
44
				->SetDefaultValue('')
45
				->SetDescription('Allowed patterns: {user:host-imap}, {user:host-smtp}, {user:domain}'),
46
			\RainLoop\Plugins\Property::NewInstance('direct_admin_port')->SetLabel('DirectAdmin Port')
47
				->SetType(\RainLoop\Enumerations\PluginPropertyType::INT)
48
				->SetDefaultValue(2222),
49
			\RainLoop\Plugins\Property::NewInstance('allowed_emails')->SetLabel('Allowed emails')
50
				->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
51
				->SetDescription('Allowed emails, space as delimiter, wildcard supported. Example: [email protected] [email protected] *@domain2.net')
52
				->SetDefaultValue('*')
53
		);
54
	}
55
}