From c8458c22e8a9f3742b624d5d4a7a4e1fa5b61720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 17 Sep 2025 14:22:58 +0200 Subject: [PATCH] clean code (#35358) * clean code * clean code * clean code * clean code * clean code * clean code --------- Co-authored-by: Laurent Destailleur --- dev/build/phpstan/phpstan-baseline.neon | 42 ------------------- .../class/accountingaccount.class.php | 42 +++++++++---------- 2 files changed, 20 insertions(+), 64 deletions(-) diff --git a/dev/build/phpstan/phpstan-baseline.neon b/dev/build/phpstan/phpstan-baseline.neon index 19eb4a4564b..4925d9f3802 100644 --- a/dev/build/phpstan/phpstan-baseline.neon +++ b/dev/build/phpstan/phpstan-baseline.neon @@ -252,48 +252,6 @@ parameters: count: 4 path: ../../../htdocs/accountancy/class/accountancyexport.class.php - - - message: '#^Negated boolean expression is always true\.$#' - identifier: booleanNot.alwaysTrue - count: 1 - path: ../../../htdocs/accountancy/class/accountingaccount.class.php - - - - message: '#^Property AccountingAccount\:\:\$account_number \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 3 - path: ../../../htdocs/accountancy/class/accountingaccount.class.php - - - - message: '#^Property AccountingAccount\:\:\$fk_pcg_version \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/accountancy/class/accountingaccount.class.php - - - - message: '#^Property AccountingAccount\:\:\$label \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/accountancy/class/accountingaccount.class.php - - - - message: '#^Property AccountingAccount\:\:\$labelshort \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/accountancy/class/accountingaccount.class.php - - - - message: '#^Property AccountingAccount\:\:\$pcg_type \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/accountancy/class/accountingaccount.class.php - - - - message: '#^Ternary operator condition is always true\.$#' - identifier: ternary.alwaysTrue - count: 1 - path: ../../../htdocs/accountancy/class/accountingaccount.class.php - - message: '#^Call to function array_key_exists\(\) with ''error'' and array\{ref\: mixed, label\: mixed, acquisition_value_ht\: mixed, depreciation\: non\-empty\-array\, disposal\?\: array\{date\: mixed, amount\: mixed, subject_to_vat\: bool\}\} will always evaluate to false\.$#' identifier: function.impossibleType diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php index 97960271195..6f519987532 100644 --- a/htdocs/accountancy/class/accountingaccount.class.php +++ b/htdocs/accountancy/class/accountingaccount.class.php @@ -1,11 +1,11 @@ - * Copyright (C) 2013-2024 Alexandre Spangaro - * Copyright (C) 2013-2021 Florian Henry - * Copyright (C) 2014 Juanjo Menent - * Copyright (C) 2015 Ari Elbaz (elarifr) - * Copyright (C) 2018-2025 Frédéric France - * Copyright (C) 2024 MDW +/* Copyright (C) 2013-2014 Olivier Geffroy + * Copyright (C) 2013-2024 Alexandre Spangaro + * Copyright (C) 2013-2021 Florian Henry + * Copyright (C) 2014 Juanjo Menent + * Copyright (C) 2015 Ari Elbaz (elarifr) + * Copyright (C) 2018-2025 Frédéric France + * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -80,17 +80,17 @@ class AccountingAccount extends CommonObject public $datec; /** - * @var string pcg version + * @var ?string pcg version */ public $fk_pcg_version; /** - * @var string pcg type + * @var ?string pcg type */ public $pcg_type; /** - * @var string account number + * @var ?string account number */ public $account_number; @@ -115,12 +115,12 @@ class AccountingAccount extends CommonObject public $status; /** - * @var string Label of account + * @var ?string Label of account */ public $label; /** - * @var string Label short of account + * @var ?string Label short of account */ public $labelshort; @@ -358,7 +358,7 @@ class AccountingAccount extends CommonObject $sql = "UPDATE " . $this->db->prefix() . $this->table_element; $sql .= " SET fk_pcg_version = " . ($this->fk_pcg_version ? "'" . $this->db->escape($this->fk_pcg_version) . "'" : "null"); - $sql .= " , pcg_type = " . ($this->pcg_type ? "'" . $this->db->escape($this->pcg_type) . "'" : "null"); + $sql .= " , pcg_type = '" . $this->db->escape($this->pcg_type) . "'"; $sql .= " , account_number = '" . $this->db->escape($this->account_number) . "'"; $sql .= " , account_parent = " . (int) $this->account_parent; $sql .= " , label = " . ($this->label ? "'" . $this->db->escape($this->label) . "'" : "''"); @@ -436,16 +436,14 @@ class AccountingAccount extends CommonObject if ($result > 0) { $this->db->begin(); - if (!$error) { - $sql = "DELETE FROM " . $this->db->prefix() . $this->table_element; - $sql .= " WHERE rowid=" . ((int) $this->id); + $sql = "DELETE FROM " . $this->db->prefix() . $this->table_element; + $sql .= " WHERE rowid=" . ((int) $this->id); - dol_syslog(get_class($this) . "::delete sql=" . $sql); - $resql = $this->db->query($sql); - if (!$resql) { - $error++; - $this->errors[] = "Error " . $this->db->lasterror(); - } + dol_syslog(get_class($this) . "::delete sql=" . $sql); + $resql = $this->db->query($sql); + if (!$resql) { + $error++; + $this->errors[] = "Error " . $this->db->lasterror(); } // Commit or rollback