From ffc216e811c3d78829774e46f533b86c65a69d8f Mon Sep 17 00:00:00 2001 From: Dave MacFarlane Date: Mon, 5 Mar 2018 11:43:41 -0500 Subject: [PATCH 01/10] More Phan Fixes --- .phan/config.php | 3 --- htdocs/acknowledgements/acknowledgements.php | 18 +++++++++--------- .../ajax/documentEditUpload.php | 3 ++- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/.phan/config.php b/.phan/config.php index 1e7ef453e4d..d62c542ba45 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -21,7 +21,6 @@ "ignore_undeclared_variables_in_global_scope" => false, "suppress_issue_types" => [ "PhanTypeMismatchDeclaredReturn", - "PhanTypeNonVarPassByRef", "PhanTypeExpectedObjectPropAccessButGotNull", "PhanTypeInvalidDimOffset", "PhanTypeMismatchDimAssignment", @@ -36,7 +35,6 @@ "PhanUndeclaredTypeReturnType", "PhanTypeMismatchDimFetch", "PhanTypeArraySuspiciousNullable", - "PhanUndeclaredStaticMethod", "PhanUndeclaredClassMethod", "PhanUndeclaredTypeParameter", "PhanUndeclaredConstant", @@ -61,7 +59,6 @@ "PhanTypeInvalidRightOperand", "PhanRedefineFunctionInternal", "PhanRedefineFunction", - "PhanParamSpecial1", "PhanParamSpecial2", "PhanUnextractableAnnotation", ], diff --git a/htdocs/acknowledgements/acknowledgements.php b/htdocs/acknowledgements/acknowledgements.php index ca20c232ba6..6484c28db18 100644 --- a/htdocs/acknowledgements/acknowledgements.php +++ b/htdocs/acknowledgements/acknowledgements.php @@ -24,15 +24,15 @@ $publication_date = $_GET["date"]; $columns = array( - full_name => 'Full Name', - citation_name => 'Citation Name', - title => 'Title', - affiliations => 'Affiliations', - degrees => 'Degrees', - roles => 'Roles', - start_date => 'Start Date', - end_date => 'End Date', - present => 'Present?', + 'full_name' => 'Full Name', + 'citation_name' => 'Citation Name', + 'title' => 'Title', + 'affiliations' => 'Affiliations', + 'degrees' => 'Degrees', + 'roles' => 'Roles', + 'start_date' => 'Start Date', + 'end_date' => 'End Date', + 'present' => 'Present?', ); $keysAsString = implode(', ', array_keys($columns)); diff --git a/modules/document_repository/ajax/documentEditUpload.php b/modules/document_repository/ajax/documentEditUpload.php index e50c3125652..a03b8aa40fe 100644 --- a/modules/document_repository/ajax/documentEditUpload.php +++ b/modules/document_repository/ajax/documentEditUpload.php @@ -63,7 +63,8 @@ $fileSize = $_FILES["file"]["size"]; $fileName = $_FILES["file"]["name"]; - $fileType = end((explode(".", $fileName))); + $ft = explode(".", $fileName); + $fileType = end($ft); // __DIR__ is the document_repository ajax directory // when this script is executing. Go up a level to the From 6e435cf3165eaa97501310eaf7e4e5cf7bc20b6f Mon Sep 17 00:00:00 2001 From: Dave MacFarlane Date: Mon, 5 Mar 2018 12:02:38 -0500 Subject: [PATCH 02/10] Fix some more errors --- .phan/config.php | 2 -- .../php/mriuploadserverprocess.class.inc | 6 +++--- modules/training/php/training.class.inc | 7 +++++-- php/libraries/Database.class.inc | 5 ++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.phan/config.php b/.phan/config.php index d62c542ba45..b2bc665d5bb 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -24,7 +24,6 @@ "PhanTypeExpectedObjectPropAccessButGotNull", "PhanTypeInvalidDimOffset", "PhanTypeMismatchDimAssignment", - "PhanDeprecatedFunction", "PhanParamSuspiciousOrder", "PhanTypeExpectedObjectPropAccess", "PhanRedefineClass", @@ -60,7 +59,6 @@ "PhanRedefineFunctionInternal", "PhanRedefineFunction", "PhanParamSpecial2", - "PhanUnextractableAnnotation", ], "analyzed_file_extensions" => ["php", "inc"], "directory_list" => [ diff --git a/modules/server_processes_manager/php/mriuploadserverprocess.class.inc b/modules/server_processes_manager/php/mriuploadserverprocess.class.inc index 6fba07db4ab..43db4bfcd17 100644 --- a/modules/server_processes_manager/php/mriuploadserverprocess.class.inc +++ b/modules/server_processes_manager/php/mriuploadserverprocess.class.inc @@ -45,21 +45,21 @@ class MriUploadServerProcess extends AbstractServerProcess /** * ID of the MRI upload request in the mri_upload table. * - * @var + * @var int */ private $_mriUploadId; /** * Location of the MRI file uploaded. * - * @var + * @var string */ private $_sourceLocation; /** * Root of the MRI files directory. * - * @var + * @var string */ private $_mriCodePath; diff --git a/modules/training/php/training.class.inc b/modules/training/php/training.class.inc index 4ddd6eddf98..4c3c961f4c6 100644 --- a/modules/training/php/training.class.inc +++ b/modules/training/php/training.class.inc @@ -121,11 +121,14 @@ class Training extends \NDB_Form foreach ($certificationInstruments['test'] as $certificationInstrument) { $test_key = $certificationInstrument['@']['value']; - $testID = $DB->selectOne( + $testID = $DB->pselectOne( "SELECT ID FROM test_names WHERE Test_name - LIKE '%$test_key%'" + LIKE CONCAT('%', :testkey, '%')", + array( + 'testkey' => $test_key + ) ); $instruments[$testID] = $certificationInstrument['#']; } diff --git a/php/libraries/Database.class.inc b/php/libraries/Database.class.inc index a89aeb719a1..fda3bc028d7 100644 --- a/php/libraries/Database.class.inc +++ b/php/libraries/Database.class.inc @@ -619,7 +619,7 @@ class Database */ function selectRow($query, &$result) { - $this->select($query, $result); + $result = $this->pselect($query, []); if (is_array($result) && isset($result[0])) { $result = $result[0]; } @@ -641,8 +641,7 @@ class Database */ function selectOne($query) { - $result = null; - $this->select($query, $result); + $result = $this->pselect($query); if (is_array($result) && count($result)) { list(,$result) = each($result[0]); } From 62d30044014cbb43742198a85e9dbfd212222f36 Mon Sep 17 00:00:00 2001 From: Dave MacFarlane Date: Mon, 5 Mar 2018 12:28:40 -0500 Subject: [PATCH 03/10] More phan phixes --- .phan/config.php | 1 - htdocs/survey.php | 4 ++++ php/libraries/Utility.class.inc | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.phan/config.php b/.phan/config.php index b2bc665d5bb..a9c938c38c4 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -53,7 +53,6 @@ "PhanParamTooFew", "PhanParamTooMany", "PhanStaticCallToNonStatic", - "PhanTypeComparisonToArray", "PhanTypeArraySuspicious", "PhanTypeInvalidRightOperand", "PhanRedefineFunctionInternal", diff --git a/htdocs/survey.php b/htdocs/survey.php index 3ec8291e02f..0f9c464a485 100644 --- a/htdocs/survey.php +++ b/htdocs/survey.php @@ -38,6 +38,10 @@ class DirectDataEntryMainPage var $key; var $TestName; + + /** + * @var mixed + */ var $Subtest; var $NumPages; diff --git a/php/libraries/Utility.class.inc b/php/libraries/Utility.class.inc index bdd7e448f64..1e3a083f0ab 100644 --- a/php/libraries/Utility.class.inc +++ b/php/libraries/Utility.class.inc @@ -614,7 +614,7 @@ class Utility * @param string $inst The test_name of the instrument for which you would * like to know the score columns * - * @return non-associative array of scored columns for the instrument given + * @return array (non-associative) of scored columns for the instrument given */ static function getScoreColsForInstrument($inst) { From b88bcd38a2c9eb91cb990e0df724212efc695a51 Mon Sep 17 00:00:00 2001 From: Dave MacFarlane Date: Mon, 5 Mar 2018 12:37:32 -0500 Subject: [PATCH 04/10] Static call to non-static function errors --- .phan/config.php | 2 -- modules/candidate_list/test/candidate_listTest.php | 2 +- php/libraries/NDB_BVL_Feedback.class.inc | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.phan/config.php b/.phan/config.php index a9c938c38c4..229d6e27fbf 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -28,7 +28,6 @@ "PhanTypeExpectedObjectPropAccess", "PhanRedefineClass", "PhanUndeclaredMethod", - "PhanUndeclaredFunction", "PhanUndeclaredVariable", "PhanUndeclaredVariableDim", "PhanUndeclaredTypeReturnType", @@ -52,7 +51,6 @@ "PhanTypeVoidAssignment", "PhanParamTooFew", "PhanParamTooMany", - "PhanStaticCallToNonStatic", "PhanTypeArraySuspicious", "PhanTypeInvalidRightOperand", "PhanRedefineFunctionInternal", diff --git a/modules/candidate_list/test/candidate_listTest.php b/modules/candidate_list/test/candidate_listTest.php index 5f25a3e60d2..963b377cb7c 100644 --- a/modules/candidate_list/test/candidate_listTest.php +++ b/modules/candidate_list/test/candidate_listTest.php @@ -286,7 +286,7 @@ private function _assertSearchBy(array $criteria, $expectedResults) $selectElement->selectByVisibleText($elementValue); break; default: - throw Exception( + throw new Exception( 'Element type ' . $element->getTagName() . ' not supported' ); } diff --git a/php/libraries/NDB_BVL_Feedback.class.inc b/php/libraries/NDB_BVL_Feedback.class.inc index ce48eee1e3e..d48537b4091 100644 --- a/php/libraries/NDB_BVL_Feedback.class.inc +++ b/php/libraries/NDB_BVL_Feedback.class.inc @@ -603,7 +603,7 @@ class NDB_BVL_Feedback * * @return array */ - function getThreadEntries($feedbackID) + static function getThreadEntries($feedbackID) { // new DB Object $db =& Database::singleton(); From 95a67a2feddb0d75705f6bf96391e2a0a0e18fce Mon Sep 17 00:00:00 2001 From: Dave MacFarlane Date: Mon, 5 Mar 2018 12:43:14 -0500 Subject: [PATCH 05/10] null_casts_as_any_type --- .phan/config.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.phan/config.php b/.phan/config.php index 229d6e27fbf..cad05445336 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -14,9 +14,7 @@ // FIXME: allow_missing_properties should be false, but there's // too many other things to fix first. "allow_missing_properties" => true, - // FIXME: null_casts_as_any_type should be false. - // This only adds 2 errors, which should be fairly easy to fix. - "null_casts_as_any_type" => true, + "null_casts_as_any_type" => false, "scalar_implicit_cast" => false, "ignore_undeclared_variables_in_global_scope" => false, "suppress_issue_types" => [ From 5b1f090b22fbbc89487ce3da1157f97ef4ac669c Mon Sep 17 00:00:00 2001 From: Dave MacFarlane Date: Mon, 5 Mar 2018 12:57:59 -0500 Subject: [PATCH 06/10] Fix PhanParamSpecial2 --- .phan/config.php | 1 - modules/new_profile/php/new_profile.class.inc | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.phan/config.php b/.phan/config.php index cad05445336..14c1d47379b 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -53,7 +53,6 @@ "PhanTypeInvalidRightOperand", "PhanRedefineFunctionInternal", "PhanRedefineFunction", - "PhanParamSpecial2", ], "analyzed_file_extensions" => ["php", "inc"], "directory_list" => [ diff --git a/modules/new_profile/php/new_profile.class.inc b/modules/new_profile/php/new_profile.class.inc index 832c6efcca3..55b63d50923 100644 --- a/modules/new_profile/php/new_profile.class.inc +++ b/modules/new_profile/php/new_profile.class.inc @@ -240,7 +240,7 @@ class New_Profile extends \NDB_Form /** * Validate function * - * @param string $values the value + * @param array $values the value * * @return string */ From e47976787f060e1ee402e8f0ddb188729df9b0cd Mon Sep 17 00:00:00 2001 From: Dave MacFarlane Date: Mon, 5 Mar 2018 16:32:09 -0500 Subject: [PATCH 07/10] Fix another class of errors --- .phan/config.php | 1 - src/Data/Provisioner.php | 2 +- src/Data/ProvisionerInstance.php | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.phan/config.php b/.phan/config.php index 14c1d47379b..2126523a526 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -18,7 +18,6 @@ "scalar_implicit_cast" => false, "ignore_undeclared_variables_in_global_scope" => false, "suppress_issue_types" => [ - "PhanTypeMismatchDeclaredReturn", "PhanTypeExpectedObjectPropAccessButGotNull", "PhanTypeInvalidDimOffset", "PhanTypeMismatchDimAssignment", diff --git a/src/Data/Provisioner.php b/src/Data/Provisioner.php index 1f58b02e5c0..3ab51ef42dd 100644 --- a/src/Data/Provisioner.php +++ b/src/Data/Provisioner.php @@ -60,7 +60,7 @@ public function map(Mapper $map) : Provisioner; * * @param \User $user The user who data is being provisioned on behalf of. * - * @return DataInstance[] + * @return \Traversable of DataInstance objects */ public function execute(\User $user) : \Traversable; }; diff --git a/src/Data/ProvisionerInstance.php b/src/Data/ProvisionerInstance.php index dd1050f6059..2002c12890f 100644 --- a/src/Data/ProvisionerInstance.php +++ b/src/Data/ProvisionerInstance.php @@ -90,7 +90,7 @@ public function map(Mapper $map) : Provisioner * respect to the User accessing the data), which then gets mapped and * filtered by execute. * - * @return Traversable of all resources provided by this data source. + * @return \Traversable of all resources provided by this data source. */ abstract protected function getAllInstances() : \Traversable; @@ -99,7 +99,7 @@ abstract protected function getAllInstances() : \Traversable; * * @param \User $user The user who data is being provisioned on behalf of. * - * @return Instance[] + * @return \Traversable of DataInstance objects */ public function execute(\User $user) : \Traversable { From 28b146e85604c09892c46dea50e93a579f5dca1e Mon Sep 17 00:00:00 2001 From: Dave MacFarlane Date: Mon, 5 Mar 2018 16:35:44 -0500 Subject: [PATCH 08/10] Fix parameter orders --- .phan/config.php | 1 - htdocs/api/v0.0.1/APIBase.php | 2 +- htdocs/api/v0.0.1/candidates/InstrumentData.php | 2 +- htdocs/api/v0.0.2/APIBase.php | 2 +- htdocs/api/v0.0.2/candidates/InstrumentData.php | 2 +- 5 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.phan/config.php b/.phan/config.php index 2126523a526..972a1ab8344 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -21,7 +21,6 @@ "PhanTypeExpectedObjectPropAccessButGotNull", "PhanTypeInvalidDimOffset", "PhanTypeMismatchDimAssignment", - "PhanParamSuspiciousOrder", "PhanTypeExpectedObjectPropAccess", "PhanRedefineClass", "PhanUndeclaredMethod", diff --git a/htdocs/api/v0.0.1/APIBase.php b/htdocs/api/v0.0.1/APIBase.php index c85c3e37cbb..2b4ff3c8af4 100644 --- a/htdocs/api/v0.0.1/APIBase.php +++ b/htdocs/api/v0.0.1/APIBase.php @@ -199,7 +199,7 @@ function handleOPTIONS() { $this->Header( "Access-Control-Allow-Methods: ". - join($this->AllowedMethods, ",") + join(",", $this->AllowedMethods) ); $this->safeExit(0); } diff --git a/htdocs/api/v0.0.1/candidates/InstrumentData.php b/htdocs/api/v0.0.1/candidates/InstrumentData.php index 98b2bf96274..e7f72f8dfea 100644 --- a/htdocs/api/v0.0.1/candidates/InstrumentData.php +++ b/htdocs/api/v0.0.1/candidates/InstrumentData.php @@ -156,7 +156,7 @@ function handleOPTIONS() { $this->Header( "Access-Control-Allow-Methods: ". - join($this->AllowedMethods, ",") + join(",", $this->AllowedMethods) ); } diff --git a/htdocs/api/v0.0.2/APIBase.php b/htdocs/api/v0.0.2/APIBase.php index dde294e8059..be8c89fa0b3 100644 --- a/htdocs/api/v0.0.2/APIBase.php +++ b/htdocs/api/v0.0.2/APIBase.php @@ -199,7 +199,7 @@ function handleOPTIONS() { $this->Header( "Access-Control-Allow-Methods: ". - join($this->AllowedMethods, ",") + join(",", $this->AllowedMethods) ); $this->safeExit(0); } diff --git a/htdocs/api/v0.0.2/candidates/InstrumentData.php b/htdocs/api/v0.0.2/candidates/InstrumentData.php index 2b5a789b610..f82fb4401c7 100644 --- a/htdocs/api/v0.0.2/candidates/InstrumentData.php +++ b/htdocs/api/v0.0.2/candidates/InstrumentData.php @@ -156,7 +156,7 @@ function handleOPTIONS() { $this->Header( "Access-Control-Allow-Methods: ". - join($this->AllowedMethods, ",") + join(",", $this->AllowedMethods) ); } From d65f2bc5140fe9446a2c3f1be00b24798093ae2e Mon Sep 17 00:00:00 2001 From: Dave MacFarlane Date: Tue, 6 Mar 2018 12:38:15 -0500 Subject: [PATCH 09/10] Fixes from review --- htdocs/survey.php | 2 ++ php/libraries/Database.class.inc | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/htdocs/survey.php b/htdocs/survey.php index 0f9c464a485..cecf94b4e7a 100644 --- a/htdocs/survey.php +++ b/htdocs/survey.php @@ -40,6 +40,8 @@ class DirectDataEntryMainPage var $TestName; /** + * The instrument subpage being accessed + * * @var mixed */ var $Subtest; diff --git a/php/libraries/Database.class.inc b/php/libraries/Database.class.inc index fda3bc028d7..b18369aa5d8 100644 --- a/php/libraries/Database.class.inc +++ b/php/libraries/Database.class.inc @@ -619,7 +619,7 @@ class Database */ function selectRow($query, &$result) { - $result = $this->pselect($query, []); + $result = $this->pselect($query, array()); if (is_array($result) && isset($result[0])) { $result = $result[0]; } @@ -641,7 +641,7 @@ class Database */ function selectOne($query) { - $result = $this->pselect($query); + $result = $this->pselect($query, array()); if (is_array($result) && count($result)) { list(,$result) = each($result[0]); } From fc8a947d3b9d1bff2f3ef4dc8b3b93f4791e170b Mon Sep 17 00:00:00 2001 From: Dave MacFarlane Date: Tue, 6 Mar 2018 13:04:00 -0500 Subject: [PATCH 10/10] Fix PHPCS --- modules/document_repository/ajax/documentEditUpload.php | 3 ++- modules/training/php/training.class.inc | 4 +--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/document_repository/ajax/documentEditUpload.php b/modules/document_repository/ajax/documentEditUpload.php index a03b8aa40fe..d8865e3f2ae 100644 --- a/modules/document_repository/ajax/documentEditUpload.php +++ b/modules/document_repository/ajax/documentEditUpload.php @@ -63,7 +63,8 @@ $fileSize = $_FILES["file"]["size"]; $fileName = $_FILES["file"]["name"]; - $ft = explode(".", $fileName); + + $ft = explode(".", $fileName); $fileType = end($ft); // __DIR__ is the document_repository ajax directory diff --git a/modules/training/php/training.class.inc b/modules/training/php/training.class.inc index 4c3c961f4c6..576188b77f6 100644 --- a/modules/training/php/training.class.inc +++ b/modules/training/php/training.class.inc @@ -126,9 +126,7 @@ class Training extends \NDB_Form FROM test_names WHERE Test_name LIKE CONCAT('%', :testkey, '%')", - array( - 'testkey' => $test_key - ) + array('testkey' => $test_key) ); $instruments[$testID] = $certificationInstrument['#']; }