From b3b0fe2444eb974281b50e774d7e9fdc936d59a8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 6 Jan 2023 19:34:45 +0100 Subject: [PATCH] Clean code --- .../class/accountancyexport.class.php | 2 +- htdocs/categories/class/categorie.class.php | 29 ++----------------- htdocs/compta/facture/class/facture.class.php | 12 ++++---- htdocs/compta/index.php | 20 ++++++++----- htdocs/compta/localtax/index.php | 7 +++-- htdocs/compta/tva/index.php | 5 +++- htdocs/core/class/evalmath.class.php | 12 ++++---- htdocs/core/class/html.form.class.php | 10 ++++--- htdocs/core/class/lessc.class.php | 6 ++-- htdocs/core/class/stats.class.php | 6 ++-- htdocs/core/lib/ftp.lib.php | 10 +++---- htdocs/ecm/index.php | 2 +- htdocs/ecm/index_auto.php | 2 +- htdocs/ecm/index_medias.php | 2 +- htdocs/ftp/index.php | 1 + htdocs/index.php | 6 ++-- htdocs/install/index.php | 2 +- htdocs/install/lib/repair.lib.php | 6 ++-- htdocs/main.inc.php | 4 +-- htdocs/paybox/lib/paybox.lib.php | 2 +- htdocs/public/recruitment/index.php | 2 +- htdocs/takepos/ajax/ajax.php | 3 ++ 22 files changed, 72 insertions(+), 79 deletions(-) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index ad7bfc4edad..4c6e2d09838 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -338,7 +338,7 @@ class AccountancyExport // PHP ZIP extension must be enabled if (!extension_loaded('zip')) { $langs->load('install'); - $this->errors[] = $langs->trans('ErrorPHPDoesNotSupport', 'ZIP');; + $this->errors[] = $langs->trans('ErrorPHPDoesNotSupport', 'ZIP'); return -1; } } else { diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 4c2842b2dcf..4d6e3e1736f 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -1189,8 +1189,6 @@ class Categorie extends CommonObject dol_syslog(get_class($this)."::get_full_arbo dol_sort_array", LOG_DEBUG); $this->cats = dol_sort_array($this->cats, 'fulllabel', 'asc', true, false); - //$this->debug_cats(); - return $this->cats; } @@ -1201,7 +1199,7 @@ class Categorie extends CommonObject * * @param int $id_categ id_categ entry to update * @param int $protection Deep counter to avoid infinite loop - * @return void + * @return int <0 if KO, >0 if OK * @see get_full_arbo() */ private function buildPathFromId($id_categ, $protection = 1000) @@ -1211,7 +1209,7 @@ class Categorie extends CommonObject if (!empty($this->cats[$id_categ]['fullpath'])) { // Already defined dol_syslog(get_class($this)."::buildPathFromId fullpath and fulllabel already defined", LOG_WARNING); - return; + return -1; } // First build full array $motherof @@ -1238,28 +1236,7 @@ class Categorie extends CommonObject $nbunderscore = substr_count($this->cats[$id_categ]['fullpath'], '_'); $this->cats[$id_categ]['level'] = ($nbunderscore ? $nbunderscore : null); - return; - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Display content of $this->cats - * - * @return void - */ - public function debug_cats() - { - // phpcs:enable - // Display $this->cats - foreach ($this->cats as $key => $val) { - print 'id: '.$this->cats[$key]['id']; - print ' label: '.$this->cats[$key]['label']; - print ' mother: '.$this->cats[$key]['fk_parent']; - //print ' children: '.(is_array($this->cats[$key]['id_children'])?join(',',$this->cats[$key]['id_children']):''); - print ' fullpath: '.$this->cats[$key]['fullpath']; - print ' fulllabel: '.$this->cats[$key]['fulllabel']; - print "
\n"; - } + return 1; } diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 69b2ea1c293..0a9b0dcfe16 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -4078,7 +4078,7 @@ class Facture extends CommonInvoice * * @param int $idline id of line to check * @param float $situation_percent progress percentage need to be test - * @return false if KO, true if OK + * @return bool false if KO, true if OK */ public function checkProgressLine($idline, $situation_percent) { @@ -4097,7 +4097,7 @@ class Facture extends CommonInvoice if ($obj === null) { return true; } else { - return $situation_percent < $obj->situation_percent; + return ($situation_percent < $obj->situation_percent); } } @@ -4651,8 +4651,8 @@ class Facture extends CommonInvoice * Invoices matching the following rules are returned: * (validated + payment on process) or classified (payed completely or payed partiely) + not already replaced + not already a credit note * - * @param int $socid Id thirdparty - * @return array Array of invoices ($id => array('ref'=>,'paymentornot'=>,'status'=>,'paye'=>) + * @param int $socid Id thirdparty + * @return array|int Array of invoices ($id => array('ref'=>,'paymentornot'=>,'status'=>,'paye'=>) */ public function list_qualified_avoir_invoices($socid = 0) { @@ -4726,8 +4726,8 @@ class Facture extends CommonInvoice /** * Load indicators for dashboard (this->nbtodo and this->nbtodolate) * - * @param User $user Object user - * @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK + * @param User $user Object user + * @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK */ public function load_board($user) { diff --git a/htdocs/compta/index.php b/htdocs/compta/index.php index cfec4d87238..70ea12ba4cb 100644 --- a/htdocs/compta/index.php +++ b/htdocs/compta/index.php @@ -742,21 +742,25 @@ if (isModEnabled('facture') && isModEnabled('commande') && $user->hasRight("comm // TODO Mettre ici recup des actions en rapport avec la compta -$resql = ''; -if ($resql) { +$sql = ''; +if ($sql) { print '
'; print ''; print ''.$langs->trans("TasksToDo").''; print "\n"; $i = 0; - while ($i < $db->num_rows($resql)) { - $obj = $db->fetch_object($resql); + $resql = $db->query($sql); + if ($resql) { + $num_rows = $db->num_rows($resql); + while ($i < $num_rows) { + $obj = $db->fetch_object($resql); - print ''; - print ''; - $i++; + print ''; + print ''; + $i++; + } + $db->free($resql); } - $db->free($resql); print "
'.dol_print_date($db->jdate($obj->da), "day").''.$obj->label.'
'.dol_print_date($db->jdate($obj->da), "day").''.$obj->label.'

"; } diff --git a/htdocs/compta/localtax/index.php b/htdocs/compta/localtax/index.php index fb96e766945..f25b476fa94 100644 --- a/htdocs/compta/localtax/index.php +++ b/htdocs/compta/localtax/index.php @@ -22,7 +22,7 @@ /** * \file htdocs/compta/localtax/index.php * \ingroup tax - * \brief Index page of IRPF reports + * \brief Index page of localtax reports */ require '../../main.inc.php'; @@ -259,6 +259,9 @@ llxHeader('', $name); //$textnextyear=" ".img_next().""; //print load_fiche_titre($langs->transcountry($LT,$mysoc->country_code),"$textprevyear ".$langs->trans("Year")." $year_start $textnextyear", 'bill'); +$periodlink = ''; +$exportlink = ''; + report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode); //report_header($name,'',$textprevyear.$langs->trans("Year")." ".$year_start.$textnextyear,'',$description,$builddate,$exportlink,array(),$calcmode); @@ -271,7 +274,7 @@ print load_fiche_titre($langs->transcountry($LTSummary, $mysoc->country_code), ' print ''; print ''; -print '"; +print '"; if ($CalcLT == 0) { print ''; print ''; diff --git a/htdocs/compta/tva/index.php b/htdocs/compta/tva/index.php index 5c0d6930475..37e7f75b306 100644 --- a/htdocs/compta/tva/index.php +++ b/htdocs/compta/tva/index.php @@ -229,6 +229,9 @@ llxHeader('', $name); //$textnextyear=" ".img_next($langs->trans("Next"), 'class="valignbottom"').""; //print load_fiche_titre($langs->transcountry("VAT", $mysoc->country_code), $textprevyear." ".$langs->trans("Year")." ".$year_start." ".$textnextyear, 'bill'); +$periodlink = ''; +$exportlink = ''; + report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode); //report_header($name,'',$textprevyear.$langs->trans("Year")." ".$year_start.$textnextyear,'',$description,$builddate,$exportlink,array(),$calcmode); @@ -242,7 +245,7 @@ if ($refresh === true) { print '
'.$langs->trans("Year")." ".$y."'.$langs->trans("Year")."'.$langs->transcountry($LTCustomer, $mysoc->country_code).''.$langs->transcountry($LTSupplier, $mysoc->country_code).'
'; print ''; - print ''; + print ''; print ''; print ''; print ''; diff --git a/htdocs/core/class/evalmath.class.php b/htdocs/core/class/evalmath.class.php index 9c01f133bf6..24be9731df9 100644 --- a/htdocs/core/class/evalmath.class.php +++ b/htdocs/core/class/evalmath.class.php @@ -481,7 +481,6 @@ class EvalMath */ class EvalMathStack { - public $stack = array(); public $count = 0; @@ -489,8 +488,8 @@ class EvalMathStack /** * push * - * @param string $val Val - * @return void + * @param string $val Val + * @return void */ public function push($val) { @@ -515,14 +514,15 @@ class EvalMathStack /** * last * - * @param int $n N - * @return mixed Stack + * @param int $n N + * @return mixed Stack */ public function last($n = 1) { if (isset($this->stack[$this->count - $n])) { return $this->stack[$this->count - $n]; } - return; + + return ''; } } diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index ad82ae86751..1c54df24e06 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -6444,7 +6444,7 @@ class Form * @param int $fullday When a checkbox with this html name is on, hour and day are set with 00:00 or 23:59 * @param string $addplusone Add a link "+1 hour". Value must be name of another select_date field. * @param datetime $adddateof Add a link "Date of invoice" using the following date. - * @return string|void Nothing or string if nooutput is 1 + * @return string '' or HTML component string if nooutput is 1 * @deprecated * @see selectDate(), form_date(), select_month(), select_year(), select_dayofweek() */ @@ -6456,7 +6456,8 @@ class Form return $retstring; } print $retstring; - return; + + return ''; } /** @@ -6990,7 +6991,7 @@ class Form * If 'textselect' input hour is in text and input min is a combo * @param integer $minunderhours If 1, show minutes selection under the hours * @param int $nooutput Do not output html string but return it - * @return string|void + * @return string HTML component */ public function select_duration($prefix, $iSecond = '', $disabled = 0, $typehour = 'select', $minunderhours = 0, $nooutput = 0) { @@ -7064,7 +7065,8 @@ class Form } print $retstring; - return; + + return ''; } /** diff --git a/htdocs/core/class/lessc.class.php b/htdocs/core/class/lessc.class.php index 1b764e20a35..0452cab45aa 100644 --- a/htdocs/core/class/lessc.class.php +++ b/htdocs/core/class/lessc.class.php @@ -1011,7 +1011,7 @@ class Lessc if ($list[0] == "list" && isset($list[2][$idx - 1])) { return $list[2][$idx - 1]; } - return null; + return ''; } protected function lib_isnumber($value) @@ -1306,7 +1306,7 @@ class Lessc if (!is_null($color = $this->coerceColor($value))) { return isset($color[4]) ? $color[4] : 1; } - return null; + return ''; } // set the alpha of the color @@ -1959,7 +1959,7 @@ class Lessc return $this->op_color_number($op, $rgt, $lft); } - return null; + return array(); } protected function op_color_number($op, $lft, $rgt) diff --git a/htdocs/core/class/stats.class.php b/htdocs/core/class/stats.class.php index 154b2b2158a..c8dbca747b9 100644 --- a/htdocs/core/class/stats.class.php +++ b/htdocs/core/class/stats.class.php @@ -55,7 +55,7 @@ abstract class Stats global $conf, $user, $langs; if ($startyear > $endyear) { - return -1; + return array(); } $datay = array(); @@ -156,7 +156,7 @@ abstract class Stats global $conf, $user, $langs; if ($startyear > $endyear) { - return -1; + return array(); } $datay = array(); @@ -251,7 +251,7 @@ abstract class Stats public function getAverageByMonthWithPrevYear($endyear, $startyear) { if ($startyear > $endyear) { - return -1; + return array(); } $datay = array(); diff --git a/htdocs/core/lib/ftp.lib.php b/htdocs/core/lib/ftp.lib.php index e49972a4a97..1b7cfc7ca73 100644 --- a/htdocs/core/lib/ftp.lib.php +++ b/htdocs/core/lib/ftp.lib.php @@ -161,11 +161,10 @@ function dol_ftp_close($connect_id) * @param resource $connect_id Connection handler * @param string $file File * @param string $newsection $newsection - * @return result + * @return bool */ function dol_ftp_delete($connect_id, $file, $newsection) { - global $conf; if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) { @@ -197,7 +196,6 @@ function dol_ftp_delete($connect_id, $file, $newsection) */ function dol_ftp_get($connect_id, $localfile, $file, $newsection) { - global $conf; if (!empty($conf->global->FTP_CONNECT_WITH_SFTP)) { @@ -223,7 +221,7 @@ function dol_ftp_get($connect_id, $localfile, $file, $newsection) * @param string $file File name * @param string $localfile The path to the local file * @param string $newsection $newsection - * @return boolean + * @return bool */ function dol_ftp_put($connect_id, $file, $localfile, $newsection) { @@ -251,7 +249,7 @@ function dol_ftp_put($connect_id, $file, $localfile, $newsection) * @param resource $connect_id Connection handler * @param string $file File * @param string $newsection $newsection - * @return boolean + * @return bool */ function dol_ftp_rmdir($connect_id, $file, $newsection) { @@ -280,7 +278,7 @@ function dol_ftp_rmdir($connect_id, $file, $newsection) * @param resource $connect_id Connection handler * @param string $newdir Dir create * @param string $newsection $newsection - * @return boolean|string + * @return bool|string */ function dol_ftp_mkdir($connect_id, $newdir, $newsection) { diff --git a/htdocs/ecm/index.php b/htdocs/ecm/index.php index 9eb512bc96d..6edf59dcbed 100644 --- a/htdocs/ecm/index.php +++ b/htdocs/ecm/index.php @@ -322,7 +322,7 @@ $moreheadjs .= ''."\n"; llxHeader($moreheadcss.$moreheadjs, $langs->trans("ECMArea"), '', '', '', '', $morejs, '', 0, 0); -$head = ecm_prepare_dasboard_head(''); +$head = ecm_prepare_dasboard_head(null); print dol_get_fiche_head($head, 'index', '', -1, ''); diff --git a/htdocs/ecm/index_auto.php b/htdocs/ecm/index_auto.php index 9d9d30e8188..3944e869da0 100644 --- a/htdocs/ecm/index_auto.php +++ b/htdocs/ecm/index_auto.php @@ -387,7 +387,7 @@ if (empty($conf->global->ECM_AUTO_TREE_HIDEN)) { } } -$head = ecm_prepare_dasboard_head(''); +$head = ecm_prepare_dasboard_head(null); print dol_get_fiche_head($head, 'index_auto', '', -1, ''); diff --git a/htdocs/ecm/index_medias.php b/htdocs/ecm/index_medias.php index 2e1edcdc269..39118774430 100644 --- a/htdocs/ecm/index_medias.php +++ b/htdocs/ecm/index_medias.php @@ -295,7 +295,7 @@ $moreheadjs .= ''."\n"; llxHeader($moreheadcss.$moreheadjs, $langs->trans("ECMArea"), '', '', '', '', $morejs, '', 0, 0); -$head = ecm_prepare_dasboard_head(''); +$head = ecm_prepare_dasboard_head(null); print dol_get_fiche_head($head, 'index_medias', '', -1, ''); diff --git a/htdocs/ftp/index.php b/htdocs/ftp/index.php index 633cb6fa5ce..e6c1aac1372 100644 --- a/htdocs/ftp/index.php +++ b/htdocs/ftp/index.php @@ -154,6 +154,7 @@ if ($action == 'addfolder') { // Action ajout d'un rep if ($action == 'add' && $user->rights->ftp->setup) { + $ecmdir = new EcmDirectory($db); $ecmdir->ref = GETPOST("ref"); $ecmdir->label = GETPOST("label"); $ecmdir->description = GETPOST("desc"); diff --git a/htdocs/index.php b/htdocs/index.php index 7cfd12d4bac..f1ce8248921 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -490,7 +490,7 @@ if (empty($conf->global->MAIN_DISABLE_GLOBAL_WORKBOARD)) { foreach ($dashboardgroup as $groupKey => $groupElement) { $boards = array(); - // Scan $groupElement and save the one with 'stats' that lust be used for Open object dashboard + // Scan $groupElement and save the one with 'stats' that must be used for the open objects dashboard if (empty($conf->global->MAIN_DISABLE_NEW_OPENED_DASH_BOARD)) { foreach ($groupElement['stats'] as $infoKey) { if (!empty($valid_dashboardlines[$infoKey])) { @@ -519,10 +519,10 @@ if (empty($conf->global->MAIN_DISABLE_GLOBAL_WORKBOARD)) { $openedDashBoard .= ' '."\n"; $openedDashBoard .= ' '."\n"; - // Show the span for the total of record + // Show the span for the total of record. TODO This seems not used. if (!empty($groupElement['globalStats'])) { $globalStatInTopOpenedDashBoard[] = $globalStatsKey; - $openedDashBoard .= ''.$nbTotal.''; + $openedDashBoard .= ''.$groupElement['globalStats']['nbTotal'].''; } $openedDashBoard .= ''."\n"; diff --git a/htdocs/install/index.php b/htdocs/install/index.php index a7ce50c819f..6810e3c509f 100644 --- a/htdocs/install/index.php +++ b/htdocs/install/index.php @@ -44,7 +44,7 @@ $langs->load("admin"); * View */ -$formadmin = new FormAdmin(''); // Note: $db does not exist yet but we don't need it, so we put ''. +$formadmin = new FormAdmin(null); // Note: $db does not exist yet but we don't need it, so we put ''. pHeader("", "check"); // Next step = check diff --git a/htdocs/install/lib/repair.lib.php b/htdocs/install/lib/repair.lib.php index aea82107d29..c7c45dff053 100644 --- a/htdocs/install/lib/repair.lib.php +++ b/htdocs/install/lib/repair.lib.php @@ -125,7 +125,7 @@ function checkLinkedElements($sourcetype, $targettype) /** * Clean data into ecm_directories table * - * @return void + * @return int <0 if KO, >0 if OK */ function clean_data_ecm_directories() { @@ -145,12 +145,14 @@ function clean_data_ecm_directories() $resqlupdate = $db->query($sqlupdate); if (!$resqlupdate) { dol_print_error($db, 'Failed to update'); + return -1; } } } } else { dol_print_error($db, 'Failed to run request'); + return -1; } - return; + return 1; } diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index d8eb602f624..17912f81101 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -1413,7 +1413,7 @@ if (!function_exists("llxHeader")) { } if (empty($conf->dol_hide_leftmenu) && !GETPOST('dol_openinpopup', 'aZ09')) { - left_menu('', $help_url, '', '', 1, $title, 1); // $menumanager is retrieved with a global $menumanager inside this function + left_menu(array(), $help_url, '', '', 1, $title, 1); // $menumanager is retrieved with a global $menumanager inside this function } // main area @@ -2885,7 +2885,7 @@ function left_menu($menu_array_before, $helppagename = '', $notused = '', $menu_ $selected = -1; if (empty($conf->global->MAIN_USE_TOP_MENU_SEARCH_DROPDOWN)) { $usedbyinclude = 1; - $arrayresult = null; + $arrayresult = array(); include DOL_DOCUMENT_ROOT.'/core/ajax/selectsearchbox.php'; // This set $arrayresult if ($conf->use_javascript_ajax && empty($conf->global->MAIN_USE_OLD_SEARCH_FORM)) { diff --git a/htdocs/paybox/lib/paybox.lib.php b/htdocs/paybox/lib/paybox.lib.php index 7f41d45d374..567a4b91669 100644 --- a/htdocs/paybox/lib/paybox.lib.php +++ b/htdocs/paybox/lib/paybox.lib.php @@ -225,5 +225,5 @@ function print_paybox_redirect($PRICE, $CURRENCY, $EMAIL, $urlok, $urlko, $TAG) print ''."\n"; print "\n"; - return; + return 1; } diff --git a/htdocs/public/recruitment/index.php b/htdocs/public/recruitment/index.php index 23a180b9a7b..8724e65ca4f 100644 --- a/htdocs/public/recruitment/index.php +++ b/htdocs/public/recruitment/index.php @@ -252,7 +252,7 @@ if (is_array($results)) { } } print ''; - print $tmpuser->getFullName(-1); + print $tmpuser->getFullName(); print '   '.dol_print_email($emailforcontact, 0, 0, 1, 0, 0, 'envelope'); print ''; print '
'; diff --git a/htdocs/takepos/ajax/ajax.php b/htdocs/takepos/ajax/ajax.php index db6b224466c..87357d10091 100644 --- a/htdocs/takepos/ajax/ajax.php +++ b/htdocs/takepos/ajax/ajax.php @@ -370,6 +370,9 @@ if ($action == 'getProducts') { $place = GETPOST('place', 'alpha'); require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php'; + + $object = new Facture($db); + $printer = new dolReceiptPrinter($db); $printer->sendToPrinter($object, getDolGlobalString('TAKEPOS_TEMPLATE_TO_USE_FOR_INVOICES'.$term), getDolGlobalString('TAKEPOS_PRINTER_TO_USE'.$term)); }
' . $langs->trans("Year") . " " . $y . '' . $langs->trans("Year") . '' . $langs->trans("VATToPay") . '' . $langs->trans("VATToCollect") . '' . $langs->trans("Balance") . '