Skip to content

Commit

Permalink
Fix all PhanUnusedVariable errors (aces#7389)
Browse files Browse the repository at this point in the history
Fix all PhanUnusedVariable class errors.
  • Loading branch information
driusan authored Mar 23, 2021
1 parent 3cc7491 commit 30b3141
Show file tree
Hide file tree
Showing 50 changed files with 39 additions and 122 deletions.
5 changes: 0 additions & 5 deletions .phan/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
// suppressed rules, we should consider reducing this value to detect more
// suspicious code.
"minimum_severity" => 1,
// FIXME: allow_missing_properties should be false, but there's
// too many other things to fix first.
"allow_missing_properties" => false,
"null_casts_as_any_type" => false,
"scalar_implicit_cast" => false,
Expand All @@ -29,11 +27,8 @@
"ignore_undeclared_variables_in_global_scope" => true,
// FIXME: We should add this.
"dead_code_detection" => false,
// FIXME: We should add this. Note that dead_code_detection also covers
// unused_variable_detection. It might be a good idea to enable this first.
"unused_variable_detection" => true,
"suppress_issue_types" => [
"PhanUnusedVariable",
"PhanUnusedPublicNoOverrideMethodParameter",
"PhanTypePossiblyInvalidDimOffset",
],
Expand Down
8 changes: 4 additions & 4 deletions modules/candidate_list/php/candidate_list.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -88,29 +88,29 @@ class Candidate_List extends \DataFrameworkMenu
$list_of_sites = $user->getStudySites();
}
$site_options = [];
foreach ($list_of_sites as $id => $name) {
foreach (array_values($list_of_sites) as $name) {
$site_options[$name] = $name;
}

// get the list of projects
$list_of_projects = \Utility::getProjectList();
$project_options = [];
foreach ($list_of_projects as $id => $name) {
foreach (array_values($list_of_projects) as $name) {
$project_options[$name] = $name;
}

// get the list of subprojects
$list_of_subprojects = \Utility::getSubprojectList();
$subproject_options = [];
foreach ($list_of_subprojects as $id => $name) {
foreach (array_values($list_of_subprojects) as $name) {
$subproject_options[$name] = $name;
}

// get the list participant status options
$list_of_participant_status
= \Candidate::getParticipantStatusOptions();
$participant_status_options = [];
foreach ($list_of_participant_status as $id => $name) {
foreach (array_values($list_of_participant_status) as $name) {
$participant_status_options[$name] = $name;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/candidate_parameters/ajax/getData.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ function getFamilyInfoFields()
);

$siblings = [];
foreach ($siblingsList as $key => $siblingArray) {
foreach (array_values($siblingsList) as $siblingArray) {
foreach ($siblingArray as $ID) {
array_push($siblings, $ID);
}
Expand Down
2 changes: 1 addition & 1 deletion modules/conflict_resolver/php/conflict_resolver.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ class Conflict_Resolver extends \NDB_Menu_Filter_Form
// Project list, if applicable
$list_of_projects = [];
$projectList = \Utility::getProjectList();
foreach ($projectList as $key => $value) {
foreach (array_values($projectList) as $value) {
$list_of_projects[$value] = $value;
}
$this->addSelect('project', 'Project: ', $list_of_projects);
Expand Down
2 changes: 1 addition & 1 deletion modules/conflict_resolver/php/resolved_conflicts.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class Resolved_Conflicts extends \NDB_Menu_Filter
// Project list, if applicable
$list_of_projects = [];
$projectList = \Utility::getProjectList();
foreach ($projectList as $key => $value) {
foreach (array_values($projectList) as $value) {
$list_of_projects[$value] = $value;
}
$this->addSelect('project', 'Project: ', $list_of_projects);
Expand Down
2 changes: 1 addition & 1 deletion modules/dashboard/php/module.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ class Module extends \Module
);
}

$logindatestring = "";
if ($last_login === null) {
$logindatestring = "...never. Welcome!";
} else {
Expand All @@ -109,6 +108,7 @@ class Module extends \Module
// a \DateTime object.
$logindatestring = $last_login->format('Y-m-d H:i:s');
}

return new Widget(
new WidgetContent(
"",
Expand Down
1 change: 0 additions & 1 deletion modules/dicom_archive/test/dicom_archiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ function testLinksViewImages()
"document.querySelector('$location').click()"
);
sleep(1);
$text = $this->webDriver->getPageSource();
$text = $this->webDriver->executescript(
"return document.querySelector('#bc2>a:nth-child(3)>div').textContent"
);
Expand Down
4 changes: 1 addition & 3 deletions modules/document_repository/php/files.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,7 @@ class Files extends \NDB_Page

$targetdir = new \SplFileInfo($path);

$fileSize = $uploadedFile->getSize();
$fileName = $uploadedFile->getClientFileName();
$fileType = pathinfo($fileName, PATHINFO_EXTENSION);
$filename = $uploadedFile->getClientFileName();
try{
$uploader = (new \LORIS\FilesUploadHandler($targetdir))
->withPermittedMIMETypes(
Expand Down
12 changes: 0 additions & 12 deletions modules/genomic_browser/php/methylation.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,6 @@ class Methylation extends \NDB_Page implements ETagCalculator
: $user->getStudySites();
$list_of_sites = array_combine($list_of_sites, $list_of_sites);

// Platform
$DB = \Database::singleton();
$platform_results = $DB->pselect(
"SELECT distinct Name FROM genotyping_platform",
[]
);
$platform_options = [];
foreach ($platform_results as $row) {
$name = $row['Name'];
$platform_options[$name] = $name;
}

return (new \LORIS\genomic_browser\Views\Methylation(
$list_of_sites,
\Utility::getSubprojectList()
Expand Down
3 changes: 0 additions & 3 deletions modules/help_editor/php/edit_help_content.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ class Edit_Help_Content extends \NDB_Form
*/
function _getDefaults()
{
//Get the default values
$defaults = [];

// Sanitize user input
$safeSection = isset($_REQUEST['section']) ?
htmlspecialchars($_REQUEST['section']) : '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ class Imaging_Session_ControlPanel
* any way by any user.
*/
$params = [];
$ID = 'NULL';
$EntityType = $candidate->getEntityType();
if ($EntityType == 'Scanner') {
$ID = ":PVL";
Expand Down
1 change: 0 additions & 1 deletion modules/imaging_browser/php/viewsession.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ class ViewSession extends \NDB_Form
$FileInsertDate = $FileObj->getParameter('InsertTime');
$SeriesDescription = $FileObj->getParameter('series_description');
$SeriesNumber = $FileObj->getParameter('series_number');
$SeriesUID = $FileObj->getParameter('series_instance_uid');
$EchoTime = number_format(
(float)$FileObj->getParameter('echo_time') * 1000,
2
Expand Down
4 changes: 2 additions & 2 deletions modules/imaging_qc/php/imaging_qc.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,12 @@ class Imaging_QC extends \NDB_Menu_Filter

$projectList = \Utility::getProjectList();
$projectList2 = [];
foreach ($projectList as $key => $value) {
foreach (array_values($projectList) as $value) {
$projectList2[$value] = $value;
}
$subprojectList = \Utility::getSubprojectList();
$subprojectList2 = [];
foreach ($subprojectList as $key => $value) {
foreach (array_values($subprojectList) as $value) {
$subprojectList2[$value] = $value;
}
//print_r($subprojectList2);
Expand Down
6 changes: 1 addition & 5 deletions modules/imaging_uploader/php/file_decompress.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ class File_Decompress
*/
function tgzDecompres()
{
$decompressed_folder = null;
$p = new \PharData($this->file_name);
$decompressed_folder = $p->decompress(); // creates /path/to/my.tar
$p->extractTo(
Expand All @@ -107,8 +106,7 @@ class File_Decompress
*/
function gzipDecompress()
{
$return_value = false;
$decomp_file = new \PharData($this->file_name);
$decomp_file = new \PharData($this->file_name);
// creates /path/to/my.tar
$return_value = $decomp_file->decompress();
return $return_value;
Expand All @@ -122,7 +120,6 @@ class File_Decompress
*/
function untar()
{
$return_value = false;
$p = new \PharData($this->file_name);
$return_value = $p->extractTo($this->dest_path);
//could remove the folder later once completed...
Expand All @@ -140,7 +137,6 @@ class File_Decompress
*/
function unzip()
{
$result = false;
$zip = new \ZipArchive();
$result = $zip->open($this->file_name);
if ($result === true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class Instrument_List_ControlPanel extends \TimePoint
}
$this->startStage($nextStage);

if ($nextStage = 'Recycling Bin') {
if ($nextStage == 'Recycling Bin') {

$battery = new \NDB_BVL_Battery();

Expand Down
1 change: 0 additions & 1 deletion modules/issue_tracker/ajax/EditIssue.php
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,6 @@ function getIssueFields()
$factory = \NDB_Factory::singleton();
$db = $factory->database();
$user = $factory->user();
$sites = [];

// get field options
$sites = Issue_Tracker::getSites(false, true);
Expand Down
4 changes: 1 addition & 3 deletions modules/issue_tracker/php/issue_tracker.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ class Issue_Tracker extends \NDB_Menu_Filter_Form
bool $study_site = true,
bool $DCC = true
): array {
$user = \User::singleton();
$sites = [];
$user = \User::singleton();
if ($user->hasPermission('access_all_profiles')) {
// get the list of study sites - to be replaced by the Site object
$sites = \Utility::getSiteList($study_site, $DCC);
Expand All @@ -106,7 +105,6 @@ class Issue_Tracker extends \NDB_Menu_Filter_Form
$db = $factory->database();

//sites
$sites = [];
if ($user->hasPermission('access_all_profiles')) {
$sites = \Utility::getSiteList();
} else {
Expand Down
2 changes: 0 additions & 2 deletions modules/login/php/requestaccount.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ class RequestAccount extends \NDB_Form
['VEmail' => $from]
);

$user_id = null;

if ($result == 0) {
// insert into DB only if email address doesn't exist
$DB->insert('users', $vals);
Expand Down
2 changes: 0 additions & 2 deletions modules/media/ajax/FileUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,6 @@ function getUploadFields()
$languageList = Utility::getLanguageList();
$startYear = $config->getSetting('startYear');
$endYear = $config->getSetting('endYear');
$visit = '';
$pscid = '';

// Build array of session data to be used in upload media dropdowns
$sessionData = [];
Expand Down
2 changes: 0 additions & 2 deletions modules/my_preferences/php/my_preferences.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ class My_Preferences extends \NDB_Form
*/
function _getDefaults()
{
$defaults = [];

$user = \User::factory($this->identifier);
// get the user defaults
$defaults = $user->getData();
Expand Down
8 changes: 4 additions & 4 deletions modules/statistics/php/statistics_mri_site.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ class Statistics_Mri_Site extends Statistics_Site
$scan_types = $DB->pselect("SELECT Scan_type from mri_scan_type", []);
$where = "WHERE (";
$counter = 1;
foreach ($scan_types as $index=>$scan) {
foreach ($scan as $type=>$label) {
foreach (array_values($scan_types) as $scan) {
foreach (array_values($scan) as $label) {
if ($counter < sizeof($scan_types)) {
$where .= "m.$label <> 'No' OR m.$label IS NULL OR ";
} else {
Expand Down Expand Up @@ -132,8 +132,8 @@ class Statistics_Mri_Site extends Statistics_Site
case 'Files_Missing':
$where = "WHERE (";
$counter = 1;
foreach ($scan_types as $index=>$scan) {
foreach ($scan as $type=>$label) {
foreach (array_values($scan_types) as $scan) {
foreach (array_values($scan) as $label) {
if ($counter < sizeof($scan_types)) {
$where .= "m.$label <> 'No' OR ";
} else {
Expand Down
2 changes: 0 additions & 2 deletions modules/statistics/php/statistics_site.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ class Statistics_Site extends \NDB_Menu
$this->query_criteria .= " AND s.CenterID =:cid ";
$this->query_vars['cid'] = $centerID;
} else {
$list_of_permitted_sites = [];

if ($user->hasPermission('access_all_profiles')) {
$list_of_permitted_sites = array_keys(\Utility::getSiteList());
} else {
Expand Down
2 changes: 0 additions & 2 deletions modules/statistics/php/stats_behavioural.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ class Stats_Behavioural extends \NDB_Form
$allProjectList = \Utility::getProjectList();
$projects = [];
$projects[''] = 'All Projects';
$Param_Project = '';

$userProjectsIDs = $user->getProjectIDs();
foreach ($userProjectsIDs as $ProjectID) {
Expand Down Expand Up @@ -166,7 +165,6 @@ class Stats_Behavioural extends \NDB_Form

//SITES

$Param_Centers = '';
if ($user->hasPermission('access_all_profiles')) {
$list_of_sites = \Utility::getSiteList();
} else {
Expand Down
2 changes: 1 addition & 1 deletion modules/statistics/php/stats_mri.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ class Stats_MRI extends \NDB_Form
if (empty($scans_selected_input)) {
$scans_selected = $scan_types ?? [];
} else {
foreach ($scans_selected_input as $key => $scid) {
foreach ($scans_selected_input as $scid) {
$scans_selected[$scid] =$scan_types[$scid];
}
}
Expand Down
6 changes: 2 additions & 4 deletions modules/timepoint_list/php/timepoint_list.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ class Timepoint_List extends \NDB_Menu
// create candidate object
$candidate = \Candidate::singleton($this->candID);

$numberOfVisits = 0;
$this->tpl_data['candID'] = $this->candID;
$this->tpl_data['PSCID'] = $candidate->getPSCID();
$this->tpl_data['candID'] = $this->candID;
$this->tpl_data['PSCID'] = $candidate->getPSCID();
$this->tpl_data['candidate'] = $candidate->getData();

$listOfSessionIDs = $candidate->getListOfTimePoints();
Expand Down Expand Up @@ -121,7 +120,6 @@ class Timepoint_List extends \NDB_Menu
if (empty($firstDateOfVisit)) {
$firstDateOfVisit = $dateOfVisit;
}
$numberOfVisits++;
}

// get timepoint data
Expand Down
2 changes: 1 addition & 1 deletion modules/user_accounts/php/edit_user.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ class Edit_User extends \NDB_Form
$editorProjects = $editor->getProjectIDs();
$projects = \Utility::getProjectList();
$projectOptions = [];
foreach ($editorProjects as $key => $projectID) {
foreach (array_values($editorProjects) as $projectID) {
$projectOptions[$projectID->__toString()]
= $projects[$projectID->__toString()];
}
Expand Down
1 change: 0 additions & 1 deletion php/libraries/CandIDGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public function __construct()
*/
public function generate(): CandID
{
$validID = false;
do {
$this->checkIDRangeFull();
$id = new CandID(
Expand Down
1 change: 0 additions & 1 deletion php/libraries/Candidate.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ class Candidate implements \LORIS\StudyEntities\AccessibleResource,
// Generate a new CandID and insert it into the database.
$generator = new \CandIDGenerator();
// declare the variable to avoid static analysis warnings
$invalidID = false;
$attemptcount = 0;
do {
// Reset on each iteration
Expand Down
Loading

0 comments on commit 30b3141

Please sign in to comment.