Completed
Push — master ( 59c197...ef601c )
by Rain
20:42 queued 12:08
created

MailInABoxChangePasswordPlugin   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 46
loc 46
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A Init() 4 4 1
A MainFabrica() 16 16 2
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
 * Mail-in-a-box Password Change Plugin
4
 *
5
 * Based on VirtualminChangePassword
6
 *
7
 * Author: Marius Gripsgard
8
 */
9 View Code Duplication
class MailInABoxChangePasswordPlugin 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...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
10
{
11
	public function Init()
12
	{
13
		$this->addHook('main.fabrica', 'MainFabrica');
14
	}
15
	/**
16
	 * @param string $sName
17
	 * @param mixed $oProvider
18
	 */
19
	public function MainFabrica($sName, &$oProvider)
20
	{
21
		switch ($sName)
22
		{
23
			case 'change-password':
24
				include_once __DIR__.'/MailInABoxChangePasswordDriver.php';
25
				$sHost = \trim($this->Config()->Get('plugin', 'host', ''));
26
				$sAdminUser = (string) $this->Config()->Get('plugin', 'admin_user', '');
27
				$sAdminPassword = (string) $this->Config()->Get('plugin', 'admin_password', '');
28
				$oProvider = new \MailInABoxChangePasswordDriver();
29
				$oProvider->SetLogger($this->Manager()->Actions()->Logger());
30
				$oProvider->SetConfig($sHost, $sAdminUser, $sAdminPassword);
31
				$oProvider->SetAllowedEmails(\strtolower(\trim($this->Config()->Get('plugin', 'allowed_emails', ''))));
32
				break;
33
		}
34
	}
35
	/**
36
	 * @return array
37
	 */
38
	public function configMapping()
39
	{
40
		return array(
41
			\RainLoop\Plugins\Property::NewInstance('host')->SetLabel('Mail-in-a-box Host')
42
					->SetDefaultValue('https://box.mailinabox.email')
43
					->SetDescription('Mail-in-a-box host URL. Example: https://box.mailinabox.email'),
44
			\RainLoop\Plugins\Property::NewInstance('admin_user')->SetLabel('Admin User')
45
					->SetDefaultValue(''),
46
			\RainLoop\Plugins\Property::NewInstance('admin_password')->SetLabel('Admin Password')
47
					->SetDefaultValue(''),
48
			\RainLoop\Plugins\Property::NewInstance('allowed_emails')->SetLabel('Allowed emails')
49
				->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
50
				->SetDescription('Allowed emails, space as delimiter, wildcard supported. Example: [email protected] [email protected] *@domain2.net')
51
				->SetDefaultValue('*')
52
		);
53
	}
54
}
55