Merge pull request #11174 from fappels/clean_10_beta

Clean code and fix phpcs
This commit is contained in:
Laurent Destailleur 2019-05-16 21:21:59 +02:00 committed by GitHub
commit d10d5554cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 115 additions and 119 deletions

View File

@ -499,7 +499,7 @@ class Commande extends CommonOrder
return -1; return -1;
} }
dol_syslog(get_class($this)."::set_draft", LOG_DEBUG); dol_syslog(__METHOD__, LOG_DEBUG);
$this->db->begin(); $this->db->begin();

View File

@ -2532,7 +2532,6 @@ class Facture extends CommonInvoice
return true; return true;
} }
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/** /**
* Set draft status * Set draft status
* *
@ -2540,7 +2539,7 @@ class Facture extends CommonInvoice
* @param int $idwarehouse Id warehouse to use for stock change. * @param int $idwarehouse Id warehouse to use for stock change.
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
public function setDraft($user, $idwarehouse = -1) public function setDraft($user, $idwarehouse = -1)
{ {
// phpcs:enable // phpcs:enable
global $conf,$langs; global $conf,$langs;
@ -2549,11 +2548,11 @@ class Facture extends CommonInvoice
if ($this->statut == self::STATUS_DRAFT) if ($this->statut == self::STATUS_DRAFT)
{ {
dol_syslog(get_class($this)."::set_draft already draft status", LOG_WARNING); dol_syslog(__METHOD__." already draft status", LOG_WARNING);
return 0; return 0;
} }
dol_syslog(get_class($this)."::set_draft", LOG_DEBUG); dol_syslog(__METHOD__, LOG_DEBUG);
$this->db->begin(); $this->db->begin();
@ -2564,10 +2563,10 @@ class Facture extends CommonInvoice
$result=$this->db->query($sql); $result=$this->db->query($sql);
if ($result) if ($result)
{ {
if (! $error) if (! $error)
{ {
$this->oldcopy= clone $this; $this->oldcopy= clone $this;
} }
// Si on decremente le produit principal et ses composants a la validation de facture, on réincrement // Si on decremente le produit principal et ses composants a la validation de facture, on réincrement
if ($this->type != self::TYPE_DEPOSIT && $result >= 0 && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_BILL)) if ($this->type != self::TYPE_DEPOSIT && $result >= 0 && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_BILL))
@ -2595,15 +2594,15 @@ class Facture extends CommonInvoice
$this->brouillon = 1; $this->brouillon = 1;
$this->statut = self::STATUS_DRAFT; $this->statut = self::STATUS_DRAFT;
// Call trigger // Call trigger
$result=$this->call_trigger('BILL_UNVALIDATE', $user); $result=$this->call_trigger('BILL_UNVALIDATE', $user);
if ($result < 0) if ($result < 0)
{ {
$error++; $error++;
$this->statut=$old_statut; $this->statut=$old_statut;
$this->brouillon=0; $this->brouillon=0;
} }
// End call triggers // End call triggers
} else { } else {
$this->db->rollback(); $this->db->rollback();
return -1; return -1;

View File

@ -709,8 +709,8 @@ while ($i < min($num, $limit))
$listsalesrepresentatives=$socstatic->getSalesRepresentatives($user); $listsalesrepresentatives=$socstatic->getSalesRepresentatives($user);
if ($listsalesrepresentatives < 0) dol_print_error($db); if ($listsalesrepresentatives < 0) dol_print_error($db);
$nbofsalesrepresentative=count($listsalesrepresentatives); $nbofsalesrepresentative=count($listsalesrepresentatives);
if ($nbofsalesrepresentative > 3) { if ($nbofsalesrepresentative > 3) {
// We print only number // We print only number
print '<a href="'.DOL_URL_ROOT.'/societe/commerciaux.php?socid='.$socstatic->id.'">'; print '<a href="'.DOL_URL_ROOT.'/societe/commerciaux.php?socid='.$socstatic->id.'">';
print $nbofsalesrepresentative; print $nbofsalesrepresentative;
print '</a>'; print '</a>';

View File

@ -1227,12 +1227,12 @@ abstract class CommonObject
$result=array(); $result=array();
$i=0; $i=0;
//cas particulier pour les expeditions //cas particulier pour les expeditions
if($this->element=='shipping' && $this->origin_id != 0) { if ($this->element=='shipping' && $this->origin_id != 0) {
$id=$this->origin_id; $id=$this->origin_id;
$element='commande'; $element='commande';
} elseif($this->element=='reception' && $this->origin_id != 0) { } elseif ($this->element=='reception' && $this->origin_id != 0) {
$id=$this->origin_id; $id=$this->origin_id;
$element='order_supplier'; $element='order_supplier';
} else { } else {
$id=$this->id; $id=$this->id;
$element=$this->element; $element=$this->element;
@ -2086,25 +2086,25 @@ abstract class CommonObject
* Change the shipping method * Change the shipping method
* *
* @param int $shipping_method_id Id of shipping method * @param int $shipping_method_id Id of shipping method
* @param bool $notrigger false=launch triggers after, true=disable triggers * @param bool $notrigger false=launch triggers after, true=disable triggers
* @param User $userused Object user * @param User $userused Object user
* *
* @return int 1 if OK, 0 if KO * @return int 1 if OK, 0 if KO
*/ */
public function setShippingMethod($shipping_method_id, $notrigger = false, $userused = null) public function setShippingMethod($shipping_method_id, $notrigger = false, $userused = null)
{ {
global $user; global $user;
if (empty($userused)) $userused=$user; if (empty($userused)) $userused=$user;
$error = 0; $error = 0;
if (! $this->table_element) { if (! $this->table_element) {
dol_syslog(get_class($this)."::setShippingMethod was called on objet with property table_element not defined", LOG_ERR); dol_syslog(get_class($this)."::setShippingMethod was called on objet with property table_element not defined", LOG_ERR);
return -1; return -1;
} }
$this->db->begin(); $this->db->begin();
if ($shipping_method_id<0) $shipping_method_id='NULL'; if ($shipping_method_id<0) $shipping_method_id='NULL';
dol_syslog(get_class($this).'::setShippingMethod('.$shipping_method_id.')'); dol_syslog(get_class($this).'::setShippingMethod('.$shipping_method_id.')');
@ -2112,30 +2112,30 @@ abstract class CommonObject
$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
$sql.= " SET fk_shipping_method = ".$shipping_method_id; $sql.= " SET fk_shipping_method = ".$shipping_method_id;
$sql.= " WHERE rowid=".$this->id; $sql.= " WHERE rowid=".$this->id;
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (! $resql) { if (! $resql) {
dol_syslog(get_class($this).'::setShippingMethod Error ', LOG_DEBUG); dol_syslog(get_class($this).'::setShippingMethod Error ', LOG_DEBUG);
$this->error = $this->db->lasterror(); $this->error = $this->db->lasterror();
$error++; $error++;
} else { } else {
if (!$notrigger) if (!$notrigger)
{ {
// Call trigger // Call trigger
$this->context=array('shippingmethodupdate'=>1); $this->context=array('shippingmethodupdate'=>1);
$result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused);
if ($result < 0) $error++; if ($result < 0) $error++;
// End call trigger // End call trigger
} }
} }
if ($error) if ($error)
{ {
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} else { } else {
$this->shipping_method_id = ($shipping_method_id=='NULL')?null:$shipping_method_id; $this->shipping_method_id = ($shipping_method_id=='NULL')?null:$shipping_method_id;
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
} }
@ -2217,17 +2217,17 @@ abstract class CommonObject
*/ */
public function setBankAccount($fk_account, $notrigger = false, $userused = null) public function setBankAccount($fk_account, $notrigger = false, $userused = null)
{ {
global $user; global $user;
if (empty($userused)) $userused=$user; if (empty($userused)) $userused=$user;
$error = 0; $error = 0;
if (! $this->table_element) { if (! $this->table_element) {
dol_syslog(get_class($this)."::setBankAccount was called on objet with property table_element not defined", LOG_ERR); dol_syslog(get_class($this)."::setBankAccount was called on objet with property table_element not defined", LOG_ERR);
return -1; return -1;
} }
$this->db->begin(); $this->db->begin();
if ($fk_account<0) $fk_account='NULL'; if ($fk_account<0) $fk_account='NULL';
dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')'); dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')');
@ -2236,36 +2236,36 @@ abstract class CommonObject
$sql.= " SET fk_account = ".$fk_account; $sql.= " SET fk_account = ".$fk_account;
$sql.= " WHERE rowid=".$this->id; $sql.= " WHERE rowid=".$this->id;
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (! $resql) if (! $resql)
{ {
dol_syslog(get_class($this).'::setBankAccount Error '.$sql.' - '.$this->db->error()); dol_syslog(get_class($this).'::setBankAccount Error '.$sql.' - '.$this->db->error());
$this->error = $this->db->lasterror(); $this->error = $this->db->lasterror();
$error++; $error++;
} }
else else
{ {
if (!$notrigger) if (!$notrigger)
{ {
// Call trigger // Call trigger
$this->context=array('bankaccountupdate'=>1); $this->context=array('bankaccountupdate'=>1);
$result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused);
if ($result < 0) $error++; if ($result < 0) $error++;
// End call trigger // End call trigger
} }
} }
if ($error) if ($error)
{ {
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
else else
{ {
$this->fk_account = ($fk_account=='NULL')?null:$fk_account; $this->fk_account = ($fk_account=='NULL')?null:$fk_account;
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
} }
// TODO: Move line related operations to CommonObjectLine? // TODO: Move line related operations to CommonObjectLine?
@ -2967,7 +2967,7 @@ abstract class CommonObject
} }
} }
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/** /**
* Add objects linked in llx_element_element. * Add objects linked in llx_element_element.
* *
@ -2978,7 +2978,7 @@ abstract class CommonObject
*/ */
public function add_object_linked($origin = null, $origin_id = null) public function add_object_linked($origin = null, $origin_id = null)
{ {
// phpcs:enable // phpcs:enable
$origin = (! empty($origin) ? $origin : $this->origin); $origin = (! empty($origin) ? $origin : $this->origin);
$origin_id = (! empty($origin_id) ? $origin_id : $this->origin_id); $origin_id = (! empty($origin_id) ? $origin_id : $this->origin_id);
@ -2986,7 +2986,7 @@ abstract class CommonObject
if ($origin == 'order') $origin='commande'; if ($origin == 'order') $origin='commande';
if ($origin == 'invoice') $origin='facture'; if ($origin == 'invoice') $origin='facture';
if ($origin == 'invoice_template') $origin='facturerec'; if ($origin == 'invoice_template') $origin='facturerec';
if ($origin == 'supplierorder') $origin='order_supplier'; if ($origin == 'supplierorder') $origin='order_supplier';
$this->db->begin(); $this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element ("; $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
@ -3003,16 +3003,16 @@ abstract class CommonObject
dol_syslog(get_class($this)."::add_object_linked", LOG_DEBUG); dol_syslog(get_class($this)."::add_object_linked", LOG_DEBUG);
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
else else
{ {
$this->error=$this->db->lasterror(); $this->error=$this->db->lasterror();
$this->db->rollback(); $this->db->rollback();
return 0; return 0;
} }
} }
/** /**
@ -3649,10 +3649,11 @@ abstract class CommonObject
{ {
if (empty($totalToShip)) $totalToShip=0; // Avoid warning because $totalToShip is '' if (empty($totalToShip)) $totalToShip=0; // Avoid warning because $totalToShip is ''
$totalToShip+=$line->qty_shipped; // defined for shipment only $totalToShip+=$line->qty_shipped; // defined for shipment only
}elseif ($line->element == 'commandefournisseurdispatch' && isset($line->qty)) }
{ elseif ($line->element == 'commandefournisseurdispatch' && isset($line->qty))
if (empty($totalToShip)) $totalToShip=0; {
$totalToShip+=$line->qty; // defined for reception only if (empty($totalToShip)) $totalToShip=0;
$totalToShip+=$line->qty; // defined for reception only
} }
// Define qty, weight, volume, weight_units, volume_units // Define qty, weight, volume, weight_units, volume_units
@ -4271,7 +4272,7 @@ abstract class CommonObject
$productstatic->id = $line->fk_product; $productstatic->id = $line->fk_product;
$productstatic->ref = $line->ref; $productstatic->ref = $line->ref;
$productstatic->type = $line->fk_product_type; $productstatic->type = $line->fk_product_type;
if(empty($productstatic->ref)){ if (empty($productstatic->ref)) {
$line->fetch_product(); $line->fetch_product();
$productstatic = $line->product; $productstatic = $line->product;
} }
@ -4637,14 +4638,14 @@ abstract class CommonObject
if (! empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; if (! empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true;
} }
if ($this->element == 'commande' && ! empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) { if ($this->element == 'commande' && ! empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) {
$setsharekey=true; $setsharekey=true;
} }
if ($this->element == 'facture' && ! empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) { if ($this->element == 'facture' && ! empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) {
$setsharekey=true; $setsharekey=true;
} }
if ($this->element == 'bank_account' && ! empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) { if ($this->element == 'bank_account' && ! empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) {
$setsharekey=true; $setsharekey=true;
} }
if ($setsharekey) if ($setsharekey)
{ {
@ -4807,7 +4808,7 @@ abstract class CommonObject
/* For triggers */ /* For triggers */
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/** /**
* Call trigger based on this instance. * Call trigger based on this instance.
* Some context information may also be provided into array property this->context. * Some context information may also be provided into array property this->context.
@ -4818,9 +4819,9 @@ abstract class CommonObject
* @param User $user Object user * @param User $user Object user
* @return int Result of run_triggers * @return int Result of run_triggers
*/ */
public function call_trigger($trigger_name, $user) public function call_trigger($trigger_name, $user)
{ {
// phpcs:enable // phpcs:enable
global $langs,$conf; global $langs,$conf;
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
@ -4845,7 +4846,7 @@ abstract class CommonObject
/* Functions for extrafields */ /* Functions for extrafields */
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/** /**
* Function to get extra fields of an object into $this->array_options * Function to get extra fields of an object into $this->array_options
* This method is in most cases called by method fetch of objects but you can call it separately. * This method is in most cases called by method fetch of objects but you can call it separately.
@ -4854,9 +4855,9 @@ abstract class CommonObject
* @param array $optionsArray Array resulting of call of extrafields->fetch_name_optionals_label(). 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 <0 if error, 0 if no values of extrafield to find nor found, 1 if an attribute is found and value loaded * @return int <0 if error, 0 if no values of extrafield to find nor found, 1 if an attribute is found and value loaded
*/ */
public function fetch_optionals($rowid = null, $optionsArray = null) public function fetch_optionals($rowid = null, $optionsArray = null)
{ {
// phpcs:enable // phpcs:enable
if (empty($rowid)) $rowid=$this->id; if (empty($rowid)) $rowid=$this->id;
// To avoid SQL errors. Probably not the better solution though // To avoid SQL errors. Probably not the better solution though
@ -5484,7 +5485,7 @@ abstract class CommonObject
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}/', $type))
{ {
$morecss = 'maxwidth75'; $morecss = 'maxwidth75';
} elseif ($type == 'url') { } elseif ($type == 'url') {
$morecss='minwidth400'; $morecss='minwidth400';
} }
elseif ($type == 'boolean') elseif ($type == 'boolean')
@ -7178,8 +7179,8 @@ abstract class CommonObject
* @param array $fieldsentry Properties of field * @param array $fieldsentry Properties of field
* @return string * @return string
*/ */
protected function quote($value, $fieldsentry) protected function quote($value, $fieldsentry)
{ {
if (is_null($value)) return 'NULL'; if (is_null($value)) return 'NULL';
elseif (preg_match('/^(int|double|real)/i', $fieldsentry['type'])) return $this->db->escape("$value"); elseif (preg_match('/^(int|double|real)/i', $fieldsentry['type'])) return $this->db->escape("$value");
else return "'".$this->db->escape($value)."'"; else return "'".$this->db->escape($value)."'";

View File

@ -1474,8 +1474,6 @@ class FactureFournisseur extends CommonInvoice
} }
} }
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/** /**
* Set draft status * Set draft status
* *
@ -1492,11 +1490,11 @@ class FactureFournisseur extends CommonInvoice
if ($this->statut == self::STATUS_DRAFT) if ($this->statut == self::STATUS_DRAFT)
{ {
dol_syslog(get_class($this)."::set_draft already draft status", LOG_WARNING); dol_syslog(__METHOD__." already draft status", LOG_WARNING);
return 0; return 0;
} }
dol_syslog(get_class($this)."::set_draft", LOG_DEBUG); dol_syslog(__METHOD__, LOG_DEBUG);
$this->db->begin(); $this->db->begin();

View File

@ -1765,8 +1765,6 @@ class Reception extends CommonObject
} }
} }
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/** /**
* Set draft status * Set draft status
* *
@ -1799,7 +1797,7 @@ class Reception extends CommonObject
$sql.= " SET fk_statut = ".self::STATUS_DRAFT; $sql.= " SET fk_statut = ".self::STATUS_DRAFT;
$sql.= " WHERE rowid = ".$this->id; $sql.= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this)."::set_draft", LOG_DEBUG); dol_syslog(__METHOD__, LOG_DEBUG);
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
// If stock increment is done on closing // If stock increment is done on closing