Skip to content

Commit

Permalink
Dev: More default string values instead of type-cast
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Mar 28, 2023
1 parent 4741ba8 commit a1c0068
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 81 deletions.
6 changes: 3 additions & 3 deletions application/controllers/admin/ConditionsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function index($subaction, $iSurveyID = null, $gid = null, $qid = null)
if (!in_array($request->getPost('method'), array_keys($method))) {
$p_method = "==";
} else {
$p_method = trim((string) $request->getPost('method'));
$p_method = trim($request->getPost('method', ''));
}
} else {
$p_method = null;
Expand Down Expand Up @@ -927,8 +927,8 @@ protected function getQuickAddData(LSHttpRequest $request)
'tokenAttr'
);
foreach ($keys as $key) {
$value = $request->getPost('quick-add-' . $key);
$value = str_replace('QUICKADD-', '', (string) $value); // Remove QUICKADD- from editSourceTab/editTargetTab
$value = $request->getPost('quick-add-' . $key, '');
$value = str_replace('QUICKADD-', '', $value); // Remove QUICKADD- from editSourceTab/editTargetTab
$result[$key] = $value;
}

Expand Down
4 changes: 2 additions & 2 deletions application/controllers/admin/DataEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,9 @@ public function editdata($subaction, $id, $surveyid)
$results[] = $idresult->attributes;
} elseif ($subaction == "editsaved") {
if (isset($_GET['public']) && $_GET['public'] == "true") {
$password = hash('sha256', (string) Yii::app()->request->getParam('accesscode'));
$password = hash('sha256', Yii::app()->request->getParam('accesscode', ''));
} else {
$password = Yii::app()->request->getParam('accesscode');
$password = Yii::app()->request->getParam('accesscode', '');
}

$svresult = SavedControl::model()->findAllByAttributes(
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/admin/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ private function actionUpdateSurveyLocaleSettings($iSurveyID)

// Url params in json
if (Yii::app()->request->getPost('allurlparams', false) !== false) {
$aURLParams = json_decode((string) Yii::app()->request->getPost('allurlparams'), true);
$aURLParams = json_decode(Yii::app()->request->getPost('allurlparams', ''), true) ?? [];
SurveyURLParameter::model()->deleteAllByAttributes(array('sid' => $iSurveyID));
foreach ($aURLParams as $aURLParam) {
$aURLParam['parameter'] = trim((string) $aURLParam['parameter']);
Expand Down
26 changes: 13 additions & 13 deletions application/controllers/admin/ParticipantsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public function deleteParticipant()

// First for delete one, second for massive action
$participantId = Yii::app()->request->getPost('participant_id');
$participantIds = json_decode((string) Yii::app()->request->getPost('sItems'), true);
$participantIds = json_decode(Yii::app()->request->getPost('sItems', ''), true);

if (empty($participantIds)) {
$participantIds = $participantId;
Expand Down Expand Up @@ -629,7 +629,7 @@ public function batchEdit()
return;
}

$aParticipantIds = json_decode((string) Yii::app()->request->getPost('sItems'));
$aParticipantIds = json_decode(Yii::app()->request->getPost('sItems', '')) ?? [];
$aResults = array();
$oBaseModel = Surveymenu::model();
// First we create the array of fields to update
Expand All @@ -639,7 +639,7 @@ public function batchEdit()
// Core Fields
$aCoreTokenFields = array('language', 'owner_uid', 'blacklisted');
foreach ($aCoreTokenFields as $sCoreTokenField) {
if (trim((string) Yii::app()->request->getPost($sCoreTokenField, 'lskeep')) != 'lskeep') {
if (trim(Yii::app()->request->getPost($sCoreTokenField, 'lskeep')) != 'lskeep') {
$aData[$sCoreTokenField] = flattenText(Yii::app()->request->getPost($sCoreTokenField));
}
}
Expand Down Expand Up @@ -893,7 +893,7 @@ public function uploadCSV()
$mappedarray = Yii::app()->request->getPost('mappedarray', false);
$filterblankemails = Yii::app()->request->getPost('filterbea');
$overwrite = Yii::app()->request->getPost('overwrite');
$sFilePath = Yii::app()->getConfig('tempdir') . '/' . basename((string) Yii::app()->request->getPost('fullfilepath'));
$sFilePath = Yii::app()->getConfig('tempdir') . '/' . basename(Yii::app()->request->getPost('fullfilepath', ''));
$errorinupload = "";
$recordcount = 0;
$mandatory = 0;
Expand Down Expand Up @@ -1169,7 +1169,7 @@ public function mapCSVcancelled()
{
$this->checkPermission('import');

unlink(Yii::app()->getConfig('tempdir') . '/' . basename((string) Yii::app()->request->getPost('fullfilepath')));
unlink(Yii::app()->getConfig('tempdir') . '/' . basename(Yii::app()->request->getPost('fullfilepath', '')));
}

/**********************************************EXPORT PARTICIPANTS***********************************************/
Expand All @@ -1184,7 +1184,7 @@ public function exporttocsv()

if (Yii::app()->request->getPost('searchcondition', '') !== '') {
// if there is a search condition then only the participants that match the search criteria are counted
$condition = explode("%7C%7C", (string) Yii::app()->request->getPost('searchcondition', ''));
$condition = explode("%7C%7C", Yii::app()->request->getPost('searchcondition', ''));
$search = Participant::model()->getParticipantsSearchMultipleCondition($condition);
} else {
$search = null;
Expand All @@ -1205,7 +1205,7 @@ public function exporttocsv()
$search = $searchSelected;
}

$aAttributes = explode('+', (string) Yii::app()->request->getPost('attributes', ''));
$aAttributes = explode('+', Yii::app()->request->getPost('attributes', ''));
$this->csvExport($search, array_filter($aAttributes)); // Array filter gets rid of empty entries
}

Expand Down Expand Up @@ -1709,7 +1709,7 @@ public function deleteAttributes()
}

$request = Yii::app()->request;
$attributeIds = json_decode((string) $request->getPost('sItems'));
$attributeIds = json_decode($request->getPost('sItems', '')) ?? [];
$attributeIds = array_map('sanitize_int', $attributeIds);

$deletedAttributes = 0;
Expand Down Expand Up @@ -1745,7 +1745,7 @@ public function editAttributeInfo()
$operation = Yii::app()->request->getPost('oper');

if ($operation == 'del' && Yii::app()->request->getPost('id')) {
$aAttributeIds = (array) explode(',', (string) Yii::app()->request->getPost('id'));
$aAttributeIds = (array) explode(',', Yii::app()->request->getPost('id', ''));
$aAttributeIds = array_map('trim', $aAttributeIds);
$aAttributeIds = array_map('intval', $aAttributeIds);

Expand Down Expand Up @@ -1778,7 +1778,7 @@ public function editAttributeInfo()
*/
public function getAttributeJson()
{
$iParticipantId = strip_tags((string) Yii::app()->request->getQuery('pid'));
$iParticipantId = strip_tags(Yii::app()->request->getQuery('pid', ''));
$records = ParticipantAttributeName::model()->getParticipantVisibleAttribute($iParticipantId);
$records = subval_sort($records, "attribute_name", "asc");

Expand Down Expand Up @@ -1948,7 +1948,7 @@ public function delAttributeValues()
public function editAttributevalue()
{
if (Yii::app()->request->getPost('oper') == "edit" && isset($_POST['attvalue'])) {
$pid = explode('_', (string) Yii::app()->request->getPost('participant_id'));
$pid = explode('_', Yii::app()->request->getPost('participant_id', ''));
$iAttributeId = Yii::app()->request->getPost('attid');
if (Permission::model()->hasGlobalPermission('participantpanel', 'update') && Participant::model()->isOwner($pid[0])) {
$aData = array('participant_id' => $pid[0], 'attribute_id' => $iAttributeId, 'value' => Yii::app()->request->getPost('attvalue'));
Expand Down Expand Up @@ -2126,7 +2126,7 @@ public function getSurveyInfoJson()
public function getSearchIDs()
{
$searchcondition = Yii::app()->request->getPost('searchcondition'); // get the search condition from the URL
$sSearchURL = basename((string) Yii::app()->request->getPost('searchURL')); // get the search condition from the URL
$sSearchURL = basename(Yii::app()->request->getPost('searchURL', '')); // get the search condition from the URL
/* a search contains posted data inside $_POST['searchcondition'].
* Each separate query is made up of 3 fields, separated by double-pipes ("|")
* EG: fname||eq||jason||lname||ct||c
Expand Down Expand Up @@ -2410,7 +2410,7 @@ public function deleteMultipleParticipantShare()
$isSuperAdmin = Permission::model()->hasGlobalPermission('superadmin');

// Array of strings with both participant id and share uid separated by comma
$participantIdAndShareUids = json_decode((string) $request->getPost('sItems'), true);
$participantIdAndShareUids = json_decode($request->getPost('sItems', ''), true) ?? [];

$sharesDeleted = 0;
foreach ($participantIdAndShareUids as $participantIdAndShareUid) {
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/admin/PluginManagerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ function pluginExtractFilter($p_event, &$p_header)
{
$aAllowExtensions = explode(
',',
(string) Yii::app()->getConfig('allowedpluginuploads')
Yii::app()->getConfig('allowedpluginuploads', '')
);
$info = pathinfo((string) $p_header['filename']);

Expand Down
4 changes: 2 additions & 2 deletions application/controllers/admin/PrintableSurvey.php
Original file line number Diff line number Diff line change
Expand Up @@ -1438,12 +1438,12 @@ private function getColumnWidth($answerBaseWidth, $labelBaseWidth)
);
}

private function starReplace($input)
private function starReplace(string $input)
{
return preg_replace(
'/\*(.*)\*/U',
'<strong>\1</strong>',
(string) $input
$input
);
}

Expand Down
6 changes: 3 additions & 3 deletions application/controllers/admin/SurveymenuController.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function batchEdit()
$this->getController()->redirect(Yii::app()->createUrl('/admin'));
}

$aSurveyMenuIds = json_decode((string) Yii::app()->request->getPost('sItems'));
$aSurveyMenuIds = json_decode(Yii::app()->request->getPost('sItems', '')) ?? [];
$aResults = array();
$oBaseModel = Surveymenu::model();
if (Permission::model()->hasGlobalPermission('settings', 'update')) {
Expand All @@ -136,7 +136,7 @@ public function batchEdit()
$aCoreTokenFields = array('position', 'parent', 'survey', 'user');

foreach ($aCoreTokenFields as $sCoreTokenField) {
if (trim((string) Yii::app()->request->getPost($sCoreTokenField, 'lskeep')) != 'lskeep') {
if (trim(Yii::app()->request->getPost($sCoreTokenField, 'lskeep')) != 'lskeep') {
$aData[$sCoreTokenField] = flattenText(Yii::app()->request->getPost($sCoreTokenField));
}
}
Expand Down Expand Up @@ -183,7 +183,7 @@ public function massDelete()
}

if (Yii::app()->request->isPostRequest) {
$aSurveyMenuIds = json_decode((string) Yii::app()->request->getPost('sItems'));
$aSurveyMenuIds = json_decode(Yii::app()->request->getPost('sItems', '')) ?? [];
$success = [];
foreach ($aSurveyMenuIds as $menuid) {
$model = $this->loadModel($menuid);
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/admin/SurveymenuEntryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function update($id)

public function batchEdit()
{
$aSurveyMenuEntryIds = json_decode((string) Yii::app()->request->getPost('sItems'));
$aSurveyMenuEntryIds = json_decode(Yii::app()->request->getPost('sItems', '')) ?? [];
$aResults = array();
$oBaseModel = SurveymenuEntries::model();
if (Permission::model()->hasGlobalPermission('settings', 'update')) {
Expand Down Expand Up @@ -277,7 +277,7 @@ public function massDelete()
}

if (Yii::app()->request->isPostRequest) {
$aSurveyMenuEntryIds = json_decode((string) Yii::app()->request->getPost('sItems'));
$aSurveyMenuEntryIds = json_decode(Yii::app()->request->getPost('sItems', '')) ?? [];
$success = [];
foreach ($aSurveyMenuEntryIds as $menuEntryid) {
$model = $this->loadModel($menuEntryid);
Expand Down
6 changes: 3 additions & 3 deletions application/controllers/admin/Themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ public function templatecopy()
*/
public function delete()
{
$templatename = trim((string) Yii::app()->request->getPost('templatename'));
$templatename = trim(Yii::app()->request->getPost('templatename', ''));
if (Permission::model()->hasGlobalPermission('templates', 'delete')) {
Yii::app()->loadHelper("admin/template");

Expand Down Expand Up @@ -819,7 +819,7 @@ public function delete()

public function deleteBrokenTheme()
{
$templatename = trim((string) Yii::app()->request->getPost('templatename'));
$templatename = trim(Yii::app()->request->getPost('templatename', ''));

if (Permission::model()->hasGlobalPermission('templates', 'delete')) {
// First we check that the theme is really broken
Expand All @@ -840,7 +840,7 @@ public function deleteBrokenTheme()

public function deleteAvailableTheme()
{
$templatename = trim((string) Yii::app()->request->getPost('templatename'));
$templatename = trim(Yii::app()->request->getPost('templatename', ''));

if (Permission::model()->hasGlobalPermission('templates', 'delete')) {
$completeFileName = realpath(Yii::app()->getConfig('userthemerootdir') . "/" . $templatename);
Expand Down

0 comments on commit a1c0068

Please sign in to comment.