Passed
Push — development ( e156b5...b889cb )
by Spuds
01:09 queued 28s
created

MaillistSettings::saveTableSettings()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 22
rs 9.8333
c 0
b 0
f 0
cc 3
nc 3
nop 6
1
<?php
2
3
/**
4
 * Specialized version of saveDBSettings to save configVars in a table and not
5
 * an external file.
6
 * Handles saving of config vars in another table than settings.
7
 *
8
 * @package   ElkArte Forum
9
 * @copyright ElkArte Forum contributors
10
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file)
11
 *
12
 * @version 2.0 dev
13
 *
14
 */
15
16
namespace ElkArte\AdminController;
17
18
use ElkArte\SettingsForm;
19
use ElkArte\SettingsForm\SettingsFormAdapter\DbTable;
20
21
/**
22
 * Similar in construction to saveDBSettings,
23
 *
24
 * - Saves the config_vars to a specified table instead of a file
25
 * - Var names are considered the table col names,
26
 * - Values are cast per config vars
27
 * - If editing a row, the primary col index and existing index value must be
28
 *   supplied (editid and editname), otherwise a new row will be added
29
 *
30
 * @package Maillist
31
 */
32
class MaillistSettings extends SettingsForm\SettingsForm
33
{
34
	/**
35
	 * static function saveTableSettings, now part of the Settings Form class
36
	 *
37
	 * @param array $configVars the key names of the vars are the table cols
38
	 * @param string $tableName name of the table the values will be saved in
39
	 * @param array|object|null $configValues the key names of the vars are the table cols
40
	 * @param string[] $indexes for compatibility
41
	 * @param int $editId -1 add a row, otherwise edit a row with the supplied key value
42
	 * @param string $editName used when editing a row, needs to be the name of the col to find $editId
43
	 */
44
	public static function saveTableSettings(array $configVars, $tableName, $configValues = null, array $indexes = array(), $editId = -1, $editName = '')
45
	{
46
		if ($configValues === null)
47
		{
48
			$configValues = $_POST;
49
		}
50
		elseif (is_object($configValues))
51
		{
52
			$configValues = (array) $configValues;
53
		}
54
55
		$settingsForm = new self(self::DBTABLE_ADAPTER);
56
		/** @var DbTable $settingsAdapter */
57
		$settingsAdapter = $settingsForm->getAdapter();
58
		$settingsAdapter->setTableName($tableName);
59
		$settingsAdapter->setEditId($editId);
60
		$settingsAdapter->setEditName($editName);
61
		$settingsAdapter->setIndexes($indexes);
62
63
		$settingsForm->setConfigVars($configVars);
64
		$settingsForm->setConfigValues($configValues);
0 ignored issues
show
Bug introduced by
It seems like $configValues can also be of type null; however, parameter $configValues of ElkArte\SettingsForm\Set...Form::setConfigValues() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

64
		$settingsForm->setConfigValues(/** @scrutinizer ignore-type */ $configValues);
Loading history...
65
		$settingsForm->save();
66
	}
67
}
68