Commit c29f4ef4 authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic Committed by Ghada El-Zoghbi

Bug 1648679: Avoiding "Passed by reference" error

Fixed lines of code that threw the error
"Only variables should be passed by reference"
and other errors found.

behatnotneeded

Change-Id: I23e6a3c1b2ef97bf2cae29c15814fcdb79d5676f
parent 552d6e93
......@@ -196,7 +196,8 @@ function addfontform_validate(Pieform $form, $values) {
}
// Check that all the needed files exist in the zip file
foreach ($check as $key => $item) {
if (end(explode('.', $zip->getNameIndex($i))) == $item['suffix']) {
$name_explode = explode('.', $zip->getNameIndex($i));
if (end($name_explode) == $item['suffix']) {
$check[$key]['found'] = true;
}
}
......@@ -256,7 +257,8 @@ function addfontform_submit(Pieform $form, $values) {
// Check that all the needed files exist in the zip file
$check = uploadfiles_info();
foreach ($check as $key => $item) {
if (end(explode('.', $zip->getNameIndex($i))) == $item['suffix']) {
$name_explode = explode('.', $zip->getNameIndex($i));
if (end($name_explode) == $item['suffix']) {
// Extract font file
$zip->extractTo($fontpath, $zip->getNameIndex($i));
$values['fontfile' . strtoupper($item['suffix'])]['name'] = $zip->getNameIndex($i);
......
......@@ -24,7 +24,8 @@ define('DEFAULTPAGE', 'home');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['license_delete'])) {
$del = array_shift(array_keys($_POST['license_delete']));
$license_delete_array_keys = array_keys($_POST['license_delete']);
$del = array_shift($license_delete_array_keys);
delete_records('artefact_license', 'name', $del);
$SESSION->add_ok_msg(get_string('licensedeleted', 'admin'));
}
......
......@@ -420,7 +420,8 @@ class LeapImportBlog extends LeapImportArtefactPlugin {
'title' => (string)$blogpostentry->title . ' ' . get_string('attachment', 'artefact.blog'),
'owner' => $importer->get('usr'),
);
$data->oldextension = end(explode('.', $data->title));
$explode_title = explode('.', $data->title);
$data->oldextension = end($explode_title);
return ArtefactTypeFile::save_file($pathname, $data, $importer->get('usrobj'), true);
}
......
......@@ -471,7 +471,9 @@ class PluginExportLeap extends PluginExport {
}
else if (isset($blockinstance['config']['artefactids'])) {
$ids = json_decode($blockinstance['config']['artefactids']);
$blockinstance['config']['artefactids'] = json_encode(array(array_map(array($this, 'prepend_artefact_identifier'), $ids[0])));
if ($ids[0]) {
$blockinstance['config']['artefactids'] = json_encode(array(array_map(array($this, 'prepend_artefact_identifier'), $ids[0])));
}
}
}
} // cols
......
......@@ -97,9 +97,10 @@ class PluginImportFile extends PluginImport {
$savedfiles = array(); // to put files into so we can delete them should we encounter an exception
foreach ($this->files as $f) {
try {
$explode_wantsfilename = explode('.', $f->wantsfilename);
$data = (object)array(
'title' => $f->wantsfilename,
'oldextension' => end(explode('.', $f->wantsfilename)),
'oldextension' => end($explode_wantsfilename),
'description' => $f->wantsfilename . ' (' . get_string('importedfrom', 'mahara', $this->get('importertransport')->get_description()) . ')',
'parent' => $this->importdir,
'owner' => $this->get('usr'),
......
......@@ -2055,7 +2055,8 @@ class PluginImportLeap extends PluginImport {
'title' => (string)$entry->title . ' ' . get_string('attachment'),
'owner' => $this->get('usr'),
);
$data->oldextension = end(explode('.', $data->title));
$title_explode = explode('.', $data->title);
$data->oldextension = end($title_explode);
return ArtefactTypeFile::save_file($pathname, $data, $this->get('usrobj'), true);
}
......
......@@ -279,7 +279,8 @@ function file_mime_type($file, $originalfilename=false) {
if (is_null($mimetypes)) {
$mimetypes = get_records_assoc('artefact_file_mime_types', '', '', '', 'description,mimetype');
}
$ext = strtolower(array_pop(explode('.', $basename)));
$basename_explode = explode('.', $basename);
$ext = strtolower(array_pop($basename_explode));
if (isset($mimetypes[$ext])) {
return $mimetypes[$ext]->mimetype;
}
......
......@@ -441,7 +441,8 @@ function get_helpfile_location($plugintype, $pluginname, $form, $element, $page=
// if it's a block instance config form element, try the wildcard form name
// and element without it's prefixes
if (preg_match('/^instconf_/', $element)) {
$element = end(explode('_', $element));
$element_explode = explode('_', $element);
$element = end($element_explode);
}
return get_helpfile_location('core', '', 'ANY', $element, $page, $section);
}
......
......@@ -362,7 +362,8 @@ $typeopts = array();
foreach (array('rest', 'soap', 'xmlrpc') as $proto) {
$typeopts[$proto] = get_string($proto, 'auth.webservice');
}
$default_type = (empty($dbconnection->type) ? array_shift(array_keys($typeopts)) : $dbconnection->type);
$typeopts_keys = array_keys($typeopts);
$default_type = (empty($dbconnection->type) ? array_shift($typeopts_keys) : $dbconnection->type);
$connection_details['elements']['type'] = array(
'type' => 'select',
'title' => get_string('type', 'auth.webservice'),
......
......@@ -29,8 +29,10 @@ if (empty($dbserviceuser)) {
$services = get_records_array('external_services', 'restrictedusers', 1);
$sopts = array();
foreach ($services as $service) {
$sopts[$service->id] = $service->name;
if ($services) {
foreach ($services as $service) {
$sopts[$service->id] = $service->name;
}
}
$dbuser = get_record('usr', 'id', $dbserviceuser->userid);
......@@ -50,7 +52,8 @@ if (isset($dbserviceuser->externalserviceid)) {
}
else {
$serviceenabled = 0;
$defaultserviceid = array_pop(array_keys($sopts));
$sopts_keys = array_keys($sopts);
$defaultserviceid = array_pop($sopts_keys);
$restrictedusers = 0;
}
......
......@@ -77,7 +77,6 @@ function build_webservice_log_search_results($search) {
$smarty = smarty_core();
$smarty->assign('results', $results);
$smarty->assign('institutions', $institutions);
$smarty->assign('searchurl', $searchurl);
$smarty->assign('sortby', $search->sortby);
$smarty->assign('sortdir', $search->sortdir);
......
......@@ -907,7 +907,8 @@ class mahara_user_external extends external_api {
*/
public static function get_my_user() {
global $USER;
return array_shift(self::get_users_by_id(array(array('id' => $USER->get('id')))));
$users_by_id = self::get_users_by_id(array(array('id' => $USER->get('id'))));
return array_shift($users_by_id);
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment