BlackListPlugin   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 50
loc 50
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A Init() 4 4 1
A FilterLoginCredentials() 14 14 6
A configMapping() 17 17 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 BlackListPlugin 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('filter.login-credentials', 'FilterLoginCredentials');
8
	}
9
10
	/**
11
	 * @param string $sEmail
12
	 * @param string $sLogin
13
	 * @param string $sPassword
14
	 *
15
	 * @throws \RainLoop\Exceptions\ClientException
16
	 */
17
	public function FilterLoginCredentials(&$sEmail, &$sLogin, &$sPassword)
18
	{
19
		$sBlackList = \trim($this->Config()->Get('plugin', 'black_list', ''));
20
		if (0 < \strlen($sBlackList) && \RainLoop\Plugins\Helper::ValidateWildcardValues($sEmail, $sBlackList))
21
		{
22
			$sExceptions = \trim($this->Config()->Get('plugin', 'exceptions', ''));
23
			if (0 === \strlen($sExceptions) || !\RainLoop\Plugins\Helper::ValidateWildcardValues($sEmail, $sExceptions))
24
			{
25
				throw new \RainLoop\Exceptions\ClientException(
26
					$this->Config()->Get('plugin', 'auth_error', true) ?
27
						\RainLoop\Notifications::AuthError : \RainLoop\Notifications::AccountNotAllowed);
28
			}
29
		}
30
	}
31
32
	/**
33
	 * @return array
34
	 */
35
	public function configMapping()
36
	{
37
		return array(
38
			\RainLoop\Plugins\Property::NewInstance('auth_error')->SetLabel('Auth Error')
39
				->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
40
				->SetDescription('Throw an authentication error instead of an access error.')
41
				->SetDefaultValue(true),
42
			\RainLoop\Plugins\Property::NewInstance('black_list')->SetLabel('Black List')
43
				->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
44
				->SetDescription('Emails black list, space as delimiter, wildcard supported.')
45
				->SetDefaultValue('*@domain1.com [email protected]'),
46
			\RainLoop\Plugins\Property::NewInstance('exceptions')->SetLabel('Exceptions')
47
				->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
48
				->SetDescription('Exceptions for black list, space as delimiter, wildcard supported.')
49
				->SetDefaultValue('[email protected] *@domain2.com admin@*')
50
		);
51
	}
52
}
53