From f03f54d406c8240c7aa91bfa246ae32e992e77f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Tue, 16 Sep 2025 00:54:59 +0200 Subject: [PATCH 1/2] clean code (#35350) * clean code * clean code * clean code * clean code * clean code * clean code * clean code --- dev/build/phpstan/phpstan-baseline.neon | 36 ------------------- htdocs/salaries/class/salary.class.php | 48 +++++++++++-------------- 2 files changed, 21 insertions(+), 63 deletions(-) diff --git a/dev/build/phpstan/phpstan-baseline.neon b/dev/build/phpstan/phpstan-baseline.neon index da4ecbdb44d..5dc51a035c4 100644 --- a/dev/build/phpstan/phpstan-baseline.neon +++ b/dev/build/phpstan/phpstan-baseline.neon @@ -17670,42 +17670,6 @@ parameters: count: 2 path: ../../../htdocs/salaries/class/paymentsalary.class.php - - - message: '#^Call to function method_exists\(\) with \$this\(Salary\) and ''LibStatut'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: ../../../htdocs/salaries/class/salary.class.php - - - - message: '#^Call to function method_exists\(\) with \$this\(Salary\) and ''getNomUrl'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: ../../../htdocs/salaries/class/salary.class.php - - - - message: '#^Call to function property_exists\(\) with \$this\(Salary\) and ''amount'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: ../../../htdocs/salaries/class/salary.class.php - - - - message: '#^Call to function property_exists\(\) with \$this\(Salary\) and ''type_payment'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: ../../../htdocs/salaries/class/salary.class.php - - - - message: '#^Method Salary\:\:getSommePaiement\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: ../../../htdocs/salaries/class/salary.class.php - - - - message: '#^Negated boolean expression is always true\.$#' - identifier: booleanNot.alwaysTrue - count: 2 - path: ../../../htdocs/salaries/class/salary.class.php - - message: '#^Negated boolean expression is always false\.$#' identifier: booleanNot.alwaysFalse diff --git a/htdocs/salaries/class/salary.class.php b/htdocs/salaries/class/salary.class.php index d8f26b229fc..220efd493b7 100644 --- a/htdocs/salaries/class/salary.class.php +++ b/htdocs/salaries/class/salary.class.php @@ -2,7 +2,7 @@ /* Copyright (C) 2011-2022 Alexandre Spangaro * Copyright (C) 2014 Juanjo Menent * Copyright (C) 2021 Gauthier VERDOL - * Copyright (C) 2024 Frédéric France + * Copyright (C) 2024-2025 Frédéric France * Copyright (C) 2024-2025 MDW * * This program is free software; you can redistribute it and/or modify @@ -253,11 +253,9 @@ class Salary extends CommonObject } // Update extrafield - if (!$error) { - $result = $this->insertExtraFields(); - if ($result < 0) { - $error++; - } + $result = $this->insertExtraFields(); + if ($result < 0) { + $error++; } if (!$notrigger) { @@ -340,7 +338,7 @@ class Salary extends CommonObject $this->status = $obj->paye; $this->fk_bank = $obj->fk_bank; $this->fk_user_author = $obj->fk_user_author; - $this->fk_user_modif = $obj->fk_user_modif; + $this->fk_user_modif = $obj->fk_user_modif; $this->fk_account = $obj->fk_account; $this->accountid = $obj->fk_account; @@ -485,11 +483,9 @@ class Salary extends CommonObject if ($this->id > 0) { // Update extrafield - if (!$error) { - $result = $this->insertExtraFields(); - if ($result < 0) { - $error++; - } + $result = $this->insertExtraFields(); + if ($result < 0) { + $error++; } // Call trigger @@ -656,7 +652,7 @@ class Salary extends CommonObject * Return amount of payments already done * * @param int $multicurrency Return multicurrency_amount instead of amount. -1=Return both. - * @return float|int|array Amount of payment already done, <0 and set ->error if KO + * @return float|int|array{} Amount of payment already done, <0 and set ->error if KO */ public function getSommePaiement($multicurrency = 0) { @@ -873,33 +869,31 @@ class Salary extends CommonObject $return .= img_picto('', $this->picto); $return .= ''; $return .= '
'; - $return .= ''.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : $this->ref).''; + $return .= '' . $this->getNomUrl(1) . ''; if ($selected >= 0) { $return .= ''; } if (!empty($arraydata['user']) && is_object($arraydata['user'])) { $user = $arraydata['user']; '@phan-var-force User $user'; + /** @var User $user */ $return .= '
'.$user->getNomUrl(empty($arraydata['user']->photo) ? 1 : -1, '', 0, 0, 16, 0, '', 'maxwidth100').''; } - if (property_exists($this, 'amount')) { - $return .= '
'.price($this->amount).''; - if (property_exists($this, 'type_payment') && !empty($this->type_payment)) { - $return .= ' '; - if ($langs->trans("PaymentTypeShort".$this->type_payment) != "PaymentTypeShort".$this->type_payment) { - $return .= $langs->trans("PaymentTypeShort".$this->type_payment); - } elseif ($langs->trans("PaymentType".$this->type_payment) != "PaymentType".$this->type_payment) { - $return .= $langs->trans("PaymentType".$this->type_payment); - } - $return .= ''; + $return .= '
'.price($this->amount).''; + if (!empty($this->type_payment)) { + $return .= ' '; + if ($langs->trans("PaymentTypeShort".$this->type_payment) != "PaymentTypeShort".$this->type_payment) { + $return .= $langs->trans("PaymentTypeShort".$this->type_payment); + } elseif ($langs->trans("PaymentType".$this->type_payment) != "PaymentType".$this->type_payment) { + $return .= $langs->trans("PaymentType".$this->type_payment); } + $return .= ''; } - if (method_exists($this, 'LibStatut')) { - $return .= '
'.$this->getLibStatut(3, isset($this->alreadypaid) ? $this->alreadypaid : $this->totalpaid).'
'; - } + $return .= '
'.$this->getLibStatut(3, isset($this->alreadypaid) ? $this->alreadypaid : $this->totalpaid).'
'; $return .= '
'; $return .= ''; $return .= ''; + return $return; } From 83407ec49f6d87b0b6b6811ce938c13bbb89b35c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Tue, 16 Sep 2025 00:55:58 +0200 Subject: [PATCH 2/2] clean code (#35355) --- htdocs/comm/action/list.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/comm/action/list.php b/htdocs/comm/action/list.php index db0a8e1a3f3..9f1a9e3573f 100644 --- a/htdocs/comm/action/list.php +++ b/htdocs/comm/action/list.php @@ -746,12 +746,12 @@ $viewmode .= ''; $tmpforcreatebutton = dol_getdate(dol_now('tzuserrel'), true); -$newparam = '&month='.str_pad((string) $month, 2, "0", STR_PAD_LEFT).'&year='.$tmpforcreatebutton['year']; +$newparam = '?month='.str_pad((string) $month, 2, "0", STR_PAD_LEFT).'&year='.$tmpforcreatebutton['year']; $url = DOL_URL_ROOT.'/comm/action/card.php?action=create'; $url .= '&apyear='.$tmpforcreatebutton['year'].'&apmonth='.$tmpforcreatebutton['mon'].'&apday='.$tmpforcreatebutton['mday']; $url .= '&aphour='.$tmpforcreatebutton['hours'].'&apmin='.$tmpforcreatebutton['minutes']; -$url .= '&backtopage='.urlencode($_SERVER["PHP_SELF"].($newparam ? '?'.$newparam : '')); +$url .= '&backtopage='.urlencode($_SERVER["PHP_SELF"].$newparam); $newcardbutton = dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', $url, '', (int) ($user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create')));