Completed
Push — master ( 9db189...2d861c )
by Lukas
24s
created

Admin   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 57
rs 10
wmc 5
lcom 0
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B getForm() 0 24 2
A getSection() 0 3 1
A getPriority() 0 3 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016 Arthur Schiwon <[email protected]>
4
 *
5
 * @author Arthur Schiwon <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 * This program is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License as
11
 * published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\User_LDAP\Settings;
25
26
use OCA\User_LDAP\Configuration;
27
use OCA\User_LDAP\Helper;
28
use OCP\AppFramework\Http\TemplateResponse;
29
use OCP\IL10N;
30
use OCP\Settings\ISettings;
31
use OCP\Template;
32
33
class Admin implements ISettings {
34
	/** @var IL10N */
35
	private $l;
36
37
	/**
38
	 * @param IL10N $l
39
	 */
40
	public function __construct(IL10N $l) {
41
		$this->l = $l;
42
	}
43
44
	/**
45
	 * @return TemplateResponse
46
	 */
47
	public function getForm() {
48
		$helper = new Helper();
49
		$prefixes = $helper->getServerConfigurationPrefixes();
50
		$hosts = $helper->getServerConfigurationHosts();
51
52
		$wControls = new Template('user_ldap', 'part.wizardcontrols');
53
		$wControls = $wControls->fetchPage();
54
		$sControls = new Template('user_ldap', 'part.settingcontrols');
55
		$sControls = $sControls->fetchPage();
56
57
		$parameters['serverConfigurationPrefixes'] = $prefixes;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
58
		$parameters['serverConfigurationHosts'] = $hosts;
59
		$parameters['settingControls'] = $sControls;
60
		$parameters['wizardControls'] = $wControls;
61
62
		// assign default values
63
		$config = new Configuration('', false);
64
		$defaults = $config->getDefaults();
65
		foreach($defaults as $key => $default) {
66
			$parameters[$key.'_default'] = $default;
67
		}
68
69
		return new TemplateResponse('user_ldap', 'settings', $parameters);
70
	}
71
72
	/**
73
	 * @return string the section ID, e.g. 'sharing'
74
	 */
75
	public function getSection() {
76
		return 'ldap';
77
	}
78
79
	/**
80
	 * @return int whether the form should be rather on the top or bottom of
81
	 * the admin section. The forms are arranged in ascending order of the
82
	 * priority values. It is required to return a value between 0 and 100.
83
	 *
84
	 * E.g.: 70
85
	 */
86
	public function getPriority() {
87
		return 5;
88
	}
89
}
90