From 4cf62b9711ab7c774af96bc4e355d862b2596e55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Fri, 12 Jan 2024 17:11:08 +0100 Subject: [PATCH] clean code and fix (#27446) * clean code and fix * clean code and fix --- htdocs/categories/class/categorie.class.php | 2 +- htdocs/categories/viewcat.php | 32 ++++++++++++++------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index f7008dad5eb..3d060a80eaa 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -859,7 +859,7 @@ class Categorie extends CommonObject * @param string $sortorder Sort order ('ASC' or 'DESC'); * @param array $filter Filter array. Example array('field'=>'valueforlike', 'customsql'=>...) * @param string $filtermode Filter mode (AND or OR) - * @return array|int -1 if KO, array of instance of object if OK + * @return CommonObject[]|int[]|int Return -1 if KO, array of instance of object if OK * @see containsObject() */ public function getObjectsInCateg($type, $onlyids = 0, $limit = 0, $offset = 0, $sortfield = '', $sortorder = 'ASC', $filter = array(), $filtermode = 'AND') diff --git a/htdocs/categories/viewcat.php b/htdocs/categories/viewcat.php index 13864aa45db..5d1d44738fe 100644 --- a/htdocs/categories/viewcat.php +++ b/htdocs/categories/viewcat.php @@ -499,6 +499,7 @@ if ($type == Categorie::TYPE_PRODUCT) { if ($prods < 0) { dol_print_error($db, $object->error, $object->errors); } else { + /** @var Product[] $prods */ // Form to add record into the category $showclassifyform = 1; if ($showclassifyform) { @@ -584,6 +585,7 @@ if ($type == Categorie::TYPE_CUSTOMER) { if ($socs < 0) { dol_print_error($db, $object->error, $object->errors); } else { + /** @var Societe[] $socs */ // Form to add record into a category $showclassifyform = 1; if ($showclassifyform) { @@ -668,6 +670,7 @@ if ($type == Categorie::TYPE_SUPPLIER) { if ($socs < 0) { dol_print_error($db, $object->error, $object->errors); } else { + /** @var Fournisseur[] $socs */ // Form to add record into a category $showclassifyform = 1; if ($showclassifyform) { @@ -751,10 +754,11 @@ if ($type == Categorie::TYPE_MEMBER) { $permission = $user->hasRight('adherent', 'creer'); - $prods = $object->getObjectsInCateg($type, 0, $limit, $offset); - if ($prods < 0) { + $members = $object->getObjectsInCateg($type, 0, $limit, $offset); + if ($members < 0) { dol_print_error($db, $object->error, $object->errors); } else { + /** @var Adherent[] $members */ // Form to add record into a category $showclassifyform = 1; if ($showclassifyform) { @@ -784,7 +788,7 @@ if ($type == Categorie::TYPE_MEMBER) { print '
'; $param = '&limit='.$limit.'&id='.$id.'&type='.$type; - $num = count($prods); + $num = count($members); $nbtotalofrecords = ''; $newcardbutton = dolGetButtonTitle($langs->trans("AddMember"), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/adherents/card.php?action=create&memcats[]='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id), '', $user->hasRight('adherent', 'creer')); @@ -793,9 +797,9 @@ if ($type == Categorie::TYPE_MEMBER) { print ''."\n"; print ''."\n"; - if (count($prods) > 0) { + if (count($members) > 0) { $i = 0; - foreach ($prods as $key => $member) { + foreach ($members as $key => $member) { $i++; if ($i > $limit) { break; @@ -841,6 +845,7 @@ if ($type == Categorie::TYPE_CONTACT) { if (is_numeric($contacts) && $contacts < 0) { dol_print_error($db, $object->error, $object->errors); } else { + /** @var Contact[] $contacts */ // Form to add record into a category $showclassifyform = 1; if ($showclassifyform) { @@ -932,6 +937,7 @@ if ($type == Categorie::TYPE_ACCOUNT) { if ($accounts < 0) { dol_print_error($db, $object->error, $object->errors); } else { + /** @var Account[] $accounts */ // Form to add record into a category $showclassifyform = 1; if ($showclassifyform) { @@ -1019,6 +1025,7 @@ if ($type == Categorie::TYPE_PROJECT) { if ($objects < 0) { dol_print_error($db, $object->error, $object->errors); } else { + /** @var Project $object */ // Form to add record into a category $showclassifyform = 1; if ($showclassifyform) { @@ -1104,6 +1111,7 @@ if ($type == Categorie::TYPE_USER) { if ($users < 0) { dol_print_error($db, $object->error, $object->errors); } else { + /** @var User[] $users */ // Form to add record into a category $showclassifyform = 1; if ($showclassifyform) { @@ -1180,7 +1188,7 @@ if ($type == Categorie::TYPE_USER) { // List of warehouses if ($type == Categorie::TYPE_WAREHOUSE) { if ($user->hasRight("stock", "read")) { - $permission = $user->rights->stock->creer; + $permission = $user->hasRight('stock', 'creer'); require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; @@ -1188,6 +1196,7 @@ if ($type == Categorie::TYPE_WAREHOUSE) { if ($objects < 0) { dol_print_error($db, $object->error, $object->errors); } else { + /** @var Entrepot[] $objects */ print ''; print ''; print ''; @@ -1208,7 +1217,7 @@ if ($type == Categorie::TYPE_WAREHOUSE) { if (count($objects) > 0) { $i = 0; - foreach ($objects as $key => $project) { + foreach ($objects as $key => $warehouse) { $i++; if ($i > $limit) { break; @@ -1216,14 +1225,14 @@ if ($type == Categorie::TYPE_WAREHOUSE) { print "\t".''."\n"; print '\n"; - print '\n"; - print '\n"; + print '\n"; + print '\n"; // Link to delete from category print '
'.$langs->trans("Name").'
'; - print $project->getNomUrl(1); + print $warehouse->getNomUrl(1); print "'.$project->ref."'.$project->title."'.$warehouse->ref."'.$warehouse->lieu."'; if ($permission) { - print "id."'>"; + print "id."'>"; print $langs->trans("DeleteFromCat"); print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft'); print ""; @@ -1253,6 +1262,7 @@ if ($type == Categorie::TYPE_TICKET) { if ($tickets < 0) { dol_print_error($db, $object->error, $object->errors); } else { + /** @var Ticket[] $tickets */ // Form to add record into a category $showclassifyform = 1; if ($showclassifyform) {