Completed
Push — master ( 6eda29...c67cfb )
by Rain
08:12 queued 02:08
created

FroxlorchangePasswordPlugin::configMapping()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 13

Duplication

Lines 16
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 0
dl 16
loc 16
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
class FroxlorchangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin
0 ignored issues
show
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...
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 exention 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 exention 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':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
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__.'/FroxlorChangePasswordDriver.php';
46
47
					$oProvider = new FroxlorChangePasswordDriver();
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 View Code Duplication
	public function configMapping()
0 ignored issues
show
Duplication introduced by
This method 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...
61
	{
62
		return array(
63
			\RainLoop\Plugins\Property::NewInstance('pdo_dsn')->SetLabel('Froxlor PDO dsn')
64
				->SetDefaultValue('mysql:host=127.0.0.1;dbname=froxlor'),
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
}
77