diff --git a/dev/tools/phan/baseline.txt b/dev/tools/phan/baseline.txt index 1b4d4db6254..5af4266911b 100644 --- a/dev/tools/phan/baseline.txt +++ b/dev/tools/phan/baseline.txt @@ -9,9 +9,9 @@ */ return [ // # Issue statistics: - // PhanPluginUnknownPropertyType : 2250+ occurrences - // PhanTypePossiblyInvalidDimOffset : 1550+ occurrences - // PhanTypeMismatchArgumentProbablyReal : 1450+ occurrences + // PhanPluginUnknownPropertyType : 2240+ occurrences + // PhanTypePossiblyInvalidDimOffset : 1540+ occurrences + // PhanTypeMismatchArgumentProbablyReal : 1440+ occurrences // PhanPossiblyUndeclaredGlobalVariable : 1400+ occurrences // PhanPluginUnknownObjectMethodCall : 1040+ occurrences // PhanUndeclaredProperty : 840+ occurrences @@ -41,7 +41,6 @@ return [ // PhanRedefinedClassReference : 20+ occurrences // PhanTypeComparisonFromArray : 15+ occurrences // PhanTypeExpectedObjectPropAccessButGotNull : 15+ occurrences - // PhanTypeMismatchDimFetchNullable : 15+ occurrences // PhanUndeclaredConstant : 15+ occurrences // PhanPluginBothLiteralsBinaryOp : 10+ occurrences // PhanPluginConstantVariableBool : 10+ occurrences @@ -49,14 +48,15 @@ return [ // PhanPluginDuplicateExpressionBinaryOp : 10+ occurrences // PhanPluginSuspiciousParamPosition : 10+ occurrences // PhanRedefineClass : 10+ occurrences + // PhanTypeMismatchDimFetchNullable : 10+ occurrences // PhanEmptyFQSENInClasslike : 5 occurrences // PhanInvalidFQSENInClasslike : 4 occurrences // PhanParamTooMany : 4 occurrences // PhanTypeConversionFromArray : 3 occurrences - // PhanNoopStringLiteral : 2 occurrences // PhanTypeComparisonToArray : 2 occurrences // PhanAccessMethodProtected : 1 occurrence // PhanAccessPropertyStaticAsNonStatic : 1 occurrence + // PhanNoopStringLiteral : 1 occurrence // PhanPluginWhitespaceTrailing : 1 occurrence // PhanTypeArraySuspiciousNull : 1 occurrence // PhanTypeMismatchReturn : 1 occurrence @@ -517,7 +517,7 @@ return [ 'htdocs/core/class/commonhookactions.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayPropertyType'], 'htdocs/core/class/commonincoterm.class.php' => ['PhanPluginUnknownObjectMethodCall', 'PhanUndeclaredProperty'], 'htdocs/core/class/commoninvoice.class.php' => ['PhanPluginDuplicateExpressionAssignmentOperation', 'PhanPluginUnknownArrayMethodReturnType', 'PhanPluginUnknownPropertyType', 'PhanPossiblyUndeclaredVariable', 'PhanTypeArraySuspiciousNullable', 'PhanTypePossiblyInvalidDimOffset'], - 'htdocs/core/class/commonobject.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanPluginUnknownArrayPropertyType', 'PhanPluginUnknownObjectMethodCall', 'PhanPluginUnknownPropertyType', 'PhanPossiblyUndeclaredVariable', 'PhanTypeArraySuspiciousNullable', 'PhanTypeMismatchArgumentNullableInternal', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchDimFetch', 'PhanTypeMismatchDimFetchNullable', 'PhanTypeMismatchProperty', 'PhanTypePossiblyInvalidDimOffset', 'PhanUndeclaredProperty'], + 'htdocs/core/class/commonobject.class.php' => ['PhanPluginUnknownObjectMethodCall', 'PhanTypeMismatchDimFetch', 'PhanTypeMismatchProperty', 'PhanTypePossiblyInvalidDimOffset', 'PhanUndeclaredProperty'], 'htdocs/core/class/commonobjectline.class.php' => ['PhanPluginUnknownPropertyType'], 'htdocs/core/class/commonorder.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownPropertyType'], 'htdocs/core/class/commonpeople.class.php' => ['PhanPluginUnknownPropertyType', 'PhanUndeclaredMethod', 'PhanUndeclaredProperty'], @@ -543,6 +543,7 @@ return [ 'htdocs/core/class/fiscalyear.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanPossiblyUndeclaredVariable'], 'htdocs/core/class/google.class.php' => ['PhanPluginUnknownPropertyType'], 'htdocs/core/class/hookmanager.class.php' => ['PhanTypeInvalidDimOffset', 'PhanUndeclaredProperty'], + 'htdocs/core/class/html.form.class.php' => ['PhanTypeArraySuspiciousNullable'], 'htdocs/core/class/html.formaccounting.class.php' => ['PhanPluginDuplicateExpressionAssignmentOperation', 'PhanPossiblyUndeclaredVariable'], 'htdocs/core/class/html.formadmin.class.php' => ['PhanPluginUnknownArrayMethodParamType'], 'htdocs/core/class/html.formbarcode.class.php' => ['PhanPluginUnknownArrayMethodParamType'], @@ -1362,7 +1363,6 @@ return [ 'htdocs/takepos/ajax/ajax.php' => ['PhanTypeMismatchArgumentProbablyReal', 'PhanTypeObjectUnsetDeclaredProperty', 'PhanUndeclaredProperty'], 'htdocs/takepos/floors.php' => ['PhanTypeMismatchArgumentProbablyReal'], 'htdocs/takepos/freezone.php' => ['PhanTypeMismatchArgumentProbablyReal'], - 'htdocs/takepos/genimg/index.php' => ['PhanTypeMismatchArgumentProbablyReal'], 'htdocs/takepos/index.php' => ['PhanTypeInvalidDimOffset', 'PhanTypePossiblyInvalidDimOffset'], 'htdocs/takepos/invoice.php' => ['PhanPluginDuplicateExpressionAssignmentOperation', 'PhanPluginEmptyStatementIf', 'PhanPluginSuspiciousParamPosition', 'PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeArraySuspiciousNullable', 'PhanTypeInvalidLeftOperandOfNumericOp', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypePossiblyInvalidDimOffset', 'PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'], 'htdocs/takepos/pay.php' => ['PhanPluginDuplicateExpressionAssignmentOperation', 'PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeArraySuspiciousNullable', 'PhanTypeMismatchArgumentProbablyReal'], diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 44525a51004..782209aac0f 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -89,7 +89,7 @@ abstract class CommonObject public $errors = array(); /** - * @var array To store error results of ->validateField() + * @var array To store error results of ->validateField() */ private $validateFieldsErrors = array(); @@ -133,7 +133,7 @@ abstract class CommonObject public $import_key; /** - * @var mixed Contains data to manage extrafields + * @var array Contains data to manage extrafields */ public $array_options = array(); @@ -144,12 +144,13 @@ abstract class CommonObject public $fields = array(); /** - * @var mixed Array to store alternative languages values of object + * @var array> Array to store alternative languages values of object + * Note: call fetchValuesForExtraLanguages() before using this */ public $array_languages = null; // Value is array() when load already tried /** - * @var array To store result of ->liste_contact() + * @var array To store result of ->liste_contact() */ public $contacts_ids; @@ -202,8 +203,13 @@ abstract class CommonObject */ public $context = array(); - // Properties set and used by Agenda trigger + /** + * @var string Properties set and used by Agenda trigger + */ public $actionmsg; + /** + * @var string Properties set and used by Agenda trigger + */ public $actionmsg2; /** @@ -384,7 +390,7 @@ abstract class CommonObject public $state_id; /** - * var int State ID + * @var int State ID * @deprecated Use $state_id. We can remove this property when the field 'fk_departement' have been renamed into 'state_id' in all tables */ public $fk_departement; @@ -745,10 +751,13 @@ abstract class CommonObject public $fk_user_modif; + /** + * @var string XX + */ public $next_prev_filter; /** - * @var int 1 if object is specimen + * @var int<0,1> 1 if object is specimen */ public $specimen = 0; @@ -770,17 +779,17 @@ abstract class CommonObject public $totalpaid; /** - * @var array Array with labels of status + * @var array Array with labels of status */ public $labelStatus = array(); /** - * @var array Array with short labels of status + * @var array Array with short labels of status */ public $labelStatusShort = array(); /** - * @var array Array to store lists of tpl + * @var array Array to store lists of tpl */ public $tpl; @@ -791,7 +800,7 @@ abstract class CommonObject public $showphoto_on_popup; /** - * @var array nb used in load_stateboard + * @var array{actionscomm?:int,banklines?:int,cheques?:int,contacts?:int,contracts?:int,customers?:int,dolresource?:int,donations?:int,expensereports?:int,holidays?:int,interventions?:int,invoices?:int,members?:int,orders?:int,products?:int,projects?:int,proposals?:int,prospects?:int,services?:int,supplier_invoices?:int,supplier_orders?:int,supplier_proposals?:int,suppliers?:int,tasks?:int,ticket?:int,users?:int} nb used in load_stateboard */ public $nb = array(); @@ -850,6 +859,12 @@ abstract class CommonObject */ public $warehouse_id; + /** + * @var int<0,1> Does object support extrafields ? 0=No, 1=Yes + */ + public $isextrafieldmanaged = 0; + + // No constructor as it is an abstract class /** @@ -939,8 +954,8 @@ abstract class CommonObject * Return array of data to show into a tooltip. This method must be implemented in each object class. * * @since v18 - * @param array $params params to construct tooltip data - * @return array + * @param array $params params to construct tooltip data + * @return array Data to show in tooltip */ public function getTooltipContentArray($params) { @@ -950,7 +965,7 @@ abstract class CommonObject /** * getTooltipContent * - * @param array $params params + * @param array $params params * @since v18 * @return string */ @@ -1077,9 +1092,9 @@ abstract class CommonObject /** * Return full address of contact * - * @param int $withcountry 1=Add country into address string + * @param int<0,1> $withcountry 1=Add country into address string * @param string $sep Separator to use to build string - * @param int $withregion 1=Add region into address string + * @param int<0,1> $withregion 1=Add region into address string * @param string $extralangcode User extralanguages as value * @return string Full address string */ @@ -1094,14 +1109,14 @@ abstract class CommonObject if ($withregion && $this->state_id && (empty($this->state_code) || empty($this->state) || empty($this->region) || empty($this->region_code))) { require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; - $tmparray = getState($this->state_id, 'all', 0, 1); + $tmparray = getState($this->state_id, 'all', null, 1); $this->state_code = $tmparray['code']; $this->state = $tmparray['label']; $this->region_code = $tmparray['region_code']; $this->region = $tmparray['region']; } - return dol_format_address($this, $withcountry, $sep, '', 0, $extralangcode); + return dol_format_address($this, $withcountry, $sep, null, 0, $extralangcode); } @@ -1312,7 +1327,7 @@ abstract class CommonObject * Copy contact from one element to current * * @param CommonObject $objFrom Source element - * @param string $source Nature of contact ('internal' or 'external') + * @param 'internal'|'external' $source Nature of contact ('internal' or 'external') * @return int >0 if OK, <0 if KO */ public function copy_linked_contact($objFrom, $source = 'internal') @@ -1455,12 +1470,12 @@ abstract class CommonObject * Get array of all contacts for an object * * @param int $statusoflink Status of links to get (-1=all). Not used. - * @param string $source Source of contact: 'external' or 'thirdparty' (llx_socpeople) or 'internal' (llx_user) - * @param int $list 0:Returned array contains all properties, 1:Return array contains just id + * @param 'external'|'thirdparty'|'internal' $source Source of contact: 'external' or 'thirdparty' (llx_socpeople) or 'internal' (llx_user) + * @param int<0,1> $list 0:Returned array contains all properties, 1:Return array contains just id * @param string $code Filter on this code of contact type ('SHIPPING', 'BILLING', ...) * @param int $status Status of user or company - * @param array $arrayoftcids Array with ID of type of contacts. If we provide this, we can make a ec.fk_c_type_contact in ($arrayoftcids) to avoid link on tc table. TODO Not implemented. - * @return array|int Array of contacts, -1 if error + * @param int[] $arrayoftcids Array with ID of type of contacts. If we provide this, we can make a ec.fk_c_type_contact in ($arrayoftcids) to avoid link on tc table. TODO Not implemented. + * @return array|int<-1,-1> Array of contacts, -1 if error */ public function liste_contact($statusoflink = -1, $source = 'external', $list = 0, $code = '', $status = -1, $arrayoftcids = array()) { @@ -1590,12 +1605,12 @@ abstract class CommonObject /** * Return array with list of possible values for type of contacts * - * @param string $source 'internal', 'external' or 'all' + * @param 'internal'|'external'|'all' $source 'internal', 'external' or 'all' * @param string $order Sort order by : 'position', 'code', 'rowid'... - * @param int $option 0=Return array id->label, 1=Return array code->label - * @param int $activeonly 0=all status of contact, 1=only the active + * @param int<0,1> $option 0=Return array id->label, 1=Return array code->label + * @param int<0,1> $activeonly 0=all status of contact, 1=only the active * @param string $code Type of contact (Example: 'CUSTOMER', 'SERVICE') - * @return array|null Array list of type of contacts (id->label if option=0, code->label if option=1), or null if error + * @return array|array|null Array list of type of contacts (id->label if option=0, code->label if option=1), or null if error */ public function liste_type_contact($source = 'internal', $order = 'position', $option = 0, $activeonly = 0, $code = '') { @@ -1653,12 +1668,12 @@ abstract class CommonObject * Return array with list of possible values for type of contacts * * @param string $source 'internal', 'external' or 'all' - * @param int $option 0=Return array id->label, 1=Return array code->label - * @param int $activeonly 0=all status of contact, 1=only the active + * @param int<0,1> $option 0=Return array id->label, 1=Return array code->label + * @param int<0,1> $activeonly 0=all status of contact, 1=only the active * @param string $code Type of contact (Example: 'CUSTOMER', 'SERVICE') * @param string $element Filter on 1 element type * @param string $excludeelement Exclude 1 element type. Example: 'agenda' - * @return array|null Array list of type of contacts (id->label if option=0, code->label if option=1), or null if error + * @return array|array|null Array list of type of contacts (id->label if option=0, code->label if option=1), or null if error */ public function listeTypeContacts($source = 'internal', $option = 0, $activeonly = 0, $code = '', $element = '', $excludeelement = '') { @@ -1740,7 +1755,7 @@ abstract class CommonObject * @param string $source 'external' or 'internal' * @param string $code 'BILLING', 'SHIPPING', 'SALESREPFOLL', ... * @param int $status limited to a certain status - * @return array|null List of id for such contacts, or null if error + * @return int[]|null List of id for such contacts, or null if error */ public function getIdContact($source, $code, $status = 0) { @@ -1807,8 +1822,8 @@ abstract class CommonObject /** * Load object contact with id=$this->contact_id into $this->contact * - * @param int $contactid Id du contact. Use this->contact_id if empty. - * @return int Return integer <0 if KO, >0 if OK + * @param ?int $contactid Id du contact. Use this->contact_id if empty. + * @return int<-1,1> Return integer <0 if KO, >0 if OK */ public function fetch_contact($contactid = null) { @@ -1832,8 +1847,9 @@ abstract class CommonObject /** * Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty * - * @param int $force_thirdparty_id Force thirdparty id - * @return int Return integer <0 if KO, >0 if OK + * @param int<0,1> $force_thirdparty_id Force thirdparty id + * @return int<-1,1> Return integer <0 if KO, >0 if OK + * @phan-suppress PhanUndeclaredProperty */ public function fetch_thirdparty($force_thirdparty_id = 0) { @@ -1874,7 +1890,7 @@ abstract class CommonObject * It does only work when $this->table_ref_field is set * * @param string $ref Wildcard - * @return int >1 = OK, 0 = Not found or table_ref_field not defined, <0 = KO + * @return int<-1,1> >1 = OK, 0 = Not found or table_ref_field not defined, <0 = KO */ public function fetchOneLike($ref) { @@ -1910,7 +1926,7 @@ abstract class CommonObject * Properties ->barcode_type that is id of barcode. Type is used to find other properties, but * if it is not defined, ->element must be defined to know default barcode type. * - * @return int Return integer <0 if KO, 0 if can't guess type of barcode (ISBN, EAN13...), >0 if OK (all barcode properties loaded) + * @return int<-1,1> Return integer <0 if KO, 0 if can't guess type of barcode (ISBN, EAN13...), >0 if OK (all barcode properties loaded) */ public function fetch_barcode() { @@ -1957,7 +1973,7 @@ abstract class CommonObject /** * Load the project with id $this->fk_project into this->project * - * @return int Return integer <0 if KO, >=0 if OK + * @return int<-1,1> Return integer <0 if KO, >=0 if OK */ public function fetch_project() { @@ -1995,18 +2011,20 @@ abstract class CommonObject /** * Load the product with id $this->fk_product into this->product * - * @return int Return integer <0 if KO, >=0 if OK + * @return int<-1,1> Return integer <0 if KO, >=0 if OK */ public function fetch_product() { // phpcs:enable include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; + // @phan-suppress-next-line PhanUndeclaredProperty if (empty($this->fk_product)) { return 0; } $product = new Product($this->db); + // @phan-suppress-next-line PhanUndeclaredProperty $result = $product->fetch($this->fk_product); $this->product = $product; @@ -2018,7 +2036,7 @@ abstract class CommonObject * Load the user with id $userid into this->user * * @param int $userid Id du contact - * @return int Return integer <0 if KO, >0 if OK + * @return int<-1,1> Return integer <0 if KO, >0 if OK */ public function fetch_user($userid) { @@ -2054,6 +2072,7 @@ abstract class CommonObject $classname = ucfirst($origin); $this->origin_object = new $classname($this->db); + // @phan-suppress-next-line PhanPluginUnknownObjectMethodCall $this->origin_object->fetch($this->origin_id); } @@ -2064,7 +2083,7 @@ abstract class CommonObject * @param string $field Field selected * @param string $key Import key * @param string $element Element name - * @return int|false Return -1 or false if KO, >0 if OK + * @return int<-1,1>|false Return -1 or false if KO, >0 if OK */ public function fetchObjectFrom($table, $field, $key, $element = null) { @@ -2106,7 +2125,7 @@ abstract class CommonObject * @param string $table Table of element or element line * @param int $id Element id * @param string $field Field selected - * @return int Return integer <0 if KO, >0 if OK + * @return int<-1,1> Return integer <0 if KO, >0 if OK */ public function getValueFrom($table, $id, $field) { @@ -2138,7 +2157,7 @@ abstract class CommonObject * @param User|string $fuser Update the user of last update field with this user. If not provided, current user is used except if value is 'none' * @param string $trigkey Trigger key to run (in most cases something like 'XXX_MODIFY') * @param string $fk_user_field Name of field to save user id making change - * @return int Return integer <0 if KO, >0 if OK + * @return int<-1,1> Return integer <0 if KO, >0 if OK * @see updateExtraField() */ public function setValueFrom($field, $value, $table = '', $id = null, $format = '', $id_field = '', $fuser = null, $trigkey = '', $fk_user_field = 'fk_user_modif') @@ -2170,9 +2189,8 @@ abstract class CommonObject $fk_user_field = ''; } + $oldvalue = null; if ($trigkey) { - $oldvalue = null; - $sql = "SELECT " . $field; $sql .= " FROM " . MAIN_DB_PREFIX . $table; $sql .= " WHERE " . $id_field . " = " . ((int) $id); @@ -2271,8 +2289,8 @@ abstract class CommonObject * Example: "(t.field1 = 'aa' OR t.field2 = 'bb')". Do not allow user input data here with this syntax. * Example: "((t.field1:=:'aa') OR (t.field2:=:'bb'))". * @param string $fieldid Name of field to use for the select MAX and MIN - * @param int $nodbprefix Do not include DB prefix to forge table name - * @return int Return integer <0 if KO, >0 if OK + * @param int<0,1> $nodbprefix Do not include DB prefix to forge table name + * @return int<-1,1> Return integer <0 if KO, >0 if OK */ public function load_previous_next_ref($filter, $fieldid, $nodbprefix = 0) { @@ -2479,7 +2497,7 @@ abstract class CommonObject * Return list of id of contacts of object * * @param string $source Source of contact: external (llx_socpeople) or internal (llx_user) or thirdparty (llx_societe) - * @return array Array of id of contacts (if source=external or internal) + * @return int[] Array of id of contacts (if source=external or internal) * Array of id of third parties with at least one contact on object (if source=thirdparty) */ public function getListContactId($source = 'external') @@ -2503,9 +2521,9 @@ abstract class CommonObject /** * Link element with a project * - * @param int $projectid Project id to link element to - * @param int $notrigger Disable the trigger - * @return int Return integer <0 if KO, >0 if OK + * @param int $projectid Project id to link element to + * @param int<0,1> $notrigger Disable the trigger + * @return int<-1,1> Return integer <0 if KO, >0 if OK */ public function setProject($projectid, $notrigger = 0) { @@ -3327,9 +3345,9 @@ abstract class CommonObject /** * Get children of line * - * @param int $id Id of parent line - * @param int $includealltree 0 = 1st level child, 1 = All level child - * @return array Array with list of children lines id + * @param int $id Id of parent line + * @param int<0,1> $includealltree 0 = 1st level child, 1 = All level child + * @return int[] Array with list of children lines id */ public function getChildrenOfLine($id, $includealltree = 0) { @@ -3408,7 +3426,7 @@ abstract class CommonObject * * @param int $rowid Id of line * @param int $rang Position - * @return int Return integer <0 if KO, >0 if OK + * @return int<-1,1> Return integer <0 if KO, >0 if OK */ public function updateRangOfLine($rowid, $rang) { @@ -3437,7 +3455,7 @@ abstract class CommonObject /** * Update position of line with ajax (rang) * - * @param array $rows Array of rows + * @param int[] $rows Array of rows * @return void */ public function line_ajaxorder($rows) @@ -3746,10 +3764,10 @@ abstract class CommonObject * Must be called at end of methods addline or updateline. * * @param int $exclspec >0 = Exclude special product (product_type=9) - * @param string $roundingadjust 'none'=Do nothing, 'auto'=Use default method (MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND if defined, or '0'), '0'=Force mode Total of rounding, '1'=Force mode Rounding of total - * @param int $nodatabaseupdate 1=Do not update database total fields of the main object. Update only properties in memory. Can be used to save SQL when this method is called several times, so we can do it only once at end. - * @param Societe $seller If roundingadjust is '0' or '1' or maybe 'auto', it means we recalculate total for lines before calculating total for object and for this, we need seller object (used to analyze lines to check corrupted data). - * @return int Return integer <0 if KO, >0 if OK + * @param 'none'|'auto'|'0'|'1' $roundingadjust 'none'=Do nothing, 'auto'=Use default method (MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND if defined, or '0'), '0'=Force mode Total of rounding, '1'=Force mode Rounding of total + * @param int<0,1> $nodatabaseupdate 1=Do not update database total fields of the main object. Update only properties in memory. Can be used to save SQL when this method is called several times, so we can do it only once at end. + * @param ?Societe $seller If roundingadjust is '0' or '1' or maybe 'auto', it means we recalculate total for lines before calculating total for object and for this, we need seller object (used to analyze lines to check corrupted data). + * @return int<-1,1> Return integer <0 if KO, >0 if OK */ public function update_price($exclspec = 0, $roundingadjust = 'auto', $nodatabaseupdate = 0, $seller = null) { @@ -3784,7 +3802,7 @@ abstract class CommonObject $isElementForSupplier = true; $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL"; } - if ($isElementForSupplier === true) { + if ($isElementForSupplier) { $roundTotalConstName = 'MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND_SUPPLIER'; // const for supplier } @@ -4929,7 +4947,7 @@ abstract class CommonObject * Return into unit=0, the calculated total of weight and volume of all lines * qty * Calculate by adding weight and volume of each product line, so properties ->volume/volume_units/weight/weight_units must be loaded on line. * - * @return array array('weight'=>...,'volume'=>...) + * @return array{weight:int|float,volume:int|float,ordered:int|float,toship:int|float} array('weight'=>...,'volume'=>...) */ public function getTotalWeightVolume() { @@ -5332,8 +5350,8 @@ abstract class CommonObject * If lines are into a template, title must also be into a template * But for the moment we don't know if it's possible, so we keep the method available on overloaded objects. * - * @param string $restrictlist ''=All lines, 'services'=Restrict to services only - * @param array $selectedLines Array of lines id for selected lines + * @param ''|'services' $restrictlist ''=All lines, 'services'=Restrict to services only + * @param int[] $selectedLines Array of lines id for selected lines * @return void */ public function printOriginLinesList($restrictlist = '', $selectedLines = array()) @@ -5388,7 +5406,7 @@ abstract class CommonObject * @param string $var Not used * @param string $restrictlist ''=All lines, 'services'=Restrict to services only (strike line if not) * @param string $defaulttpldir Directory where to find the template - * @param array $selectedLines Array of lines id for selected lines + * @param int[] $selectedLines Array of lines id for selected lines * @return void */ public function printOriginLine($line, $var, $restrictlist = '', $defaulttpldir = '/core/tpl', $selectedLines = array()) @@ -5629,14 +5647,14 @@ abstract class CommonObject /** * Common function for all objects extending CommonObject for generating documents * - * @param string $modelspath Relative folder where generators are placed - * @param string $modele Generator to use. Caller must set it to from obj->model_pdf or from GETPOST for example. - * @param Translate $outputlangs Output language to use - * @param int $hidedetails 1 to hide details. 0 by default - * @param int $hidedesc 1 to hide product description. 0 by default - * @param int $hideref 1 to hide product reference. 0 by default - * @param null|array $moreparams Array to provide more information - * @return int >0 if OK, <0 if KO + * @param string $modelspath Relative folder where generators are placed + * @param string $modele Generator to use. Caller must set it to from obj->model_pdf or from GETPOST for example. + * @param Translate $outputlangs Output language to use + * @param int<0,1> $hidedetails 1 to hide details. 0 by default + * @param int<0,1> $hidedesc 1 to hide product description. 0 by default + * @param int<0,1> $hideref 1 to hide product reference. 0 by default + * @param ?array $moreparams Array to provide more information + * @return int<-1,1> >0 if OK, <0 if KO * @see addFileIntoDatabaseIndex() */ protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams = null) @@ -5778,6 +5796,7 @@ abstract class CommonObject $this->model_pdf = $saved_model; if (in_array(get_class($this), array('Adherent'))) { + '@phan-var-force Adherent $this'; $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, 'member', 1, 'tmp_cards', $moreparams); } else { $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $moreparams); @@ -6094,7 +6113,7 @@ abstract class CommonObject * Function to get alternative languages of a data into $this->array_languages * This method is NOT called by method fetch of objects but must be called separately. * - * @return int Return integer <0 if error, 0 if no values of alternative languages to find nor found, 1 if a value was found and loaded + * @return int<-1,1> Return integer <0 if error, 0 if no values of alternative languages to find nor found, 1 if a value was found and loaded * @see fetch_optionnals() */ public function fetchValuesForExtraLanguages() @@ -6164,7 +6183,7 @@ abstract class CommonObject * Fill array_options property of object by extrafields value (using for data sent by forms) * * @param string $onlykey Only the following key is filled. When we make update of only one language field ($action = 'update_languages'), calling page must set this to avoid to have other languages being reset. - * @return int 1 if array_options set, 0 if no value, -1 if error (field required missing for example) + * @return int<-1,1> 1 if array_options set, 0 if no value, -1 if error (field required missing for example) */ public function setValuesForExtraLanguages($onlykey = '') { @@ -6247,7 +6266,7 @@ abstract class CommonObject * Function to make a fetch but set environment to avoid to load computed values before. * * @param int $id ID of object - * @return int >0 if OK, 0 if not found, <0 if KO + * @return int<-1,1> >0 if OK, 0 if not found, <0 if KO */ public function fetchNoCompute($id) { @@ -6269,8 +6288,8 @@ abstract class CommonObject * This method is in most cases called by method fetch of objects but you can call it separately. * * @param int $rowid Id of line. Use the id of object if not defined. Deprecated. Function must be called without parameters. - * @param array $optionsArray Array resulting of call of extrafields->fetch_name_optionals_label(). Deprecated. Function must be called without parameters. - * @return int Return integer <0 if error, 0 if no values of extrafield to find nor found, 1 if an attribute is found and value loaded + * @param array{}|array{label:array,type:array,size:array,default:array,computed:array,unique:array,required:array,param:array,perms:array,list:array|array,pos:array,totalizable:array,help:array,printable:array,enabled:array,langfile:array,css:array,csslist:array,hidden:array,mandatoryfieldsofotherentities?:array,loaded?:int,count:int} $optionsArray Array resulting of call of extrafields->fetch_name_optionals_label(). Deprecated. Function must be called without parameters. + * @return int<-1,1> Return integer <0 if error, 0 if no values of extrafield to find nor found, 1 if an attribute is found and value loaded * @see fetchValuesForExtraLanguages() */ public function fetch_optionals($rowid = null, $optionsArray = null) @@ -6399,7 +6418,7 @@ abstract class CommonObject /** * Delete all extra fields values for the current object. * - * @return int Return integer <0 if KO, >0 if OK + * @return int<-1,1> Return integer <0 if KO, >0 if OK * @see deleteExtraLanguages(), insertExtraField(), updateExtraField(), setValueFrom() */ public function deleteExtraFields() @@ -6439,7 +6458,7 @@ abstract class CommonObject * * @param string $trigger If defined, call also the trigger (for example COMPANY_MODIFY) * @param User $userused Object user - * @return int -1=error, O=did nothing, 1=OK + * @return int<-1,1> -1=error, O=did nothing, 1=OK * @see insertExtraLanguages(), updateExtraField(), deleteExtraField(), setValueFrom() */ public function insertExtraFields($trigger = '', $userused = null) @@ -6765,7 +6784,7 @@ abstract class CommonObject * * @param string $trigger If defined, call also the trigger (for example COMPANY_MODIFY) * @param User $userused Object user - * @return int -1=error, O=did nothing, 1=OK + * @return int<-1,1> -1=error, O=did nothing, 1=OK * @see insertExtraFields(), updateExtraField(), setValueFrom() */ public function insertExtraLanguages($trigger = '', $userused = null) @@ -6795,7 +6814,7 @@ abstract class CommonObject switch ($attributeType) { case 'int': - if (!is_numeric($value) && $value != '') { + if (is_array($value) || (!is_numeric($value) && $value != '')) { $this->errors[] = $langs->trans("ExtraLanguageHasWrongValue", $attributeLabel); return -1; } elseif ($value == '') { @@ -6883,7 +6902,7 @@ abstract class CommonObject * @param string $key Key of the extrafield to update (without starting 'options_') * @param string $trigger If defined, call also the trigger (for example COMPANY_MODIFY) * @param User $userused Object user - * @return int -1=error, O=did nothing, 1=OK + * @return int<-1,1> -1=error, O=did nothing, 1=OK * @see updateExtraLanguages(), insertExtraFields(), deleteExtraFields(), setValueFrom() */ public function updateExtraField($key, $trigger = null, $userused = null) @@ -7204,9 +7223,10 @@ abstract class CommonObject * Return HTML string to put an input field into a page * Code very similar with showInputField of extra fields * - * @param array|null $val Array of properties for field to show (used only if ->fields not defined) + * @param ?array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string} $val Array of properties for field to show (used only if ->fields not defined) + * Array of properties of field to show * @param string $key Key of attribute - * @param string|array $value Preselected value to show (for date type it must be in timestamp format, for amount or price it must be a php numeric value, for array type must be array) + * @param string|string[] $value Preselected value to show (for date type it must be in timestamp format, for amount or price it must be a php numeric value, for array type must be array) * @param string $moreparam To add more parameters on html input tag * @param string $keysuffix Prefix string to add into name and id of field (can be used to avoid duplicate names) * @param string $keyprefix Suffix string to add into name and id of field (can be used to avoid duplicate names) @@ -7243,6 +7263,7 @@ abstract class CommonObject $param = array(); $param['options'] = array(); $reg = array(); + // @phan-suppress-next-line PhanTypeArraySuspiciousNullable $size = !empty($this->fields[$key]['size']) ? $this->fields[$key]['size'] : 0; // Because we work on extrafields if (preg_match('/^(integer|link):(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) { @@ -7287,13 +7308,20 @@ abstract class CommonObject $label = $this->fields[$key]['label']; //$elementtype=$this->fields[$key]['elementtype']; // Seems not used + // @phan-suppress-next-line PhanTypeArraySuspiciousNullable $default = (!empty($this->fields[$key]['default']) ? $this->fields[$key]['default'] : ''); + // @phan-suppress-next-line PhanTypeArraySuspiciousNullable $computed = (!empty($this->fields[$key]['computed']) ? $this->fields[$key]['computed'] : ''); + // @phan-suppress-next-line PhanTypeArraySuspiciousNullable $unique = (!empty($this->fields[$key]['unique']) ? $this->fields[$key]['unique'] : 0); + // @phan-suppress-next-line PhanTypeArraySuspiciousNullable $required = (!empty($this->fields[$key]['required']) ? $this->fields[$key]['required'] : 0); + // @phan-suppress-next-line PhanTypeArraySuspiciousNullable $autofocusoncreate = (!empty($this->fields[$key]['autofocusoncreate']) ? $this->fields[$key]['autofocusoncreate'] : 0); + // @phan-suppress-next-line PhanTypeArraySuspiciousNullable $langfile = (!empty($this->fields[$key]['langfile']) ? $this->fields[$key]['langfile'] : ''); + // @phan-suppress-next-line PhanTypeArraySuspiciousNullable $list = (!empty($this->fields[$key]['list']) ? $this->fields[$key]['list'] : 0); $hidden = (in_array(abs($this->fields[$key]['visible']), array(0, 2)) ? 1 : 0); @@ -7315,7 +7343,7 @@ abstract class CommonObject $morecss = 'minwidth100imp'; } elseif ($type == 'datetime' || $type == 'link') { // link means an foreign key to another primary id $morecss = 'minwidth200imp'; - } elseif (in_array($type, array('int', 'integer', 'price')) || preg_match('/^double(\([0-9],[0-9]\)){0,1}/', $type)) { + } elseif (in_array($type, array('int', 'integer', 'price')) || preg_match('/^double(\([0-9],[0-9]\)){0,1}/', (string) $type)) { $morecss = 'maxwidth75'; } elseif ($type == 'url') { $morecss = 'minwidth400'; @@ -7369,11 +7397,11 @@ abstract class CommonObject $out = ' 0 ? ' maxlength="'.$newsize.'"' : '').' value="'.dol_escape_htmltag($value).'"'.($moreparam ? $moreparam : '').($autofocusoncreate ? ' autofocus' : '').'>'; } elseif (in_array($type, array('real'))) { $out = ''; - } elseif (preg_match('/varchar/', $type)) { + } elseif (preg_match('/varchar/', (string) $type)) { $out = ' 0 ? ' maxlength="'.$size.'"' : '').' value="'.dol_escape_htmltag($value).'"'.($moreparam ? $moreparam : '').($autofocusoncreate ? ' autofocus' : '').'>'; } elseif (in_array($type, array('email', 'mail', 'phone', 'url', 'ip'))) { $out = ''; - } elseif (preg_match('/^text/', $type)) { + } elseif (preg_match('/^text/', (string) $type)) { if (!preg_match('/search_/', $keyprefix)) { // If keyprefix is search_ or search_options_, we must just use a simple text field require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $doleditor = new DolEditor($keyprefix.$key.$keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, false, ROWS_5, '90%'); @@ -7381,7 +7409,7 @@ abstract class CommonObject } else { $out = ''; } - } elseif (preg_match('/^html/', $type)) { + } elseif (preg_match('/^html/', (string) $type)) { if (!preg_match('/search_/', $keyprefix)) { // If keyprefix is search_ or search_options_, we must just use a simple text field require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $doleditor = new DolEditor($keyprefix.$key.$keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, isModEnabled('fckeditor') && $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_5, '90%'); @@ -7402,7 +7430,7 @@ abstract class CommonObject $value = price($value); } $out = ' '.$langs->getCurrencySymbol($conf->currency); - } elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/', $type)) { + } elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/', (string) $type)) { if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. $value = price($value); } @@ -7503,7 +7531,7 @@ abstract class CommonObject } } - if ($filter_categorie === false) { + if (!$filter_categorie) { $fields_label = explode('|', $InfoFieldList[1]); if (is_array($fields_label)) { $keyList .= ', '; @@ -7632,7 +7660,7 @@ abstract class CommonObject $out .= ''; } elseif ($type == 'checkbox') { $value_arr = explode(',', $value); - $out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options']) ? null : $param['options']), $value_arr, '', 0, $morecss, 0, '100%'); + $out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options']) ? null : $param['options']), $value_arr, 0, 0, $morecss, 0, '100%'); } elseif ($type == 'radio') { $out = ''; // @phan-suppress-current-line PhanPluginRedundantAssignment foreach ($param['options'] as $keyopt => $valopt) { @@ -7661,6 +7689,8 @@ abstract class CommonObject // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value // 5 : id category type // 6 : ids categories list separated by comma for category root + '@phan-var-force array{0:string,1:string,2:string,3:string,3:string,5:string,6:string} $InfoFieldList'; + $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2].' as rowid'); if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) { @@ -7682,7 +7712,7 @@ abstract class CommonObject } } - if ($filter_categorie === false) { + if (!$filter_categorie) { $fields_label = explode('|', $InfoFieldList[1]); if (is_array($fields_label)) { $keyList .= ', '; @@ -7788,14 +7818,14 @@ abstract class CommonObject } $this->db->free($resql); - $out = $form->multiselectarray($keyprefix . $key . $keysuffix, $data, $value_arr, '', 0, $morecss, 0, '100%'); + $out = $form->multiselectarray($keyprefix . $key . $keysuffix, $data, $value_arr, 0, 0, $morecss, 0, '100%'); } else { print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.
'; } } else { require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; $data = $form->select_all_categories(Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]], '', 'parent', 64, $InfoFieldList[6], 1, 1); - $out = $form->multiselectarray($keyprefix . $key . $keysuffix, $data, $value_arr, '', 0, $morecss, 0, '100%'); + $out = $form->multiselectarray($keyprefix . $key . $keysuffix, $data, $value_arr, 0, 0, $morecss, 0, '100%'); } } } elseif ($type == 'link') { @@ -7904,7 +7934,7 @@ abstract class CommonObject * Return HTML string to show a field into a page * Code very similar with showOutputField of extra fields * - * @param array $val Array of properties of field to show + * @param array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string} $val Array of properties of field to show * @param string $key Key of attribute * @param string $value Preselected value to show (for date type it must be in timestamp format, for amount or price it must be a php numeric value) * @param string $moreparam To add more parameters on html tag @@ -7926,6 +7956,7 @@ abstract class CommonObject $type = empty($val['type']) ? '' : $val['type']; $size = empty($val['css']) ? '' : $val['css']; $reg = array(); + $value = ''; // Default return value // Convert var to be able to share same code than showOutputField of extrafields if (preg_match('/varchar\((\d+)\)/', $type, $reg)) { @@ -8062,7 +8093,7 @@ abstract class CommonObject $value = price($value, 0, $langs, 0, 0, -1, $conf->currency); } } elseif ($type == 'select') { - $value = isset($param['options'][$value]) ? $param['options'][$value] : ''; + $value = isset($param['options'][(string) $value]) ? $param['options'][(string) $value] : ''; if (strpos($value, "|") !== false) { $value = $langs->trans(explode('|', $value)[0]); } elseif (! is_numeric($value)) { @@ -8111,7 +8142,7 @@ abstract class CommonObject dol_syslog(get_class($this).':showOutputField:$type=sellist', LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { - if ($filter_categorie === false) { + if (!$filter_categorie) { $value = ''; // value was used, so now we reste it to use it to build final output $numrows = $this->db->num_rows($resql); if ($numrows) { @@ -8161,9 +8192,9 @@ abstract class CommonObject dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); } } elseif ($type == 'radio') { - $value = $param['options'][$value]; + $value = $param['options'][(string) $value]; } elseif ($type == 'checkbox') { - $value_arr = explode(',', $value); + $value_arr = explode(',', (string) $value); $value = ''; if (is_array($value_arr) && count($value_arr) > 0) { $toprint = array(); @@ -8214,8 +8245,8 @@ abstract class CommonObject dol_syslog(get_class($this).':showOutputField:$type=chkbxlst', LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { - if ($filter_categorie === false) { - $value = ''; // value was used, so now we reste it to use it to build final output + if (!$filter_categorie) { + $value = ''; // value was used, so now we reset it to use it to build final output $toprint = array(); while ($obj = $this->db->fetch_object($resql)) { // Several field into label (eq table:code|libelle:rowid) @@ -8399,7 +8430,7 @@ abstract class CommonObject /** * Return validation test result for a field * - * @param array $fields Array of properties of field to show + * @param array|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string}> $fields Array of properties of field to show * @param string $fieldKey Key of attribute * @param string $fieldValue value of attribute * @return bool return false if fail true on success, see $this->error for error message @@ -8414,13 +8445,11 @@ abstract class CommonObject $this->clearFieldError($fieldKey); - if (!isset($fields[$fieldKey])) { + if (!isset($fields[$fieldKey]) || $fields[$fieldKey] === null) { $this->setFieldError($fieldKey, $langs->trans('FieldNotFoundInObject')); return false; } - $val = $fields[$fieldKey]; - $param = array(); $param['options'] = array(); $type = $val['type']; @@ -8607,7 +8636,7 @@ abstract class CommonObject * * @param Extrafields $extrafields Extrafield Object * @param string $mode Show output ('view') or input ('create' or 'edit') for extrafield - * @param array $params Optional parameters. Example: array('style'=>'class="oddeven"', 'colspan'=>$colspan) + * @param array $params Optional parameters. Example: array('style'=>'class="oddeven"', 'colspan'=>$colspan) * @param string $keysuffix Suffix string to add after name and id of field (can be used to avoid duplicate names) * @param string $keyprefix Prefix string to add before name and id of field (can be used to avoid duplicate names) * @param string $onetrtd All fields in same tr td. Used by objectline_create.tpl.php for example. @@ -8651,7 +8680,7 @@ abstract class CommonObject foreach ($extrafields->attributes[$this->table_element]['label'] as $key => $label) { $i++; - // Show only the key field in params + // Show only the key field in params @phan-suppress-next-line PhanTypeArraySuspiciousNullable if (is_array($params) && array_key_exists('onlykey', $params) && $key != $params['onlykey']) { continue; } @@ -8692,6 +8721,7 @@ abstract class CommonObject } $colspan = 0; + $value = null; if (is_array($params) && count($params) > 0 && $display_type == 'card') { if (array_key_exists('cols', $params)) { $colspan = $params['cols']; @@ -9018,12 +9048,12 @@ abstract class CommonObject * This function is meant to be called from replaceThirdparty with the appropriate tables * Column name fk_soc MUST exist. * - * @param DoliDB $dbs Database handler - * @param int $origin_id Old thirdparty id (the thirdparty to delete) - * @param int $dest_id New thirdparty id (the thirdparty that will received element of the other) - * @param string[] $tables Tables that need to be changed - * @param int $ignoreerrors Ignore errors. Return true even if errors. We need this when replacement can fails like for categories (categorie of old thirdparty may already exists on new one) - * @return bool True if success, False if error + * @param DoliDB $dbs Database handler + * @param int $origin_id Old thirdparty id (the thirdparty to delete) + * @param int $dest_id New thirdparty id (the thirdparty that will received element of the other) + * @param string[] $tables Tables that need to be changed + * @param int<0,1> $ignoreerrors Ignore errors. Return true even if errors. We need this when replacement can fails like for categories (categorie of old thirdparty may already exists on new one) + * @return bool True if success, False if error */ public static function commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors = 0) { @@ -9047,12 +9077,12 @@ abstract class CommonObject * This function is meant to be called from replaceProduct with the appropriate tables * Column name fk_product MUST be used to identify products * - * @param DoliDB $dbs Database handler - * @param int $origin_id Old product id (the product to delete) - * @param int $dest_id New product id (the product that will received element of the other) - * @param string[] $tables Tables that need to be changed - * @param int $ignoreerrors Ignore errors. Return true even if errors. We need this when replacement can fails like for categories (categorie of old product may already exists on new one) - * @return bool True if success, False if error + * @param DoliDB $dbs Database handler + * @param int $origin_id Old product id (the product to delete) + * @param int $dest_id New product id (the product that will received element of the other) + * @param string[] $tables Tables that need to be changed + * @param int<0,1> $ignoreerrors Ignore errors. Return true even if errors. We need this when replacement can fails like for categories (categorie of old product may already exists on new one) + * @return bool True if success, False if error */ public static function commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors = 0) { @@ -9078,10 +9108,10 @@ abstract class CommonObject * elseif calculation MARGIN_TYPE = 'pmp' and pmp is calculated, use pmp as buyprice * else set min buy price as buy price * - * @param float $unitPrice Product unit price - * @param float $discountPercent Line discount percent - * @param int $fk_product Product id - * @return float|int Return buy price if OK, integer <0 if KO + * @param float $unitPrice Product unit price + * @param float $discountPercent Line discount percent + * @param int $fk_product Product id + * @return float|int<-1,-1> Return buy price if OK, integer <0 if KO */ public function defineBuyPrice($unitPrice = 0.0, $discountPercent = 0.0, $fk_product = 0) { @@ -9095,6 +9125,7 @@ abstract class CommonObject } else { // Get cost price for margin calculation if (!empty($fk_product) && $fk_product > 0) { + $result = 0; if (getDolGlobalString('MARGIN_TYPE') == 'costprice') { require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; $product = new Product($this->db); @@ -9141,7 +9172,7 @@ abstract class CommonObject * * @param string $modulepart Module part * @param string $imagesize Image size - * @return array Array of data to show photo + * @return array{dir:string,file:string,originalfile:string,altfile:string,email:string,capture:string} Array of data to show photo */ public function getDataToShowPhoto($modulepart, $imagesize) { @@ -9317,7 +9348,7 @@ abstract class CommonObject $cache = $val['label']; } if ($usesharelink) { - if ($val['share']) { + if (array_key_exists('share', $val) && $val['share']) { if (empty($maxHeight) || ($photo_vignette && $imgarray['height'] > $maxHeight)) { $return .= ''; $return .= ''; @@ -9424,7 +9455,7 @@ abstract class CommonObject /** * Function test if type is array * - * @param array $info content information of field + * @param array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string} $info content information of field * @return bool true if array */ protected function isArray($info) @@ -9442,7 +9473,7 @@ abstract class CommonObject /** * Function test if type is date * - * @param array $info content information of field + * @param array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string} $info content information of field * @return bool true if date */ public function isDate($info) @@ -9456,7 +9487,7 @@ abstract class CommonObject /** * Function test if type is duration * - * @param array $info content information of field + * @param array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string} $info content information of field * @return bool true if field of type duration */ public function isDuration($info) @@ -9475,7 +9506,7 @@ abstract class CommonObject /** * Function test if type is integer * - * @param array $info content information of field + * @param array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string} $info Properties of field * @return bool true if integer */ public function isInt($info) @@ -9494,7 +9525,7 @@ abstract class CommonObject /** * Function test if type is float * - * @param array $info content information of field + * @param array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string} $info content information of field * @return bool true if float */ public function isFloat($info) @@ -9512,7 +9543,7 @@ abstract class CommonObject /** * Function test if type is text * - * @param array $info content information of field + * @param array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string} $info Properties of field * @return bool true if type text */ public function isText($info) @@ -9530,13 +9561,13 @@ abstract class CommonObject /** * Function test if field can be null * - * @param array $info content information of field + * @param array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string} $info content information of field * @return bool true if it can be null */ protected function canBeNull($info) { if (is_array($info)) { - if (isset($info['notnull']) && $info['notnull'] != '1') { + if (array_key_exists('notnull', $info) && $info['notnull'] != '1') { return true; } else { return false; @@ -9548,13 +9579,13 @@ abstract class CommonObject /** * Function test if field is forced to null if zero or empty * - * @param array $info content information of field + * @param array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string} $info content information of field * @return bool true if forced to null */ protected function isForcedToNullIfZero($info) { if (is_array($info)) { - if (isset($info['notnull']) && $info['notnull'] == '-1') { + if (array_key_exists('notnull', $info) && $info['notnull'] == '-1') { return true; } else { return false; @@ -9566,13 +9597,13 @@ abstract class CommonObject /** * Function test if is indexed * - * @param array $info content information of field + * @param array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string} $info content information of field * @return bool */ protected function isIndex($info) { if (is_array($info)) { - if (isset($info['index']) && $info['index'] == true) { + if (array_key_exists('index', $info) && $info['index'] == true) { return true; } else { return false; @@ -9588,7 +9619,7 @@ abstract class CommonObject * Note: $this->${field} are set by the page that make the createCommon() or the updateCommon(). * $this->${field} should be a clean and string value (so date are formatted for SQL insert). * - * @return array Array with all values of each properties to update + * @return array Array with all values of each property to update */ protected function setSaveQuery() { @@ -9641,7 +9672,7 @@ abstract class CommonObject $queryarray[$field] = $this->{$field}; } - if ($info['type'] == 'timestamp' && empty($queryarray[$field])) { + if (array_key_exists('type', $info) && $info['type'] == 'timestamp' && empty($queryarray[$field])) { unset($queryarray[$field]); } if (!empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) { @@ -9680,7 +9711,7 @@ abstract class CommonObject $this->$field = (float) $obj->$field; } } else { - if (isset($obj->$field) && (!is_null($obj->$field) || (isset($info['notnull']) && $info['notnull'] == 1))) { + if (isset($obj->$field) && (!is_null($obj->$field) || (array_key_exists('notnull', $info) && $info['notnull'] == 1))) { $this->$field = (int) $obj->$field; } else { $this->$field = null; @@ -9695,7 +9726,7 @@ abstract class CommonObject $this->$field = (float) $obj->$field; } } else { - if (isset($obj->$field) && (!is_null($obj->$field) || (isset($info['notnull']) && $info['notnull'] == 1))) { + if (isset($obj->$field) && (!is_null($obj->$field) || (array_key_exists('notnull', $info) && $info['notnull'] == 1))) { $this->$field = (float) $obj->$field; } else { $this->$field = null; @@ -9726,9 +9757,9 @@ abstract class CommonObject /** * Function to concat keys of fields * - * @param string $alias String of alias of table for fields. For example 't'. It is recommended to use '' and set alias into fields definition. - * @param array $excludefields Array of fields to exclude - * @return string List of alias fields + * @param string $alias String of alias of table for fields. For example 't'. It is recommended to use '' and set alias into fields definition. + * @param string[] $excludefields Array of fields to exclude + * @return string List of alias fields */ public function getFieldList($alias = '', $excludefields = array()) { @@ -9753,7 +9784,7 @@ abstract class CommonObject * Add quote to field value if necessary * * @param string|int $value Value to protect - * @param array $fieldsentry Properties of field + * @param array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string} $fieldsentry Properties of field * @return string|int */ protected function quote($value, $fieldsentry) @@ -9761,7 +9792,7 @@ abstract class CommonObject if (is_null($value)) { return 'NULL'; } elseif (preg_match('/^(int|double|real|price)/i', $fieldsentry['type'])) { - return price2num("$value"); + return price2num((string) $value); } elseif (preg_match('/int$/i', $fieldsentry['type'])) { return (int) $value; } elseif ($fieldsentry['type'] == 'boolean') { @@ -9777,11 +9808,11 @@ abstract class CommonObject /** - * Create object into database + * Create object in the database * - * @param User $user User that creates - * @param int $notrigger 0=launch triggers after, 1=disable triggers - * @return int Return integer <0 if KO, Id of created object if OK + * @param User $user User that creates + * @param int<0,1> $notrigger 0=launch triggers after, 1=disable triggers + * @return int<-1,-1> Return integer <0 if KO, Id of created object if OK */ public function createCommon(User $user, $notrigger = 0) { @@ -9809,6 +9840,7 @@ abstract class CommonObject $this->user_creation_id = $user->id; } if (array_key_exists('pass_crypted', $fieldvalues) && property_exists($this, 'pass')) { + // @phan-suppress-next-line PhanUndeclaredProperty $fieldvalues['pass_crypted'] = dol_hash($this->pass); } if (array_key_exists('ref', $fieldvalues)) { @@ -9828,35 +9860,40 @@ abstract class CommonObject // Clean and check mandatory foreach ($keys as $key) { + if (!isset($this->fields[$key])) { + continue; + } + $key_fields = $this->fields[$key]; + // If field is an implicit foreign key field (so type = 'integer:...') - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') { + if (preg_match('/^integer:/i', $key_fields['type']) && $values[$key] == '-1') { $values[$key] = ''; } - if (!empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') { + if (!empty($key_fields['foreignkey']) && $values[$key] == '-1') { $values[$key] = ''; } - if (isset($this->fields[$key]['notnull']) && $this->fields[$key]['notnull'] == 1 && (!isset($values[$key]) || $values[$key] === 'NULL') && is_null($this->fields[$key]['default'])) { + if (isset($key_fields['notnull']) && $key_fields['notnull'] == 1 && (!isset($values[$key]) || $values[$key] === 'NULL') && (!isset($key_fields['default']) || is_null($key_fields['default']))) { $error++; $langs->load("errors"); dol_syslog("Mandatory field '".$key."' is empty and required into ->fields definition of class"); - $this->errors[] = $langs->trans("ErrorFieldRequired", $this->fields[$key]['label']); + $this->errors[] = $langs->trans("ErrorFieldRequired", isset($key_fields['label']) ? $key_fields['label'] : $key); } - // If value is null and there is a default value for field - if (isset($this->fields[$key]['notnull']) && $this->fields[$key]['notnull'] == 1 && (!isset($values[$key]) || $values[$key] === 'NULL') && !is_null($this->fields[$key]['default'])) { - $values[$key] = $this->quote($this->fields[$key]['default'], $this->fields[$key]); + // If value is null and there is a default value for field @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset + if (isset($key_fields['notnull']) && $key_fields['notnull'] == 1 && (!isset($values[$key]) || $values[$key] === 'NULL') && !is_null($key_fields['default'])) { + $values[$key] = $this->quote($key_fields['default'], $key_fields); } // If field is an implicit foreign key field (so type = 'integer:...') - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && empty($values[$key])) { - if (isset($this->fields[$key]['default'])) { - $values[$key] = ((int) $this->fields[$key]['default']); + if (isset($key_fields['type']) && preg_match('/^integer:/i', $key_fields['type']) && empty($values[$key])) { + if (isset($key_fields['default'])) { + $values[$key] = ((int) $key_fields['default']); } else { $values[$key] = 'null'; } } - if (!empty($this->fields[$key]['foreignkey']) && empty($values[$key])) { + if (!empty($key_fields['foreignkey']) && empty($values[$key])) { $values[$key] = 'null'; } } @@ -9889,6 +9926,7 @@ abstract class CommonObject // If we have a field ref with a default value of (PROV) if (!$error) { + // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset if (array_key_exists('ref', $this->fields) && array_key_exists('notnull', $this->fields['ref']) && $this->fields['ref']['notnull'] > 0 && array_key_exists('default', $this->fields['ref']) && $this->fields['ref']['default'] == '(PROV)') { $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET ref = '(PROV".((int) $this->id).")' WHERE (ref = '(PROV)' OR ref = '') AND rowid = ".((int) $this->id); $resqlupdate = $this->db->query($sql); @@ -9960,11 +9998,11 @@ abstract class CommonObject /** * Load object in memory from the database. This does not load line. This is done by parent fetch() that call fetchCommon * - * @param int $id Id object - * @param string $ref Ref - * @param string $morewhere More SQL filters (' AND ...') - * @param int $noextrafields 0=Default to load extrafields, 1=No extrafields - * @return int Return integer <0 if KO, 0 if not found, >0 if OK + * @param int $id Id object + * @param string $ref Ref + * @param string $morewhere More SQL filters (' AND ...') + * @param int<0,1> $noextrafields 0=Default to load extrafields, 1=No extrafields + * @return int<-1,1> Return integer <0 if KO, 0 if not found, >0 if OK */ public function fetchCommon($id, $ref = null, $morewhere = '', $noextrafields = 0) { @@ -10026,9 +10064,9 @@ abstract class CommonObject /** * Load object in memory from the database * - * @param string $morewhere More SQL filters (' AND ...') - * @param int $noextrafields 0=Default to load extrafields, 1=No extrafields - * @return int Return integer <0 if KO, 0 if not found, >0 if OK + * @param string $morewhere More SQL filters (' AND ...') + * @param int<0,1> $noextrafields 0=Default to load extrafields, 1=No extrafields + * @return int<-1,1> Return integer <0 if KO, 0 if not found, >0 if OK */ public function fetchLinesCommon($morewhere = '', $noextrafields = 0) { @@ -10039,6 +10077,7 @@ abstract class CommonObject } $objectline = new $objectlineclassname($this->db); + '@phan-var-force CommonObjectLine $objectline'; $sql = "SELECT ".$objectline->getFieldList('l'); $sql .= " FROM ".$this->db->prefix().$objectline->table_element." as l"; @@ -10058,6 +10097,7 @@ abstract class CommonObject $obj = $this->db->fetch_object($resql); if ($obj) { $newline = new $objectlineclassname($this->db); + '@phan-var-force CommonObjectLine $newline'; $newline->setVarsFromFetchObj($obj); // Note: extrafields load of line not yet supported @@ -10082,9 +10122,9 @@ abstract class CommonObject /** * Update object into database * - * @param User $user User that modifies - * @param int $notrigger 0=launch triggers after, 1=disable triggers - * @return int Return integer <0 if KO, >0 if OK + * @param User $user User that modifies + * @param int<0,1> $notrigger 0=launch triggers after, 1=disable triggers + * @return int<-1,1> Return integer <0 if KO, >0 if OK */ public function updateCommon(User $user, $notrigger = 0) { @@ -10193,10 +10233,10 @@ abstract class CommonObject /** * Delete object in database * - * @param User $user User that deletes - * @param int $notrigger 0=launch triggers after, 1=disable triggers - * @param int $forcechilddeletion 0=no, 1=Force deletion of children - * @return int Return integer <0 if KO, 0=Nothing done because object has child, >0 if OK + * @param User $user User that deletes + * @param int<0,1> $notrigger 0=launch triggers after, 1=disable triggers + * @param int<0,1> $forcechilddeletion 0=no, 1=Force deletion of children + * @return int<-1,1> Return integer <0 if KO, 0=Nothing done because object has child, >0 if OK */ public function deleteCommon(User $user, $notrigger = 0, $forcechilddeletion = 0) { @@ -10243,6 +10283,7 @@ abstract class CommonObject if (dol_include_once($filePath)) { $childObject = new $className($this->db); if (method_exists($childObject, 'deleteByParentField')) { + '@phan-var-force CommonObject $childObject'; $result = $childObject->deleteByParentField($this->id, $columnName, $filter); if ($result < 0) { $error++; @@ -10432,6 +10473,7 @@ abstract class CommonObject if (empty($error)) { // Remove extrafields $tmpobjectline = new $tmpforobjectlineclass($this->db); + '@phan-var-force CommonObjectLine $tmpobjectline'; if (!isset($tmpobjectline->isextrafieldmanaged) || !empty($tmpobjectline->isextrafieldmanaged)) { $tmpobjectline->id = $idline; $result = $tmpobjectline->deleteExtraFields(); @@ -10836,6 +10878,7 @@ abstract class CommonObject default: $element = $this->element; } + '@phan-var-force string $element'; // Delete ecm_files_extrafields with mode 0 (using name) $sql = "DELETE FROM ".$this->db->prefix()."ecm_files_extrafields WHERE fk_object IN ("; diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 48c6340c708..ea711bacaa5 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -601,18 +601,18 @@ function getCountry($searchkey, $withcode = '', $dbtouse = null, $outputlangs = * Return state translated from an id. Return value is always utf8 encoded and without entities. * * @param int $id id of state (province/departement) - * @param string $withcode '0'=Return label, - * '1'=Return string code + label, - * '2'=Return code, - * 'all'=return array('id'=>,'code'=>,'label'=>) - * @param DoliDB $dbtouse Database handler (using in global way may fail because of conflicts with some autoload features) - * @param int $withregion '0'=Ignores region, + * @param '0'|'1'|'2'|'all' $withcode '0'=Return label, + * '1'=Return string code + label, + * '2'=Return code, + * 'all'=return array('id'=>,'code'=>,'label'=>) + * @param ?DoliDB $dbtouse Database handler (using in global way may fail because of conflicts with some autoload features) + * @param int<0,1> $withregion '0'=Ignores region, * '1'=Add region name/code/id as needed to output, * @param Translate $outputlangs Langs object for output translation, not fully implemented yet - * @param int $entconv 0=Return value without entities and not converted to output charset, 1=Ready for html output - * @return string|array String with state code or state name or Array('id','code','label')/Array('id','code','label','region_code','region') + * @param int<0,1> $entconv 0=Return value without entities and not converted to output charset, 1=Ready for html output + * @return string|array{id:int,code:string,label:string}|array{id:int,code:string,label:string,region_code:string,region:string} String with state code or state name or Array('id','code','label')/Array('id','code','label','region_code','region') */ -function getState($id, $withcode = '', $dbtouse = null, $withregion = 0, $outputlangs = null, $entconv = 1) +function getState($id, $withcode = '0', $dbtouse = null, $withregion = 0, $outputlangs = null, $entconv = 1) { global $db, $langs; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index e16a732bd6c..711024650db 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -2914,7 +2914,7 @@ function dol_bc($var, $moreclass = '') * @param Object $object A company or contact object * @param int $withcountry 1=Add country into address string * @param string $sep Separator to use to separate info when building string - * @param Translate $outputlangs Object lang that contains language for text translation. + * @param ?Translate $outputlangs Object lang that contains language for text translation. * @param int $mode 0=Standard output, 1=Remove address * @param string $extralangcode User extralanguage $langcode as values for address, town * @return string Formatted string diff --git a/htdocs/core/triggers/interface_95_modWebhook_WebhookTriggers.class.php b/htdocs/core/triggers/interface_95_modWebhook_WebhookTriggers.class.php index c78c99fc304..de8c742eea8 100644 --- a/htdocs/core/triggers/interface_95_modWebhook_WebhookTriggers.class.php +++ b/htdocs/core/triggers/interface_95_modWebhook_WebhookTriggers.class.php @@ -97,7 +97,7 @@ class InterfaceWebhookTriggers extends DolibarrTriggers $jsonstr = json_encode($resobject); - $response = getURLContent($tmpobject->url, 'POST', $jsonstr, 1, array(), array('http', 'https'), 0, -1); + $response = getURLContent($tmpobject->url, 'POST', $jsonstr, 1, array('content-type:application/json'), array('http', 'https'), 0, -1); if (empty($response['curl_error_no']) && $response['http_code'] >= 200 && $response['http_code'] < 300) { $nbPosts++; } else { diff --git a/htdocs/hrm/class/position.class.php b/htdocs/hrm/class/position.class.php index 74dc5bd65ec..e3ac01dd65d 100644 --- a/htdocs/hrm/class/position.class.php +++ b/htdocs/hrm/class/position.class.php @@ -843,7 +843,7 @@ class Position extends CommonObject * Return HTML string to put an input field into a page * Code very similar with showInputField of extra fields * - * @param array $val Array of properties for field to show + * @param ?array{type:string,label:string,enabled:int|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array,comment?:string} $val Array of properties for field to show * @param string $key Key of attribute * @param string $value Preselected value to show (for date type it must be in timestamp format, for amount or price it must be a php numeric value) * @param string $moreparam To add more parameters on html input tag