From 18c5c586abb9a5213a55055c9775ce7b665f1153 Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Wed, 1 May 2019 09:38:27 +0200 Subject: [PATCH 1/3] Cleanup set_draft in syslog --- htdocs/commande/class/commande.class.php | 2 +- htdocs/compta/facture/class/facture.class.php | 23 +++++++++---------- .../fourn/class/fournisseur.facture.class.php | 6 ++--- htdocs/reception/class/reception.class.php | 4 +--- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 35cb8335232..38a38d45b12 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -499,7 +499,7 @@ class Commande extends CommonOrder return -1; } - dol_syslog(get_class($this)."::set_draft", LOG_DEBUG); + dol_syslog(__METHOD__, LOG_DEBUG); $this->db->begin(); diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index c2dc89c903e..7483d527f4d 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -2532,7 +2532,6 @@ class Facture extends CommonInvoice return true; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Set draft status * @@ -2540,7 +2539,7 @@ class Facture extends CommonInvoice * @param int $idwarehouse Id warehouse to use for stock change. * @return int <0 if KO, >0 if OK */ - public function setDraft($user, $idwarehouse = -1) + public function setDraft($user, $idwarehouse = -1) { // phpcs:enable global $conf,$langs; @@ -2549,11 +2548,11 @@ class Facture extends CommonInvoice 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; } - dol_syslog(get_class($this)."::set_draft", LOG_DEBUG); + dol_syslog(__METHOD__, LOG_DEBUG); $this->db->begin(); @@ -2564,10 +2563,10 @@ class Facture extends CommonInvoice $result=$this->db->query($sql); if ($result) { - if (! $error) - { - $this->oldcopy= clone $this; - } + if (! $error) + { + $this->oldcopy= clone $this; + } // 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)) @@ -2595,15 +2594,15 @@ class Facture extends CommonInvoice $this->brouillon = 1; $this->statut = self::STATUS_DRAFT; - // Call trigger - $result=$this->call_trigger('BILL_UNVALIDATE', $user); - if ($result < 0) + // Call trigger + $result=$this->call_trigger('BILL_UNVALIDATE', $user); + if ($result < 0) { $error++; $this->statut=$old_statut; $this->brouillon=0; } - // End call triggers + // End call triggers } else { $this->db->rollback(); return -1; diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index bf517f85c64..d9c6781e74d 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -1474,8 +1474,6 @@ class FactureFournisseur extends CommonInvoice } } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Set draft status * @@ -1492,11 +1490,11 @@ class FactureFournisseur extends CommonInvoice 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; } - dol_syslog(get_class($this)."::set_draft", LOG_DEBUG); + dol_syslog(__METHOD__, LOG_DEBUG); $this->db->begin(); diff --git a/htdocs/reception/class/reception.class.php b/htdocs/reception/class/reception.class.php index 0b416512ffa..bd45bf45390 100644 --- a/htdocs/reception/class/reception.class.php +++ b/htdocs/reception/class/reception.class.php @@ -1763,8 +1763,6 @@ class Reception extends CommonObject } } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Set draft status * @@ -1797,7 +1795,7 @@ class Reception extends CommonObject $sql.= " SET fk_statut = ".self::STATUS_DRAFT; $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 stock increment is done on closing From 6e5d826d651ee6a525e440baeb1d8067cb589702 Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Mon, 13 May 2019 22:02:33 +0200 Subject: [PATCH 2/3] Clean PHPCS for commonobject.class --- htdocs/core/class/commonobject.class.php | 195 ++++++++++++----------- 1 file changed, 98 insertions(+), 97 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 57f2a7ef97c..a32c55a13e8 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1227,12 +1227,12 @@ abstract class CommonObject $result=array(); $i=0; //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; $element='commande'; - } elseif($this->element=='reception' && $this->origin_id != 0) { - $id=$this->origin_id; - $element='order_supplier'; + } elseif ($this->element=='reception' && $this->origin_id != 0) { + $id=$this->origin_id; + $element='order_supplier'; } else { $id=$this->id; $element=$this->element; @@ -2086,25 +2086,25 @@ abstract class CommonObject * Change the shipping method * * @param int $shipping_method_id Id of shipping method - * @param bool $notrigger false=launch triggers after, true=disable triggers - * @param User $userused Object user + * @param bool $notrigger false=launch triggers after, true=disable triggers + * @param User $userused Object user * * @return int 1 if OK, 0 if KO */ 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) { dol_syslog(get_class($this)."::setShippingMethod was called on objet with property table_element not defined", LOG_ERR); return -1; } - $this->db->begin(); + $this->db->begin(); if ($shipping_method_id<0) $shipping_method_id='NULL'; 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.= " SET fk_shipping_method = ".$shipping_method_id; $sql.= " WHERE rowid=".$this->id; - $resql = $this->db->query($sql); + $resql = $this->db->query($sql); if (! $resql) { dol_syslog(get_class($this).'::setShippingMethod Error ', LOG_DEBUG); $this->error = $this->db->lasterror(); $error++; - } else { - if (!$notrigger) - { - // Call trigger - $this->context=array('shippingmethodupdate'=>1); - $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); - if ($result < 0) $error++; - // End call trigger - } - } - if ($error) - { - $this->db->rollback(); - return -1; - } else { - $this->shipping_method_id = ($shipping_method_id=='NULL')?null:$shipping_method_id; - $this->db->commit(); - return 1; - } + } else { + if (!$notrigger) + { + // Call trigger + $this->context=array('shippingmethodupdate'=>1); + $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); + if ($result < 0) $error++; + // End call trigger + } + } + if ($error) + { + $this->db->rollback(); + return -1; + } else { + $this->shipping_method_id = ($shipping_method_id=='NULL')?null:$shipping_method_id; + $this->db->commit(); + return 1; + } } @@ -2217,17 +2217,17 @@ abstract class CommonObject */ 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) { dol_syslog(get_class($this)."::setBankAccount was called on objet with property table_element not defined", LOG_ERR); return -1; } - $this->db->begin(); + $this->db->begin(); if ($fk_account<0) $fk_account='NULL'; dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')'); @@ -2236,36 +2236,36 @@ abstract class CommonObject $sql.= " SET fk_account = ".$fk_account; $sql.= " WHERE rowid=".$this->id; - $resql = $this->db->query($sql); - if (! $resql) - { - dol_syslog(get_class($this).'::setBankAccount Error '.$sql.' - '.$this->db->error()); - $this->error = $this->db->lasterror(); - $error++; - } - else - { - if (!$notrigger) - { - // Call trigger - $this->context=array('bankaccountupdate'=>1); - $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); - if ($result < 0) $error++; - // End call trigger - } - } - if ($error) - { - $this->db->rollback(); - return -1; - } - else - { - $this->fk_account = ($fk_account=='NULL')?null:$fk_account; - $this->db->commit(); - return 1; - } - } + $resql = $this->db->query($sql); + if (! $resql) + { + dol_syslog(get_class($this).'::setBankAccount Error '.$sql.' - '.$this->db->error()); + $this->error = $this->db->lasterror(); + $error++; + } + else + { + if (!$notrigger) + { + // Call trigger + $this->context=array('bankaccountupdate'=>1); + $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); + if ($result < 0) $error++; + // End call trigger + } + } + if ($error) + { + $this->db->rollback(); + return -1; + } + else + { + $this->fk_account = ($fk_account=='NULL')?null:$fk_account; + $this->db->commit(); + return 1; + } + } // 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. * @@ -2978,7 +2978,7 @@ abstract class CommonObject */ public function add_object_linked($origin = null, $origin_id = null) { - // phpcs:enable + // phpcs:enable $origin = (! empty($origin) ? $origin : $this->origin); $origin_id = (! empty($origin_id) ? $origin_id : $this->origin_id); @@ -2986,7 +2986,7 @@ abstract class CommonObject if ($origin == 'order') $origin='commande'; if ($origin == 'invoice') $origin='facture'; if ($origin == 'invoice_template') $origin='facturerec'; - if ($origin == 'supplierorder') $origin='order_supplier'; + if ($origin == 'supplierorder') $origin='order_supplier'; $this->db->begin(); $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); if ($this->db->query($sql)) - { - $this->db->commit(); - return 1; - } - else - { - $this->error=$this->db->lasterror(); - $this->db->rollback(); - return 0; - } + { + $this->db->commit(); + return 1; + } + else + { + $this->error=$this->db->lasterror(); + $this->db->rollback(); + return 0; + } } /** @@ -3649,10 +3649,11 @@ abstract class CommonObject { if (empty($totalToShip)) $totalToShip=0; // Avoid warning because $totalToShip is '' $totalToShip+=$line->qty_shipped; // defined for shipment only - }elseif ($line->element == 'commandefournisseurdispatch' && isset($line->qty)) - { - if (empty($totalToShip)) $totalToShip=0; - $totalToShip+=$line->qty; // defined for reception only + } + elseif ($line->element == 'commandefournisseurdispatch' && isset($line->qty)) + { + if (empty($totalToShip)) $totalToShip=0; + $totalToShip+=$line->qty; // defined for reception only } // Define qty, weight, volume, weight_units, volume_units @@ -4271,7 +4272,7 @@ abstract class CommonObject $productstatic->id = $line->fk_product; $productstatic->ref = $line->ref; $productstatic->type = $line->fk_product_type; - if(empty($productstatic->ref)){ + if (empty($productstatic->ref)) { $line->fetch_product(); $productstatic = $line->product; } @@ -4637,14 +4638,14 @@ abstract class CommonObject if (! empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; } 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)) { - $setsharekey=true; - } + $setsharekey=true; + } if ($this->element == 'bank_account' && ! empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) { - $setsharekey=true; - } + $setsharekey=true; + } if ($setsharekey) { @@ -4807,7 +4808,7 @@ abstract class CommonObject /* For triggers */ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Call trigger based on this instance. * Some context information may also be provided into array property this->context. @@ -4818,9 +4819,9 @@ abstract class CommonObject * @param User $user Object user * @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; include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; @@ -4845,7 +4846,7 @@ abstract class CommonObject /* 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 * 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. * @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; // 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)) { $morecss = 'maxwidth75'; - } elseif ($type == 'url') { + } elseif ($type == 'url') { $morecss='minwidth400'; } elseif ($type == 'boolean') @@ -7178,8 +7179,8 @@ abstract class CommonObject * @param array $fieldsentry Properties of field * @return string */ - protected function quote($value, $fieldsentry) - { + protected function quote($value, $fieldsentry) + { if (is_null($value)) return 'NULL'; elseif (preg_match('/^(int|double|real)/i', $fieldsentry['type'])) return $this->db->escape("$value"); else return "'".$this->db->escape($value)."'"; From 79a347ab115052a7b1c723e87cf2c92b8c5a273c Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Mon, 13 May 2019 22:49:43 +0200 Subject: [PATCH 3/3] Fix PHPCS contract list --- htdocs/contrat/list.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/contrat/list.php b/htdocs/contrat/list.php index cd833f07894..1ba35031041 100644 --- a/htdocs/contrat/list.php +++ b/htdocs/contrat/list.php @@ -48,8 +48,8 @@ $contextpage= GETPOST('contextpage', 'aZ')?GETPOST('contextpage', 'aZ'):'contrac $search_name=GETPOST('search_name', 'alpha'); $search_email=GETPOST('search_email', 'alpha'); -$search_town=GETPOST('search_town','alpha'); -$search_zip=GETPOST('search_zip','alpha'); +$search_town=GETPOST('search_town', 'alpha'); +$search_zip=GETPOST('search_zip', 'alpha'); $search_state=trim(GETPOST("search_state")); $search_country=GETPOST("search_country", 'int'); $search_type_thirdparty=GETPOST("search_type_thirdparty", 'int'); @@ -709,8 +709,8 @@ while ($i < min($num, $limit)) $listsalesrepresentatives=$socstatic->getSalesRepresentatives($user); if ($listsalesrepresentatives < 0) dol_print_error($db); $nbofsalesrepresentative=count($listsalesrepresentatives); - if ($nbofsalesrepresentative > 3) { - // We print only number + if ($nbofsalesrepresentative > 3) { + // We print only number print ''; print $nbofsalesrepresentative; print '';