Completed
Pull Request — master (#841)
by Blizzz
10:54 queued 01:57
created

Admin::getForm()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 17
nc 2
nop 0
dl 0
loc 24
rs 8.9713
c 1
b 0
f 0
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
35
	/** @var IL10N */
36
	private $l;
37
38
	public function __construct(IL10N $l) {
39
		$this->l = $l;
40
	}
41
42
	/**
43
	 * @return TemplateResponse
44
	 */
45
	public function getForm() {
46
		$helper = new Helper();
47
		$prefixes = $helper->getServerConfigurationPrefixes();
48
		$hosts = $helper->getServerConfigurationHosts();
49
50
		$wControls = new Template('user_ldap', 'part.wizardcontrols');
51
		$wControls = $wControls->fetchPage();
52
		$sControls = new Template('user_ldap', 'part.settingcontrols');
53
		$sControls = $sControls->fetchPage();
54
55
		$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...
56
		$parameters['serverConfigurationHosts'] = $hosts;
57
		$parameters['settingControls'] = $sControls;
58
		$parameters['wizardControls'] = $wControls;
59
60
		// assign default values
61
		$config = new Configuration('', false);
62
		$defaults = $config->getDefaults();
63
		foreach($defaults as $key => $default) {
64
			$parameters[$key.'_default'] = $default;
65
		}
66
67
		return new TemplateResponse('user_ldap', 'settings', $parameters);
68
	}
69
70
	/**
71
	 * @return string the section ID, e.g. 'sharing'
72
	 */
73
	public function getSection() {
74
		return 'ldap';
75
	}
76
77
	/**
78
	 * @return int whether the form should be rather on the top or bottom of
79
	 * the admin section. The forms are arranged in ascending order of the
80
	 * priority values. It is required to return a value between 0 and 100.
81
	 *
82
	 * E.g.: 70
83
	 */
84
	public function getPriority() {
85
		return 5;
86
	}
87
88
	private function renderControls() {
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
89
		$controls = new Template('user_ldap', 'part.settingcontrols');
90
		return $controls->fetchPage();
91
92
	}
93
}
94