From df1f9bc0bcd6329f4dc4ce0db4f91330c80a3d6c Mon Sep 17 00:00:00 2001 From: thibdrev Date: Wed, 17 Jul 2024 15:46:14 +0200 Subject: [PATCH] qual: better phpdoc and use of isProduct(), isService() and isStockManaged() (#30405) Co-authored-by: Laurent Destailleur --- htdocs/product/class/product.class.php | 48 +++++++++++++------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 568bd5f47fc..0fa4bc719cc 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -1525,7 +1525,7 @@ class Product extends CommonObject $this->error = "Object must be fetched before calling delete"; return -1; } - if (($this->type == Product::TYPE_PRODUCT && !$user->hasRight('produit', 'supprimer')) || ($this->type == Product::TYPE_SERVICE && !$user->hasRight('service', 'supprimer'))) { + if (($this->isProduct() && !$user->hasRight('produit', 'supprimer')) || ($this->isService() && !$user->hasRight('service', 'supprimer'))) { $this->error = "ErrorForbidden"; return 0; } @@ -5335,9 +5335,9 @@ class Product extends CommonObject } } - if ($this->type == Product::TYPE_PRODUCT) { + if ($this->isProduct()) { $datas['picto'] = img_picto('', 'product').' '.$langs->trans("Product").''; - } elseif ($this->type == Product::TYPE_SERVICE) { + } elseif ($this->isService()) { $datas['picto'] = img_picto('', 'service').' '.$langs->trans("Service").''; } if (isset($this->status) && isset($this->status_buy)) { @@ -5353,7 +5353,7 @@ class Product extends CommonObject if (!empty($this->description)) { $datas['description'] = '
'.$langs->trans('ProductDescription').': '.dolGetFirstLineOfText($this->description, 5); } - if ($this->type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) { + if ($this->isStockManaged()) { if (isModEnabled('productbatch')) { $langs->load("productbatch"); $datas['batchstatus'] = "
".$langs->trans("ManageLotSerial").': '.$this->getLibStatut(0, 2); @@ -5363,7 +5363,7 @@ class Product extends CommonObject $datas['barcode'] = '
'.$langs->trans('BarCode').': '.$this->barcode; } - if ($this->type == Product::TYPE_PRODUCT) { + if ($this->isProduct()) { if ($this->weight) { $datas['weight'] = "
".$langs->trans("Weight").': '.$this->weight.' '.measuringUnitString(0, "weight", $this->weight_units); } @@ -5392,7 +5392,7 @@ class Product extends CommonObject $datas['surface'] = "
" . $labelsurfacevolume; } } - if ($this->type == Product::TYPE_SERVICE && !empty($this->duration_value)) { + if ($this->isService() && !empty($this->duration_value)) { // Duration $datas['duration'] = '
'.$langs->trans("Duration").': '.$this->duration_value; if ($this->duration_value > 1) { @@ -5518,10 +5518,10 @@ class Product extends CommonObject $result .= $linkstart; if ($withpicto) { - if ($this->type == Product::TYPE_PRODUCT) { + if ($this->isProduct()) { $result .= (img_object(($notooltip ? '' : $label), 'product', 'class="paddingright"', 0, 0, $notooltip ? 0 : 1)); } - if ($this->type == Product::TYPE_SERVICE) { + if ($this->isService()) { $result .= (img_object(($notooltip ? '' : $label), 'service', 'class="paddingright"', 0, 0, $notooltip ? 0 : 1)); } } @@ -6318,29 +6318,29 @@ class Product extends CommonObject } /** - * Return if object is a product. + * Return if the object is a product. * - * @return boolean True if it's a product + * @return boolean True if the object is a product, false otherwise. */ public function isProduct() { - return ($this->type == Product::TYPE_PRODUCT ? true : false); + return $this->type == Product::TYPE_PRODUCT; } /** - * Return if object is a product + * Return if the object is a service. * - * @return boolean True if it's a service + * @return boolean True if the object is a service, false otherwise. */ public function isService() { - return ($this->type == Product::TYPE_SERVICE ? true : false); + return $this->type == Product::TYPE_SERVICE; } /** - * Return if object need to have its stock managed + * Return if the object is managed in stock. * - * @return boolean True if it's a service + * @return boolean True if the object is managed in stock, false otherwise. */ public function isStockManaged() { @@ -6348,23 +6348,23 @@ class Product extends CommonObject } /** - * Return if object have a constraint on mandatory_period + * Return if the object has a constraint on mandatory_period * - * @return boolean True if mandatory_period set to 1 + * @return boolean True if mandatory_period is set to 1, false otherwise. */ public function isMandatoryPeriod() { - return ($this->mandatory_period == 1 ? true : false); + return $this->mandatory_period == 1; } /** - * Return if object has a sell-by date or eat-by date + * Return if the object has a sell-by or eat-by date. * - * @return boolean True if it's has + * @return boolean True if the object has a sell-by or eat-by date, false otherwise. */ public function hasbatch() { - return ($this->status_batch > 0 ? true : false); + return $this->status_batch > 0; } @@ -6726,9 +6726,9 @@ class Product extends CommonObject $label .= $this->show_photos('product', $conf->product->multidir_output[$this->entity], 1, 1, 0, 0, 0, 120, 160, 0, 0, 0, '', 'photoref photokanban'); $return .= $label; } else { - if ($this->type == Product::TYPE_PRODUCT) { + if ($this->isProduct()) { $label .= img_picto('', 'product'); - } elseif ($this->type == Product::TYPE_SERVICE) { + } elseif ($this->isService()) { $label .= img_picto('', 'service'); } $return .= $label;