mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2025-01-03 14:32:40 +00:00
use list() instead of extract()
Improves clarity where Database::generateSet() is actually used at the expense of clarity within the method itself
This commit is contained in:
parent
929d763981
commit
e6f2f22888
1 changed files with 11 additions and 13 deletions
|
@ -16,17 +16,17 @@ class Database {
|
||||||
|
|
||||||
protected function generateSet(array $props, array $valid): array {
|
protected function generateSet(array $props, array $valid): array {
|
||||||
$out = [
|
$out = [
|
||||||
'setValues' => [],
|
[], // query clause
|
||||||
'setTypes' => [],
|
[], // binding types
|
||||||
'set' => [],
|
[], // binding values
|
||||||
];
|
];
|
||||||
foreach($valid as $prop => $type) {
|
foreach($valid as $prop => $type) {
|
||||||
if(!array_key_exists($prop, $props)) continue;
|
if(!array_key_exists($prop, $props)) continue;
|
||||||
$out['setValues'][] = $props[$prop];
|
$out[0][] = "$prop = ?";
|
||||||
$out['setTypes'][] = $type;
|
$out[1][] = $type;
|
||||||
$out['set'][] = "$prop = ?";
|
$out[2][] = $props[$prop];
|
||||||
}
|
}
|
||||||
$out['set'] = implode(", ", $out['set']);
|
$out[0] = implode(", ", $out[0]);
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,9 +249,8 @@ class Database {
|
||||||
$valid = [ // FIXME: add future properties
|
$valid = [ // FIXME: add future properties
|
||||||
"name" => "str",
|
"name" => "str",
|
||||||
];
|
];
|
||||||
$data = $this->generateSet($properties, $valid);
|
list($setClause, $setTypes, $setValues) = $this->generateSet($properties, $valid);
|
||||||
extract($data);
|
$this->db->prepare("UPDATE arsse_users set $setClause where id is ?", $setTypes, "str")->run($setValues, $user);
|
||||||
$this->db->prepare("UPDATE arsse_users set $set where id is ?", $setTypes, "str")->run($setValues, $user);
|
|
||||||
return $this->userPropertiesGet($user);
|
return $this->userPropertiesGet($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,9 +381,8 @@ class Database {
|
||||||
'name' => "str",
|
'name' => "str",
|
||||||
'parent' => "int",
|
'parent' => "int",
|
||||||
];
|
];
|
||||||
$data = $this->generateSet($data, $valid);
|
list($setClause, $setTypes, $setValues) = $this->generateSet($data, $valid);
|
||||||
extract($data);
|
$this->db->prepare("UPDATE arsse_folders set $setClause where owner is ? and id is ?", $setTypes, "str", "int")->run($setValues, $user, $id);
|
||||||
$this->db->prepare("UPDATE arsse_folders set $set where owner is ? and id is ?", $setTypes, "str", "int")->run($setValues, $user, $id);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue