From 608e6658506f95851df823419914c2b516821c6d Mon Sep 17 00:00:00 2001 From: kurund Date: Wed, 14 Jan 2015 19:15:55 +0530 Subject: [PATCH] code cleanup --- CRM/ACL/Form/WordPress/Permissions.php | 4 +- CRM/Admin/Form/WordReplacements.php | 4 +- CRM/Campaign/Page/AJAX.php | 20 ++++----- CRM/Case/Form/Task/Restore.php | 2 +- CRM/Contact/BAO/GroupContact.php | 23 +++++------ CRM/Contact/Form/Domain.php | 1 - CRM/Contact/Page/View/Sunlight.php | 2 +- CRM/Contact/Page/View/Tag.php | 2 +- CRM/Contact/StateMachine/Search.php | 2 +- CRM/Core/BAO/ConfigSetting.php | 25 ++++++----- CRM/Core/BAO/MessageTemplate.php | 21 ++++------ CRM/Core/BAO/UFField.php | 21 ++++------ CRM/Core/Form/Tag.php | 2 +- CRM/Core/Permission/UnitTests.php | 2 +- CRM/Dashlet/Page/Blog.php | 2 +- .../Registration/AdditionalParticipant.php | 20 ++++----- CRM/Event/Form/Registration/Register.php | 5 +-- CRM/Event/Page/ManageEvent.php | 41 +++++++++---------- CRM/Grant/Form/Task.php | 2 +- CRM/Member/BAO/Membership.php | 39 +++++++++--------- CRM/Member/BAO/MembershipLog.php | 1 - CRM/PCP/Page/PCPInfo.php | 2 +- CRM/Utils/Geocode/Yahoo.php | 4 +- CRM/Utils/Recent.php | 2 +- CRM/Utils/String.php | 19 ++++----- Civi/CCase/Analyzer.php | 2 +- api/v3/Job.php | 20 ++++----- api/v3/UFGroup.php | 4 +- bin/cleanup42.php | 3 ++ .../main.php | 20 ++++----- tests/phpunit/CRM/Contact/AllTests.php | 2 +- tests/phpunit/CRM/Core/TransactionTest.php | 19 ++++----- tests/phpunit/CRM/Mailing/BAO/QueryTest.php | 2 +- tests/phpunit/Civi/AllTests.php | 2 +- 34 files changed, 163 insertions(+), 179 deletions(-) diff --git a/CRM/ACL/Form/WordPress/Permissions.php b/CRM/ACL/Form/WordPress/Permissions.php index 489bd60757..acd6254449 100644 --- a/CRM/ACL/Form/WordPress/Permissions.php +++ b/CRM/ACL/Form/WordPress/Permissions.php @@ -90,7 +90,7 @@ class CRM_ACL_Form_WordPress_Permissions extends CRM_Core_Form { 'type' => 'next', 'name' => ts('Save'), 'spacing' => '', - 'isDefault' => FALSE + 'isDefault' => FALSE, ), ) ); @@ -143,7 +143,7 @@ class CRM_ACL_Form_WordPress_Permissions extends CRM_Core_Form { CRM_Core_Session::setStatus( ts('The %1 role was assigned one or more permissions that may prove dangerous for users of that role to have. Please reconsider assigning %2 to them.', array( 1 => $wp_roles->role_names[$role], - 2 => implode(', ', $warningPermissionNames) + 2 => implode(', ', $warningPermissionNames), )), ts('Unsafe Permission Settings') ); diff --git a/CRM/Admin/Form/WordReplacements.php b/CRM/Admin/Form/WordReplacements.php index 4394353ba6..b0d0db63a2 100644 --- a/CRM/Admin/Form/WordReplacements.php +++ b/CRM/Admin/Form/WordReplacements.php @@ -55,7 +55,7 @@ class CRM_Admin_Form_WordReplacements extends CRM_Core_Form { array( 'title' => ts('Word Replacements'), 'url' => $breadCrumbUrl, - ) + ), ); CRM_Utils_System::appendBreadCrumb($breadCrumb); } @@ -219,7 +219,7 @@ class CRM_Admin_Form_WordReplacements extends CRM_Core_Form { */ public function postProcess() { $params = $this->controller->exportValues($this->_name); - $this->_numStrings = sizeof($params['old']); + $this->_numStrings = count($params['old']); $enabled['exactMatch'] = $enabled['wildcardMatch'] = $disabled['exactMatch'] = $disabled['wildcardMatch'] = array(); for ($i = 1; $i <= $this->_numStrings; $i++) { diff --git a/CRM/Campaign/Page/AJAX.php b/CRM/Campaign/Page/AJAX.php index b8cf42de6d..b6aeb8ffc5 100644 --- a/CRM/Campaign/Page/AJAX.php +++ b/CRM/Campaign/Page/AJAX.php @@ -158,7 +158,7 @@ class CRM_Campaign_Page_AJAX { //format multi-select group and contact types. foreach (array( 'group', - 'contact_type' + 'contact_type', ) as $param) { $paramValue = CRM_Utils_Array::value($param, $params); if ($paramValue) { @@ -174,7 +174,7 @@ class CRM_Campaign_Page_AJAX { foreach (array( 'campaign_survey_id', 'survey_interviewer_id', - 'campaign_search_voter_for' + 'campaign_search_voter_for', ) as $fld) { $voterClauseParams[$fld] = CRM_Utils_Array::value($fld, $params); } @@ -499,7 +499,7 @@ class CRM_Campaign_Page_AJAX { array( 'value' => '', 'title' => ts('- select -'), - ) + ), ); foreach ($campaigns as $value => $title) { $class = NULL; @@ -546,7 +546,7 @@ class CRM_Campaign_Page_AJAX { array( 'value' => '', 'title' => ts('- select -'), - ) + ), ); foreach ($campGroups as $grpId => $title) { $groups[] = array( @@ -565,7 +565,7 @@ class CRM_Campaign_Page_AJAX { /** * Retrieve campaigns as for campaign dashboard. * - **/ + */ public function campaignList() { //get the search criteria params. $searchParams = explode(',', CRM_Utils_Array::value('searchCriteria', $_POST)); @@ -635,7 +635,7 @@ class CRM_Campaign_Page_AJAX { 'sort', 'offset', 'rowCount', - 'sortOrder' + 'sortOrder', ) as $sortParam) { $params[$sortParam] = $$sortParam; } @@ -666,7 +666,7 @@ class CRM_Campaign_Page_AJAX { /** * Retrieve survey for survey dashboard. * - **/ + */ public function surveyList() { //get the search criteria params. $searchParams = explode(',', CRM_Utils_Array::value('searchCriteria', $_POST)); @@ -738,7 +738,7 @@ class CRM_Campaign_Page_AJAX { 'sort', 'offset', 'rowCount', - 'sortOrder' + 'sortOrder', ) as $sortParam) { $params[$sortParam] = $$sortParam; } @@ -769,7 +769,7 @@ class CRM_Campaign_Page_AJAX { /** * Retrieve petitions for petition dashboard. * - **/ + */ public function petitionList() { //get the search criteria params. $searchParams = explode(',', CRM_Utils_Array::value('searchCriteria', $_POST)); @@ -836,7 +836,7 @@ class CRM_Campaign_Page_AJAX { 'sort', 'offset', 'rowCount', - 'sortOrder' + 'sortOrder', ) as $sortParam) { $params[$sortParam] = $$sortParam; } diff --git a/CRM/Case/Form/Task/Restore.php b/CRM/Case/Form/Task/Restore.php index 2709c8171d..93bbaa0f90 100644 --- a/CRM/Case/Form/Task/Restore.php +++ b/CRM/Case/Form/Task/Restore.php @@ -53,7 +53,7 @@ class CRM_Case_Form_Task_Restore extends CRM_Case_Form_Task { * * @return void */ - function preProcess() { + public function preProcess() { parent::preProcess(); } diff --git a/CRM/Contact/BAO/GroupContact.php b/CRM/Contact/BAO/GroupContact.php index bfadfc54b8..72be26a332 100644 --- a/CRM/Contact/BAO/GroupContact.php +++ b/CRM/Contact/BAO/GroupContact.php @@ -73,7 +73,7 @@ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact { * @param array $params * (reference ) an assoc array of name/value pairs. * - * @return boolean + * @return bool */ public static function dataExists(&$params) { // return if no data present @@ -129,7 +129,7 @@ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact { * @return array * (total, added, notAdded) count of contacts added to group */ - static function addContactsToGroup( + public static function addContactsToGroup( $contactIds, $groupId, $method = 'Admin', @@ -137,7 +137,6 @@ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact { $tracking = NULL ) { - CRM_Utils_Hook::pre('create', 'GroupContact', $groupId, $contactIds); list($numContactsAdded, @@ -179,7 +178,7 @@ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact { * @return array * (total, removed, notRemoved) count of contacts removed to group */ - static function removeContactsFromGroup( + public static function removeContactsFromGroup( &$contactIds, $groupId, $method = 'Admin', @@ -329,13 +328,11 @@ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact { * * @param bool $excludeHidden * - * @return array - * (reference )|int $values the relevant data object values for the contact or - * the total count when $count is TRUE - * - * $access public + * @return array (reference)|int $values + * the relevant data object values for the contact or + * the total count when $count is TRUE */ - static function &getContactGroup( + public static function &getContactGroup( $contactId, $status = NULL, $numGroupContact = NULL, @@ -720,7 +717,7 @@ AND group_id IN ( $groupIDString ) * @return array * (total, added, notAdded) count of contacts added to group */ - static function bulkAddContactsToGroup( + public static function bulkAddContactsToGroup( $contactIDs, $groupID, $method = 'Admin', @@ -797,11 +794,11 @@ AND contact_id IN ( $contactStr ) * * @param string $fieldName * @param string $context - * @see CRM_Core_DAO::buildOptionsContext. + * @see CRM_Core_DAO::buildOptionsContext * @param array $props * whatever is known about this dao object. * - * @return Array|bool + * @return array|bool */ public static function buildOptions($fieldName, $context = NULL, $props = array()) { $params = array(); diff --git a/CRM/Contact/Form/Domain.php b/CRM/Contact/Form/Domain.php index 22328fb9db..d749ee8eaf 100644 --- a/CRM/Contact/Form/Domain.php +++ b/CRM/Contact/Form/Domain.php @@ -298,7 +298,6 @@ class CRM_Contact_Form_Domain extends CRM_Core_Form { $emailParams['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues); } - //reset default within domain. $emailParams['reset_default_for'] = array('domain_id' => CRM_Core_Config::domainID()); diff --git a/CRM/Contact/Page/View/Sunlight.php b/CRM/Contact/Page/View/Sunlight.php index 09b2d1148f..9bd21723e9 100644 --- a/CRM/Contact/Page/View/Sunlight.php +++ b/CRM/Contact/Page/View/Sunlight.php @@ -37,7 +37,7 @@ class CRM_Contact_Page_View_Sunlight extends CRM_Contact_Page_View { /** * called when action is browse * - * @return null + * @return void */ public function browse() { // get the primary city, state and zip for the contact diff --git a/CRM/Contact/Page/View/Tag.php b/CRM/Contact/Page/View/Tag.php index dd9e83f736..7e902626c5 100644 --- a/CRM/Contact/Page/View/Tag.php +++ b/CRM/Contact/Page/View/Tag.php @@ -37,7 +37,7 @@ class CRM_Contact_Page_View_Tag extends CRM_Core_Page { /** * called when action is browse * - * @return null + * @return void */ public function browse() { $controller = new CRM_Core_Controller_Simple('CRM_Tag_Form_Tag', ts('Contact Tags'), $this->_action); diff --git a/CRM/Contact/StateMachine/Search.php b/CRM/Contact/StateMachine/Search.php index 2b35e17f34..9dc31c61a8 100644 --- a/CRM/Contact/StateMachine/Search.php +++ b/CRM/Contact/StateMachine/Search.php @@ -44,7 +44,7 @@ class CRM_Contact_StateMachine_Search extends CRM_Core_StateMachine { /** * Class constructor */ - function __construct($controller, $action = CRM_Core_Action::NONE) { + public function __construct($controller, $action = CRM_Core_Action::NONE) { parent::__construct($controller, $action); $this->_pages = array(); diff --git a/CRM/Core/BAO/ConfigSetting.php b/CRM/Core/BAO/ConfigSetting.php index 546b145ac7..4b2a5f2709 100644 --- a/CRM/Core/BAO/ConfigSetting.php +++ b/CRM/Core/BAO/ConfigSetting.php @@ -47,7 +47,7 @@ class CRM_Core_BAO_ConfigSetting { * @param array $params * Associated array of civicrm variables. * - * @return null + * @return void */ public static function create($params) { self::add($params); @@ -63,7 +63,7 @@ class CRM_Core_BAO_ConfigSetting { * @param array $params * Associated array of civicrm variables. * - * @return null + * @return void */ public static function add(&$params) { self::fixParams($params); @@ -71,8 +71,8 @@ class CRM_Core_BAO_ConfigSetting { // also set a template url so js files can use this // CRM-6194 $params['civiRelativeURL'] = CRM_Utils_System::url('CIVI_BASE_TEMPLATE'); - $params['civiRelativeURL'] = - str_replace( + $params['civiRelativeURL'] + = str_replace( 'CIVI_BASE_TEMPLATE', '', $params['civiRelativeURL'] @@ -144,7 +144,7 @@ class CRM_Core_BAO_ConfigSetting { * @param array $params * Associated array of civicrm variables. * - * @return null + * @return void */ public static function fixParams(&$params) { // in our old civicrm.settings.php we were using ISO code for country and @@ -178,7 +178,7 @@ class CRM_Core_BAO_ConfigSetting { * @param array $values * Associated array of civicrm variables stored in db. * - * @return null + * @return void */ public static function formatParams(&$params, &$values) { if (empty($params) || @@ -228,7 +228,7 @@ class CRM_Core_BAO_ConfigSetting { $defaults = unserialize($domain->config_backend); if ($defaults === FALSE || !is_array($defaults)) { $defaults = array(); - return; + return FALSE; } $skipVars = self::skipVars(); @@ -519,7 +519,6 @@ class CRM_Core_BAO_ConfigSetting { list($oldURL, $oldDir, $oldSiteName, $oldSiteRoot) = self::getConfigSettings(); list($newURL, $newDir, $newSiteName, $newSiteRoot) = self::getBestGuessSettings(); - // retrieve these values from the argument list $variables = array('URL', 'Dir', 'SiteName', 'SiteRoot', 'Val_1', 'Val_2', 'Val_3'); $states = array('old', 'new'); @@ -656,7 +655,7 @@ WHERE option_group_id = ( * @param string $componentName * Name of the component to be enabled, needs to be valid. * - * @return boolean + * @return bool * true if valid component name and enabling succeeds, else false */ public static function enableComponent($componentName) { @@ -672,8 +671,8 @@ WHERE option_group_id = ( } // get enabled-components from DB and add to the list - $enabledComponents = - CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enable_components', NULL, array()); + $enabledComponents + = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enable_components', NULL, array()); $enabledComponents[] = $componentName; self::setEnabledComponents($enabledComponents); @@ -691,8 +690,8 @@ WHERE option_group_id = ( } // get enabled-components from DB and add to the list - $enabledComponents = - CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enable_components', NULL, array()); + $enabledComponents + = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enable_components', NULL, array()); $enabledComponents = array_diff($enabledComponents, array($componentName)); self::setEnabledComponents($enabledComponents); diff --git a/CRM/Core/BAO/MessageTemplate.php b/CRM/Core/BAO/MessageTemplate.php index eeb4f5448f..591fcd3320 100644 --- a/CRM/Core/BAO/MessageTemplate.php +++ b/CRM/Core/BAO/MessageTemplate.php @@ -99,10 +99,8 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate { /** * Delete the Message Templates * - * * @param int $messageTemplatesID - * - * @return object + * @return void */ public static function del($messageTemplatesID) { // make sure messageTemplatesID is an integer @@ -229,7 +227,7 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate { $smarty = CRM_Core_Smarty::singleton(); foreach (array( 'text', - 'html' + 'html', ) as $elem) { $$elem = $smarty->fetch("string:{$$elem}"); } @@ -274,12 +272,12 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate { /** * Revert a message template to its default subject+text+HTML state * - * @param int id id of the template + * @param int $id id of the template * * @return void */ public static function revert($id) { - $diverted = new self; + $diverted = new CRM_Core_BAO_MessageTemplate(); $diverted->id = (int) $id; $diverted->find(1); @@ -287,7 +285,7 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate { CRM_Core_Error::fatal(ts('Did not find a message template with id of %1.', array(1 => $id))); } - $orig = new self; + $orig = new CRM_Core_BAO_MessageTemplate(); $orig->workflow_id = $diverted->workflow_id; $orig->is_reserved = 1; $orig->find(1); @@ -379,7 +377,7 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate { else { CRM_Core_Error::fatal(ts('No such message template: option group %1, option value %2.', array( 1 => $params['groupName'], - 2 => $params['valueName'] + 2 => $params['valueName'], ))); } } @@ -409,7 +407,7 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate { // replace tokens in the three elements (in subject as if it was the text body) $domain = CRM_Core_BAO_Domain::getDomain(); $hookTokens = array(); - $mailing = new CRM_Mailing_BAO_Mailing; + $mailing = new CRM_Mailing_BAO_Mailing(); $mailing->body_text = $text; $mailing->body_html = $html; $tokens = $mailing->getTokens(); @@ -452,7 +450,6 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate { $text = CRM_Utils_Token::replaceContactTokens($text, $contact, FALSE, $tokens['text'], FALSE, TRUE); $html = CRM_Utils_Token::replaceContactTokens($html, $contact, FALSE, $tokens['html'], FALSE, TRUE); - $contactArray = array($contactID => $contact); CRM_Utils_Hook::tokenValues($contactArray, array($contactID), @@ -472,8 +469,6 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate { $subject = "{strip}$subject{/strip}"; // parse the three elements with Smarty - - $smarty = CRM_Core_Smarty::singleton(); foreach ($params['tplParams'] as $name => $value) { $smarty->assign($name, $value); @@ -481,7 +476,7 @@ class CRM_Core_BAO_MessageTemplate extends CRM_Core_DAO_MessageTemplate { foreach (array( 'subject', 'text', - 'html' + 'html', ) as $elem) { $$elem = $smarty->fetch("string:{$$elem}"); } diff --git a/CRM/Core/BAO/UFField.php b/CRM/Core/BAO/UFField.php index 0781e9e554..6abb7e34c6 100644 --- a/CRM/Core/BAO/UFField.php +++ b/CRM/Core/BAO/UFField.php @@ -106,7 +106,7 @@ class CRM_Core_BAO_UFField extends CRM_Core_DAO_UFField { * @param int $id * Field Id. * - * @return boolean + * @return bool * */ public static function del($id) { @@ -360,7 +360,7 @@ WHERE cf.id IN (" . $customFieldIds . ") AND is_multiple = 1 LIMIT 0,1"; * * @param int $UFFieldId * - * @return boolean + * @return bool * false if custom field are disabled else true */ public static function checkUFStatus($UFFieldId) { @@ -450,11 +450,11 @@ WHERE cf.id IN (" . $customFieldIds . ") AND is_multiple = 1 LIMIT 0,1"; * @param array $optional * Array of types those are optional. * - * @return boolean + * @return bool */ public static function checkValidProfileType($ufGroupId, $required, $optional = NULL) { if (!is_array($required) || empty($required)) { - return; + return FALSE; } $ufGroup = new CRM_Core_DAO_UFGroup(); @@ -569,7 +569,6 @@ WHERE cf.id IN (" . $customFieldIds . ") AND is_multiple = 1 LIMIT 0,1"; * @return string * profile group_type * - * TODO Why is this function in this class? It seems to be about the UFGroup. */ public static function getProfileType($ufGroupId, $returnMixType = TRUE, $onlyPure = FALSE, $skipComponentType = FALSE) { $ufGroup = new CRM_Core_DAO_UFGroup(); @@ -590,10 +589,8 @@ WHERE cf.id IN (" . $customFieldIds . ") AND is_multiple = 1 LIMIT 0,1"; * True if only pure profiles are required. * @param bool $skipComponentType * - * @return string - * profile group_type + * @return string profile group_type * - * TODO Why is this function in this class? It seems to be about the UFGroup. */ public static function calculateProfileType($ufGroupType, $returnMixType = TRUE, $onlyPure = FALSE, $skipComponentType = FALSE) { // profile types @@ -728,7 +725,7 @@ SELECT ufg.id as id * * @param int $profileID * - * @return boolean + * @return bool */ public static function checkSearchableORInSelector($profileID) { $result = FALSE; @@ -802,7 +799,7 @@ SELECT id 'return' => 'field_name, is_required', 'options' => array( 'limit' => 0, - ) + ), ) )); //check for valid fields ( fields that are present in billing block ) @@ -831,7 +828,7 @@ SELECT id } if (!in_array($prefixName, $validProfileFields)) { - return; + return FALSE; } if (!empty($index) && ( @@ -1029,7 +1026,7 @@ SELECT id )); //unset selected fields foreach ($groupFieldList as $key => $value) { - if (is_integer($key)) { + if (is_int($key)) { unset($fields['Individual'][$value], $fields['Household'][$value], $fields['Organization'][$value]); continue; } diff --git a/CRM/Core/Form/Tag.php b/CRM/Core/Form/Tag.php index 50c182feea..2a00429676 100644 --- a/CRM/Core/Form/Tag.php +++ b/CRM/Core/Form/Tag.php @@ -60,7 +60,7 @@ class CRM_Core_Form_Tag { * * @return void */ - static function buildQuickForm( + public static function buildQuickForm( &$form, $parentNames, $entityTable, $entityId = NULL, $skipTagCreate = FALSE, $skipEntityAction = FALSE, $tagsetElementName = NULL) { $tagset = $form->_entityTagValues = array(); diff --git a/CRM/Core/Permission/UnitTests.php b/CRM/Core/Permission/UnitTests.php index 904703fc7f..2e5043f1e3 100644 --- a/CRM/Core/Permission/UnitTests.php +++ b/CRM/Core/Permission/UnitTests.php @@ -47,7 +47,7 @@ class CRM_Core_Permission_UnitTests extends CRM_Core_Permission_Base { * @param string $str * The permission to check. * - * @return boolean + * @return bool * true if yes, else false */ public function check($str) { diff --git a/CRM/Dashlet/Page/Blog.php b/CRM/Dashlet/Page/Blog.php index 60069a94fd..c76d86b678 100644 --- a/CRM/Dashlet/Page/Blog.php +++ b/CRM/Dashlet/Page/Blog.php @@ -117,7 +117,7 @@ class CRM_Dashlet_Page_Blog extends CRM_Core_Page { $item = (array) $item; // Clean up description - remove tags that would break dashboard layout $description = preg_replace('#]*>(.+?)]*>#s', '

$1

', $item['description']); - $item['description'] = strip_tags($description, "