IspconfigChangePasswordPlugin   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 74
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 74
loc 74
rs 10
c 0
b 0
f 0
wmc 12
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A Init() 4 4 1
A Supported() 15 15 5
A MainFabrica() 23 23 5
A configMapping() 16 16 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 IspconfigChangePasswordPlugin 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
	 * @return string
12
	 */
13
	public function Supported()
14
	{
15
		if (!extension_loaded('pdo') || !class_exists('PDO'))
16
		{
17
			return 'The PHP extension PDO (mysql) must be installed to use this plugin';
18
		}
19
20
		$aDrivers = \PDO::getAvailableDrivers();
21
		if (!is_array($aDrivers) || !in_array('mysql', $aDrivers))
22
		{
23
			return 'The PHP extension PDO (mysql) must be installed to use this plugin';
24
		}
25
26
		return '';
27
	}
28
29
	/**
30
	 * @param string $sName
31
	 * @param mixed $oProvider
32
	 */
33
	public function MainFabrica($sName, &$oProvider)
34
	{
35
		switch ($sName)
36
		{
37
			case 'change-password':
38
39
				$sDsn = \trim($this->Config()->Get('plugin', 'pdo_dsn', ''));
40
				$sUser = (string) $this->Config()->Get('plugin', 'user', '');
41
				$sPassword = (string) $this->Config()->Get('plugin', 'password', '');
42
43
				if (!empty($sDsn) && 0 < \strlen($sUser) && 0 < \strlen($sPassword))
44
				{
45
					include_once __DIR__.'/IspConfigChangePasswordDriver.php';
46
47
					$oProvider = new IspConfigChangePasswordDriver();
48
					$oProvider->SetLogger($this->Manager()->Actions()->Logger());
49
					$oProvider->SetConfig($sDsn, $sUser, $sPassword);
50
					$oProvider->SetAllowedEmails(\strtolower(\trim($this->Config()->Get('plugin', 'allowed_emails', ''))));
51
				}
52
53
				break;
54
		}
55
	}
56
57
	/**
58
	 * @return array
59
	 */
60
	public function configMapping()
61
	{
62
		return array(
63
			\RainLoop\Plugins\Property::NewInstance('pdo_dsn')->SetLabel('ISPConfig PDO dsn')
64
				->SetDefaultValue('mysql:host=127.0.0.1;dbname=dbispconfig'),
65
			\RainLoop\Plugins\Property::NewInstance('user')->SetLabel('DB User')
66
				->SetDefaultValue('root'),
67
			\RainLoop\Plugins\Property::NewInstance('password')->SetLabel('DB Password')
68
				->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD)
69
				->SetDefaultValue(''),
70
			\RainLoop\Plugins\Property::NewInstance('allowed_emails')->SetLabel('Allowed emails')
71
				->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
72
				->SetDescription('Allowed emails, space as delimiter, wildcard supported. Example: [email protected] [email protected] *@domain2.net')
73
				->SetDefaultValue('*')
74
		);
75
	}
76
}