浏览代码

Clean code

Laurent Destailleur 2 年之前
父节点
当前提交
382f45ec14
共有 31 个文件被更改,包括 95 次插入63 次删除
  1. 5 5
      htdocs/api/class/api_access.class.php
  2. 1 1
      htdocs/core/class/CMailFile.class.php
  3. 2 2
      htdocs/core/class/commondocgenerator.class.php
  4. 1 1
      htdocs/core/class/hookmanager.class.php
  5. 8 8
      htdocs/core/class/html.form.class.php
  6. 5 0
      htdocs/core/class/lessc.class.php
  7. 1 1
      htdocs/core/class/rssparser.class.php
  8. 1 1
      htdocs/core/js/lib_notification.js.php
  9. 1 4
      htdocs/core/js/timesheet.js
  10. 2 2
      htdocs/core/lib/functions.lib.php
  11. 1 1
      htdocs/core/lib/images.lib.php
  12. 1 1
      htdocs/core/lib/pdf.lib.php
  13. 1 1
      htdocs/core/modules/import/import_csv.modules.php
  14. 1 1
      htdocs/core/modules/import/import_xlsx.modules.php
  15. 2 2
      htdocs/core/modules/import/modules_import.php
  16. 1 1
      htdocs/debugbar/class/DataCollector/DolConfigCollector.php
  17. 1 1
      htdocs/debugbar/class/DataCollector/DolExceptionsCollector.php
  18. 1 1
      htdocs/debugbar/class/DataCollector/DolMemoryCollector.php
  19. 1 1
      htdocs/debugbar/class/DataCollector/DolMessagesCollector.php
  20. 1 1
      htdocs/debugbar/class/DataCollector/DolRequestDataCollector.php
  21. 1 1
      htdocs/debugbar/class/DataCollector/DolTimeDataCollector.php
  22. 1 1
      htdocs/debugbar/class/DebugBar.php
  23. 5 0
      htdocs/don/class/don.class.php
  24. 1 1
      htdocs/expensereport/card.php
  25. 11 0
      htdocs/exports/class/export.class.php
  26. 15 10
      htdocs/imports/class/import.class.php
  27. 2 2
      htdocs/modulebuilder/index.php
  28. 2 2
      htdocs/public/stripe/ipn.php
  29. 5 6
      htdocs/societe/class/api_thirdparties.class.php
  30. 3 3
      htdocs/takepos/index.php
  31. 11 1
      qodana.yaml

+ 5 - 5
htdocs/api/class/api_access.class.php

@@ -30,11 +30,11 @@ require_once DOL_DOCUMENT_ROOT.'/includes/restler/framework/Luracast/Restler/iUs
 require_once DOL_DOCUMENT_ROOT.'/includes/restler/framework/Luracast/Restler/Resources.php';
 require_once DOL_DOCUMENT_ROOT.'/includes/restler/framework/Luracast/Restler/Defaults.php';
 require_once DOL_DOCUMENT_ROOT.'/includes/restler/framework/Luracast/Restler/RestException.php';
-use \Luracast\Restler\iAuthenticate;
-use \Luracast\Restler\iUseAuthentication;
-use \Luracast\Restler\Resources;
-use \Luracast\Restler\Defaults;
-use \Luracast\Restler\RestException;
+use Luracast\Restler\iAuthenticate;
+use Luracast\Restler\iUseAuthentication;
+use Luracast\Restler\Resources;
+use Luracast\Restler\Defaults;
+use Luracast\Restler\RestException;
 
 /**
  * Dolibarr API access class

+ 1 - 1
htdocs/core/class/CMailFile.class.php

@@ -1350,7 +1350,7 @@ class CMailFile
 	/**
 	 * Build a css style (mode = all) into this->styleCSS and this->bodyCSS
 	 *
-	 * @return string
+	 * @return void
 	 */
 	public function buildCSS()
 	{

+ 2 - 2
htdocs/core/class/commondocgenerator.class.php

@@ -1535,8 +1535,8 @@ abstract class CommonDocGenerator
 	/**
 	 *  get column status from column key
 	 *
-	 *  @param	string			$colKey    		the column key
-	 *  @return	float      width in mm
+	 *  @param	string		$colKey    		the column key
+	 *  @return	boolean						true if column on
 	 */
 	public function getColumnStatus($colKey)
 	{

+ 1 - 1
htdocs/core/class/hookmanager.class.php

@@ -148,7 +148,7 @@ class HookManager
 	 *  @param		array	$parameters		Array of parameters
 	 *  @param		Object	$object			Object to use hooks on
 	 *  @param		string	$action			Action code on calling page ('create', 'edit', 'view', 'add', 'update', 'delete'...)
-	 *  @return		mixed					For 'addreplace' hooks (doActions, formConfirm, formObjectOptions, pdf_xxx,...): 	Return 0 if we want to keep standard actions, >0 if we want to stop/replace standard actions, <0 if KO. Things to print are returned into ->resprints and set into ->resPrint. Things to return are returned into ->results by hook and set into ->resArray for caller.
+	 *  @return		int						For 'addreplace' hooks (doActions, formConfirm, formObjectOptions, pdf_xxx,...): 	Return 0 if we want to keep standard actions, >0 if we want to stop/replace standard actions, <0 if KO. Things to print are returned into ->resprints and set into ->resPrint. Things to return are returned into ->results by hook and set into ->resArray for caller.
 	 *                                      For 'output' hooks (printLeftBlock, formAddObjectLine, formBuilddocOptions, ...):	Return 0 if we want to keep standard actions, >0 uf we want to stop/replace standard actions (at least one > 0 and replacement will be done), <0 if KO. Things to print are returned into ->resprints and set into ->resPrint. Things to return are returned into ->results by hook and set into ->resArray for caller.
 	 *                                      All types can also return some values into an array ->results that will be finaly merged into this->resArray for caller.
 	 *                                      $this->error or this->errors are also defined by class called by this function if error.

+ 8 - 8
htdocs/core/class/html.form.class.php

@@ -9987,14 +9987,14 @@ class Form
 	/**
 	 * Return HTML to show the select of expense categories
 	 *
-	 * @param string $selected preselected category
-	 * @param string $htmlname name of HTML select list
-	 * @param integer $useempty 1=Add empty line
-	 * @param array $excludeid id to exclude
-	 * @param string $target htmlname of target select to bind event
-	 * @param int $default_selected default category to select if fk_c_type_fees change = EX_KME
-	 * @param array $params param to give
-	 * @param int $info_admin Show the tooltip help picto to setup list
+	 * @param string 	$selected 		preselected category
+	 * @param string 	$htmlname 		name of HTML select list
+	 * @param integer 	$useempty 		1=Add empty line
+	 * @param array 	$excludeid 		id to exclude
+	 * @param string 	$target 		htmlname of target select to bind event
+	 * @param int 		$default_selected default category to select if fk_c_type_fees change = EX_KME
+	 * @param array 	$params 		param to give
+	 * @param int 		$info_admin 	Show the tooltip help picto to setup list
 	 * @return    string
 	 */
 	public function selectExpenseCategories($selected = '', $htmlname = 'fk_c_exp_tax_cat', $useempty = 0, $excludeid = array(), $target = '', $default_selected = 0, $params = array(), $info_admin = 1)

+ 5 - 0
htdocs/core/class/lessc.class.php

@@ -53,6 +53,11 @@ class Lessc
 	public $importDisabled = false;
 	public $importDir = '';
 
+	public $scope;
+	public $formatter;
+	public $env;
+	public $count;
+
 	protected $numberPrecision = null;
 
 	protected $allParsedFiles = array();

+ 1 - 1
htdocs/core/class/rssparser.class.php

@@ -667,7 +667,7 @@ class RssParser
 
 
 	/**
-	 * 	To concat 2 string with no warning if an operand is not defined
+	 * 	To concat 2 strings with no warning if an operand is not defined
 	 *
 	 * 	@param	string	$str1		Str1
 	 *  @param	string	$str2		Str2

+ 1 - 1
htdocs/core/js/lib_notification.js.php

@@ -75,7 +75,7 @@ if ("Notification" in window) {
 	/* Check if permission ok */
 	if (Notification.permission !== "granted") {
 		console.log("Ask Notification.permission");
-		Notification.requestPermission()
+		Notification.requestPermission();
 	}
 
 	/* Launch timer */

+ 1 - 4
htdocs/core/js/timesheet.js

@@ -72,12 +72,9 @@ function regexEvent(objet,evt,type)
                   // ((charCode>=96) && (charCode<=105)) || //numpad
             	  return true;
 
-              }else
-              {
+              } else {
                   return false;
               }
-
-              break;
           default:
               break;
       }

+ 2 - 2
htdocs/core/lib/functions.lib.php

@@ -735,7 +735,7 @@ function GETPOST($paramname, $check = 'alphanohtml', $method = 0, $filter = null
 									$qualified = 1;
 								}
 
-								if ($qualified) {
+								if ($qualified && isset($user->default_values[$relativepathstring]['filters'][$defkey][$paramname])) {
 									// We must keep $_POST and $_GET here
 									if (isset($_POST['sall']) || isset($_POST['search_all']) || isset($_GET['sall']) || isset($_GET['search_all'])) {
 										// We made a search from quick search menu, do we still use default filter ?
@@ -1390,7 +1390,7 @@ function dol_string_unaccent($str)
 
 	if (utf8_check($str)) {
 		if (extension_loaded('intl') && !empty($conf->global->MAIN_UNACCENT_USE_TRANSLITERATOR)) {
-			$transliterator = \Transliterator::createFromRules(':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: NFC;', \Transliterator::FORWARD);
+			$transliterator = Transliterator::createFromRules(':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: NFC;', Transliterator::FORWARD);
 			return $transliterator->transliterate($str);
 		}
 		// See http://www.utf8-chartable.de/

+ 1 - 1
htdocs/core/lib/images.lib.php

@@ -621,7 +621,7 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName = '_small',
 	}
 
 	// Before PHP8, img was a resource, With PHP8, it is a GdImage
-	if (!is_resource($img) && !($img instanceof \GdImage)) {
+	if (!is_resource($img) && !($img instanceof GdImage)) {
 		dol_syslog('Failed to detect type of image. We found infoImg[2]='.$infoImg[2], LOG_WARNING);
 		return 0;
 	}

+ 1 - 1
htdocs/core/lib/pdf.lib.php

@@ -241,7 +241,7 @@ function pdf_getEncryption($pathoffile)
 	$content = file_get_contents($pathoffile);
 
 	//ob_start();
-	@($parser = new \TCPDF_PARSER(ltrim($content)));
+	@($parser = new TCPDF_PARSER(ltrim($content)));
 	list($xref, $data) = $parser->getParsedData();
 	unset($parser);
 	//ob_end_clean();

+ 1 - 1
htdocs/core/modules/import/import_csv.modules.php

@@ -51,7 +51,7 @@ class ImportCsv extends ModeleImports
 	public $errors = array();
 
 	/**
-	 * @var int ID
+	 * @var string Code of driver
 	 */
 	public $id;
 

+ 1 - 1
htdocs/core/modules/import/import_xlsx.modules.php

@@ -55,7 +55,7 @@ class ImportXlsx extends ModeleImports
 	public $errors = array();
 
 	/**
-	 * @var int ID
+	 * @var string Code of driver
 	 */
 	public $id;
 

+ 2 - 2
htdocs/core/modules/import/modules_import.php

@@ -43,7 +43,7 @@ class ModeleImports
 	public $error = '';
 
 	/**
-	 * @var int id of driver
+	 * @var string Code of driver
 	 */
 	public $id;
 
@@ -129,7 +129,7 @@ class ModeleImports
 	/**
 	 * getDriverId
 	 *
-	 * @return string		Id
+	 * @return int		Id
 	 */
 	public function getDriverId()
 	{

+ 1 - 1
htdocs/debugbar/class/DataCollector/DolConfigCollector.php

@@ -21,7 +21,7 @@
  *	\ingroup    debugbar
  */
 
-use \DebugBar\DataCollector\ConfigCollector;
+use DebugBar\DataCollector\ConfigCollector;
 
 /**
  * DolConfigCollector class

+ 1 - 1
htdocs/debugbar/class/DataCollector/DolExceptionsCollector.php

@@ -21,7 +21,7 @@
  *	\ingroup    debugbar
  */
 
-use \DebugBar\DataCollector\ExceptionsCollector;
+use DebugBar\DataCollector\ExceptionsCollector;
 
 /**
  * DolExceptionsCollector class

+ 1 - 1
htdocs/debugbar/class/DataCollector/DolMemoryCollector.php

@@ -21,7 +21,7 @@
  *	\ingroup    debugbar
  */
 
-use \DebugBar\DataCollector\MemoryCollector;
+use DebugBar\DataCollector\MemoryCollector;
 
 /**
  * DolMemoryCollector class

+ 1 - 1
htdocs/debugbar/class/DataCollector/DolMessagesCollector.php

@@ -21,7 +21,7 @@
  *	\ingroup    debugbar
  */
 
-use \DebugBar\DataCollector\MessagesCollector;
+use DebugBar\DataCollector\MessagesCollector;
 
 /**
  * DolMessagesCollector class

+ 1 - 1
htdocs/debugbar/class/DataCollector/DolRequestDataCollector.php

@@ -21,7 +21,7 @@
  *	\ingroup    debugbar
  */
 
-use \DebugBar\DataCollector\RequestDataCollector;
+use DebugBar\DataCollector\RequestDataCollector;
 
 /**
  * DolRequestDataCollector class

+ 1 - 1
htdocs/debugbar/class/DataCollector/DolTimeDataCollector.php

@@ -21,7 +21,7 @@
  *	\ingroup    debugbar
  */
 
-use \DebugBar\DataCollector\TimeDataCollector;
+use DebugBar\DataCollector\TimeDataCollector;
 
 /**
  * DolTimeDataCollector class

+ 1 - 1
htdocs/debugbar/class/DebugBar.php

@@ -23,7 +23,7 @@
 
 dol_include_once('/debugbar/class/autoloader.php');
 
-use \DebugBar\DebugBar;
+use DebugBar\DebugBar;
 
 dol_include_once('/debugbar/class/DataCollector/DolMessagesCollector.php');
 dol_include_once('/debugbar/class/DataCollector/DolRequestDataCollector.php');

+ 5 - 0
htdocs/don/class/don.class.php

@@ -74,6 +74,11 @@ class Don extends CommonObject
 	 */
 	public $amount;
 
+	/**
+	 * @var integer Thirdparty ID
+	 */
+	public $socid;
+
 	/**
 	 * @var string Thirdparty name
 	 */

+ 1 - 1
htdocs/expensereport/card.php

@@ -2337,7 +2337,7 @@ if ($action == 'create') {
 
 						if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) {
 							print '<td class="fk_c_exp_tax_cat">';
-							$params = array('fk_expense' => $object->id, 'fk_expense_det' => $line->id, 'date' => $line->dates);
+							$params = array('fk_expense' => $object->id, 'fk_expense_det' => $line->id, 'date' => $line->date);
 							print $form->selectExpenseCategories($line->fk_c_exp_tax_cat, 'fk_c_exp_tax_cat', 1, array(), 'fk_c_type_fees', $userauthor->default_c_exp_tax_cat, $params);
 							print '</td>';
 						}

+ 11 - 0
htdocs/exports/class/export.class.php

@@ -35,7 +35,18 @@ class Export
 	 */
 	public $db;
 
+	/**
+	 * @var string Last error message
+	 */
 	public $error;
+	/**
+	 * @var string Last error code
+	 */
+	public $errno;
+	/**
+	 * @var string Error messages
+	 */
+	public $errors;
 
 	public $array_export_code = array(); // Tableau de "idmodule_numexportprofile"
 	public $array_export_code_for_sort = array(); // Tableau de "idmodule_numexportprofile"

+ 15 - 10
htdocs/imports/class/import.class.php

@@ -29,6 +29,21 @@
  */
 class Import
 {
+	/**
+	 * @var DoliDB Database handler.
+	 */
+	public $db;
+
+	/**
+	 * @var string Error code (or message)
+	 */
+	public $error = '';
+
+	/**
+	 * @var string[] Error codes (or messages)
+	 */
+	public $errors = array();
+
 	public $array_import_module;
 	public $array_import_perms;
 	public $array_import_icon;
@@ -45,16 +60,6 @@ class Import
 	public $array_import_convertvalue;
 	public $array_import_run_sql_after;
 
-	/**
-	 * @var string Error code (or message)
-	 */
-	public $error = '';
-
-	/**
-	 * @var string[] Error codes (or messages)
-	 */
-	public $errors = array();
-
 	// To store import templates
 	public $id;
 	public $hexa; // List of fields in the export profile

+ 2 - 2
htdocs/modulebuilder/index.php

@@ -2864,11 +2864,11 @@ if (!empty($module) && $module != 'initmodule' && $module != 'deletemodule') {
 		dol_include_once($fullpathdirtodescriptor);
 
 		$class = 'mod'.$module;
-	} catch (Throwable $e) {		// This is called in PHP 7 only. Never called with PHP 5.6
+	} catch (Throwable $e) {		// This is called in PHP 7 only (includes Error and Exception). Never called with PHP 5.6-.
 		$loadclasserrormessage = $e->getMessage()."<br>\n";
 		$loadclasserrormessage .= 'File: '.$e->getFile()."<br>\n";
 		$loadclasserrormessage .= 'Line: '.$e->getLine()."<br>\n";
-	} catch (Exception $e) {
+	} catch (Exception $e) {		// This is called in PHP 5.6- because not already trapped by previous case in PHP 5.6-.
 		$loadclasserrormessage = $e->getMessage()."<br>\n";
 		$loadclasserrormessage .= 'File: '.$e->getFile()."<br>\n";
 		$loadclasserrormessage .= 'Line: '.$e->getLine()."<br>\n";

+ 2 - 2
htdocs/public/stripe/ipn.php

@@ -122,10 +122,10 @@ $error = 0;
 
 try {
 	$event = \Stripe\Webhook::constructEvent($payload, $sig_header, $endpoint_secret);
-} catch (\UnexpectedValueException $e) {
+} catch (UnexpectedValueException $e) {
 	// Invalid payload
 	httponly_accessforbidden('Invalid payload', 400);
-} catch (\Stripe\Error\SignatureVerification $e) {
+} catch (\Stripe\Exception\SignatureVerificationException $e) {
 	httponly_accessforbidden('Invalid signature', 400);
 } catch (Exception $e) {
 	httponly_accessforbidden('Error '.$e->getMessage(), 400);

+ 5 - 6
htdocs/societe/class/api_thirdparties.class.php

@@ -622,8 +622,7 @@ class Thirdparties extends DolibarrApi
 	 * @param string	$sortorder	Sort order
 	 * @param int		$limit		Limit for list
 	 * @param int		$page		Page number
-	 *
-	 * @return mixed
+	 * @return array|void
 	 *
 	 * @url GET {id}/categories
 	 */
@@ -640,17 +639,17 @@ class Thirdparties extends DolibarrApi
 
 		$categories = new Categorie($this->db);
 
-		$result = $categories->getListForItem($id, 'customer', $sortfield, $sortorder, $limit, $page);
+		$arrayofcateg = $categories->getListForItem($id, 'customer', $sortfield, $sortorder, $limit, $page);
 
-		if (is_numeric($result) && $result < 0) {
+		if (is_numeric($arrayofcateg) && $arrayofcateg < 0) {
 			throw new RestException(503, 'Error when retrieve category list : '.$categories->error);
 		}
 
-		if (is_numeric($result) && $result == 0) {	// To fix a return of 0 instead of empty array of method getListForItem
+		if (is_numeric($arrayofcateg) && $arrayofcateg == 0) {	// To fix a return of 0 instead of empty array of method getListForItem
 			return array();
 		}
 
-		return $result;
+		return $arrayofcateg;
 	}
 
 	/**

+ 3 - 3
htdocs/takepos/index.php

@@ -245,18 +245,18 @@ function PrintCategories(first) {
 
 function MoreCategories(moreorless) {
 	console.log("MoreCategories moreorless="+moreorless+" pagecategories="+pagecategories);
-	if (moreorless=="more") {
+	if (moreorless == "more") {
 		$('#catimg15').animate({opacity: '0.5'}, 1);
 		$('#catimg15').animate({opacity: '1'}, 100);
 		pagecategories=pagecategories+1;
 	}
-	if (moreorless=="less") {
+	if (moreorless == "less") {
 		$('#catimg14').animate({opacity: '0.5'}, 1);
 		$('#catimg14').animate({opacity: '1'}, 100);
 		if (pagecategories==0) return; //Return if no less pages
 		pagecategories=pagecategories-1;
 	}
-	if (typeof (categories[<?php echo ($MAXCATEG - 2); ?> * pagecategories] && moreorless=="more") == "undefined"){ // Return if no more pages
+	if (typeof (categories[<?php echo ($MAXCATEG - 2); ?> * pagecategories] && moreorless == "more") == "undefined") { // Return if no more pages
 		pagecategories=pagecategories-1;
 		return;
 	}

+ 11 - 1
qodana.yaml

@@ -16,6 +16,7 @@ exclude:
       - htdocs/includes
       - htdocs/install/doctemplates
       - htdocs/modulebuilder/template/test/phpunit/functionnal
+      - htdocs/theme/common/fontawesome-5
   - name: PhpIssetCanBeReplacedWithCoalesceInspection
   - name: PhpRedundantOptionalArgumentInspection
   - name: PhpLanguageLevelInspection
@@ -83,4 +84,13 @@ exclude:
   - name: PhpNestedDirNameCallsCanBeReplacedWithLevelParameterInspection
   - name: PhpPointlessBooleanExpressionInConditionInspection  
   - name: PhpUndefinedMethodInspection
-  - name: PhpDuplicateCatchBodyInspection
+  - name: PhpDuplicateCatchBodyInspection
+  - name: PhpDefineCanBeReplacedWithConstInspection
+  - name: PhpMissingParamTypeInspection
+  - name: PhpMissingReturnTypeInspection
+  - name: CommaExpressionJS
+  - name: JSTypeOfValues
+  - name: PhpRedundantVariableDocTypeInspection
+  - name: PhpUnhandledExceptionInspection
+  - name: JSIgnoredPromiseFromCall
+