Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean code and phpdoc #28773

Merged
merged 27 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions dev/tools/phan/config.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
/* Copyright (C) 2024 MDW <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
*/
define('DOL_PROJECT_ROOT', __DIR__.'/../../..');
define('DOL_DOCUMENT_ROOT', DOL_PROJECT_ROOT.'/htdocs');
Expand Down Expand Up @@ -535,7 +536,8 @@
// 'PhanTypeInvalidThrowsIsInterface',
// 'PhanPluginRedundantAssignmentInLoop',
// 'PhanInvalidCommentForDeclarationType',
//'PhanParamSignatureMismatchInternal',
// 'PhanParamSignatureMismatchInternal',
'PhanParamSignatureMismatch',
frederic34 marked this conversation as resolved.
Show resolved Hide resolved
// 'PhanPluginEmptyStatementForeachLoop',
// 'PhanCompatibleDimAlternativeSyntax',
'PhanInvalidFQSENInClasslike',
Expand Down Expand Up @@ -656,5 +658,4 @@
'sockets' => PHAN_DIR . '/stubs/sockets.phan_php',
'zip' => PHAN_DIR . '/stubs/zip.phan_php',
],

];
5 changes: 3 additions & 2 deletions dev/tools/phan/config_fixer.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php
/* Copyright (C) 2024 MDW <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
*/

// Uncomment require_once to enable corresponding fixer

Expand All @@ -7,8 +10,6 @@
//require_once __DIR__.'/plugins/UrlEncodeStringifyFixer.php';
require_once __DIR__.'/plugins/SelectDateFixer.php';

/* Copyright (C) 2024 MDW <[email protected]>
*/
define('DOL_PROJECT_ROOT', __DIR__.'/../../..');
define('DOL_DOCUMENT_ROOT', DOL_PROJECT_ROOT.'/htdocs');
define('PHAN_DIR', __DIR__);
Expand Down
5 changes: 3 additions & 2 deletions htdocs/comm/remx.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <[email protected]>
* Copyright (C) 2004-2019 Laurent Destailleur <[email protected]>
* Copyright (C) 2008 Raphael Bertrand (Resultic) <[email protected]>
* Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2019-2024 Frédéric France <frederic.france@free.fr>
*
* 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
Expand Down Expand Up @@ -45,6 +45,7 @@

// Security check
$socid = GETPOSTINT('id') ? GETPOSTINT('id') : GETPOSTINT('socid');
/** @var User $user */
if ($user->socid > 0) {
$socid = $user->socid;
}
Expand All @@ -55,7 +56,7 @@
}
$result = restrictedArea($user, 'societe', $id, '&societe', '', 'fk_soc', 'rowid', 0);

$permissiontocreate = ($user->rights->societe->creer || $user->rights->facture->creer);
$permissiontocreate = ($user->hasRight('societe', 'creer') || $user->hasRight('facture', 'creer'));



Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/class/commonnumrefgenerator.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function info($langs)
* Checks if the numbers already in the database do not
* cause conflicts that would prevent this numbering working.
*
* @param Object $object Object we need next value for
* @param CommonObject $object Object we need next value for
* @return boolean false if conflict, true if ok
*/
public function canBeActivated($object)
Expand Down
15 changes: 8 additions & 7 deletions htdocs/core/lib/functions2.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Copyright (C) 2015-2016 Raphaël Doursenaud <[email protected]>
* Copyright (C) 2017 Juanjo Menent <[email protected]>
* Copyright (C) 2024 MDW <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
*
* 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
Expand Down Expand Up @@ -892,7 +893,7 @@ function array2table($data, $tableMarkup = 1, $tableoptions = '', $troptions = '
* @param string $table Table containing field with counter
* @param string $field Field containing already used values of counter
* @param string $where To add a filter on selection (for example to filter on invoice types)
* @param Societe $objsoc The company that own the object we need a counter for
* @param Societe|string $objsoc The company that own the object we need a counter for
* @param string $date Date to use for the {y},{m},{d} tags.
* @param string $mode 'next' for next value or 'last' for last value
* @param bool $bentityon Activate the entity filter. Default is true (for modules not compatible with multicompany)
Expand Down Expand Up @@ -2511,16 +2512,16 @@ function colorLighten($hex, $percent)


/**
* @param string $hex color in hex
* @param float $alpha 0 to 1 to add alpha channel
* @param bool $returnArray true=return an array instead, false=return string
* @return string|array String or array
* @param string $hex color in hex
* @param float|false $alpha 0 to 1 to add alpha channel
* @param bool $returnArray true=return an array instead, false=return string
* @return string|array String or array
*/
function colorHexToRgb($hex, $alpha = false, $returnArray = false)
{
$string = '';
$hex = str_replace('#', '', $hex);
$length = strlen($hex);
$hex = str_replace('#', '', $hex);
$length = strlen($hex);
$rgb = array();
$rgb['r'] = hexdec($length == 6 ? substr($hex, 0, 2) : ($length == 3 ? str_repeat(substr($hex, 0, 1), 2) : 0));
$rgb['g'] = hexdec($length == 6 ? substr($hex, 2, 2) : ($length == 3 ? str_repeat(substr($hex, 1, 1), 2) : 0));
Expand Down
32 changes: 15 additions & 17 deletions htdocs/core/lib/usergroups.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Copyright (C) 2015 Alexandre Spangaro <[email protected]>
* Copyright (C) 2018 Ferran Marcet <[email protected]>
* Copyright (C) 2021-2023 Anthony Berton <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
*
* 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
Expand Down Expand Up @@ -237,7 +238,7 @@ function group_prepare_head($object)

$canreadperms = true;
if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) {
$canreadperms = ($user->admin || $user->rights->user->group_advance->readperms);
$canreadperms = ($user->admin || $user->hasRight('user', 'group_advance', 'readperms'));
}

$h = 0;
Expand Down Expand Up @@ -504,17 +505,17 @@ function showSkins($fuser, $edit = 0, $foruserprofile = false)
//Nothing
} else {
$listofdarkmodes = array(
'0' => $langs->trans("AlwaysDisabled"),
'1' => $langs->trans("AccordingToBrowser"),
'2' => $langs->trans("AlwaysEnabled")
$langs->trans("AlwaysDisabled"),
$langs->trans("AccordingToBrowser"),
$langs->trans("AlwaysEnabled")
);
print '<tr class="oddeven">';
print '<td>'.$langs->trans("DarkThemeMode").'</td>';
print '<td colspan="'.($colspan - 1).'">';
if ($edit) {
print $form->selectarray('THEME_DARKMODEENABLED', $listofdarkmodes, isset($conf->global->THEME_DARKMODEENABLED) ? $conf->global->THEME_DARKMODEENABLED : 0);
print $form->selectarray('THEME_DARKMODEENABLED', $listofdarkmodes, getDolGlobalInt('THEME_DARKMODEENABLED'));
} else {
print $listofdarkmodes[isset($conf->global->THEME_DARKMODEENABLED) ? $conf->global->THEME_DARKMODEENABLED : 0];
print $listofdarkmodes[getDolGlobalInt('THEME_DARKMODEENABLED')];
}
print $form->textwithpicto('', $langs->trans("DoesNotWorkWithAllThemes"));
print '</tr>';
Expand Down Expand Up @@ -545,11 +546,11 @@ function showSkins($fuser, $edit = 0, $foruserprofile = false)
print '</td>';*/
} else {
$listoftopmenumodes = array(
'0' => $langs->transnoentitiesnoconv("IconAndText"),
'1' => $langs->transnoentitiesnoconv("TextOnly"),
'2' => $langs->transnoentitiesnoconv("IconOnlyAllTextsOnHover"),
'3' => $langs->transnoentitiesnoconv("IconOnlyTextOnHover"),
'4' => $langs->transnoentitiesnoconv("IconOnly"),
$langs->transnoentitiesnoconv("IconAndText"),
$langs->transnoentitiesnoconv("TextOnly"),
$langs->transnoentitiesnoconv("IconOnlyAllTextsOnHover"),
$langs->transnoentitiesnoconv("IconOnlyTextOnHover"),
$langs->transnoentitiesnoconv("IconOnly"),
);
print '<tr class="oddeven">';
print '<td>'.$langs->trans("TopMenuDisableImages").'</td>';
Expand Down Expand Up @@ -637,13 +638,10 @@ function showSkins($fuser, $edit = 0, $foruserprofile = false)
print (empty($dolibarr_main_demo) && $edit)?'':' disabled="disabled"'; // Disabled for demo
print '> '.$langs->trans("UsePersonalValue").'</td>';
print '<td>';
if ($edit)
{
if ($edit) {
print $formother->selectColor(colorArrayToHex(colorStringToArray($conf->global->THEME_ELDY_TOPMENU_BACK1,array()),''),'THEME_ELDY_TOPMENU_BACK1','',1).' ';
}
else
{
$color = colorArrayToHex(colorStringToArray($conf->global->THEME_ELDY_TOPMENU_BACK1,array()),'');
} else {
$color = colorArrayToHex(colorStringToArray($conf->global->THEME_ELDY_TOPMENU_BACK1,array()),'');
if ($color) print '<input type="text" class="colorthumb" disabled style="padding: 1px; margin-top: 0; margin-bottom: 0; background-color: #'.$color.'" value="'.$color.'">';
else print '';
}
Expand Down
6 changes: 3 additions & 3 deletions htdocs/core/modules/asset/mod_asset_standard.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2005-2010 Laurent Destailleur <[email protected]>
* Copyright (C) 2005-2009 Regis Houssin <[email protected]>
* Copyright (C) 2022 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2022-2024 Frédéric France <frederic.france@free.fr>
*
* 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
Expand Down Expand Up @@ -78,7 +78,7 @@ public function getExample()
* Checks if the numbers already in the database do not
* cause conflicts that would prevent this numbering working.
*
* @param Object $object Object we need next value for
* @param Asset $object Object we need next value for
* @return boolean false if conflict, true if ok
*/
public function canBeActivated($object)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdeweerd phan warning here

Expand Down Expand Up @@ -118,7 +118,7 @@ public function canBeActivated($object)
/**
* Return next free value
*
* @param Object $object Object we need next value for
* @param Asset $object Object we need next value for
* @return string|-1 Next value if OK, -1 if KO
*/
public function getNextValue($object)
Expand Down
4 changes: 2 additions & 2 deletions htdocs/core/modules/barcode/mod_barcode_product_standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ public function getExample($langs, $objproduct = 0)
/**
* Return literal barcode type code from numerical rowid type of barcode
*
* @param Database $db Database
* @param int $type Type of barcode (EAN, ISBN, ...) as rowid
* @param DoliDB $db Database
* @param int $type Type of barcode (EAN, ISBN, ...) as rowid
* @return string
*/
public function literalBarcodeType($db, $type = 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function getExample($langs, $objthirdparty = 0)
/**
* Return literal barcode type code from numerical rowid type of barcode
*
* @param Database $db Database
* @param DoliDB $db Database
* @param int $type Type of barcode (EAN, ISBN, ...) as rowid
* @return string
*/
Expand Down
4 changes: 2 additions & 2 deletions htdocs/core/modules/bom/mod_bom_advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright (C) 2004-2007 Laurent Destailleur <[email protected]>
* Copyright (C) 2005-2009 Regis Houssin <[email protected]>
* Copyright (C) 2008 Raphael Bertrand (Resultic) <[email protected]>
* Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2019-2024 Frédéric France <frederic.france@free.fr>
*
* 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
Expand Down Expand Up @@ -119,7 +119,7 @@ public function getExample()
* Return next free value
*
* @param Product $objprod Object product
* @param Object $object Object we need next value for
* @param Bom $object Object we need next value for
* @return string|0 Next value if OK, 0 if KO
*/
public function getNextValue($objprod, $object)
Expand Down
11 changes: 6 additions & 5 deletions htdocs/core/modules/bom/mod_bom_standard.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/* Copyright (C) 2005-2010 Laurent Destailleur <[email protected]>
* Copyright (C) 2005-2009 Regis Houssin <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
*
* 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
Expand Down Expand Up @@ -76,8 +77,8 @@ public function getExample()
* Checks if the numbers already in the database do not
* cause conflicts that would prevent this numbering working.
*
* @param Object $object Object we need next value for
* @return boolean false if conflict, true if ok
* @param Bom $object Object we need next value for
* @return boolean false if conflict, true if ok
*/
public function canBeActivated($object)
{
Expand Down Expand Up @@ -112,9 +113,9 @@ public function canBeActivated($object)
/**
* Return next free value
*
* @param Product $objprod Object product
* @param Object $object Object we need next value for
* @return string|-1 Next value if OK, -1 if KO
* @param Product $objprod Object product
* @param Bom $object Object we need next value for
* @return string|-1 Next value if OK, -1 if KO
*/
public function getNextValue($objprod, $object)
{
Expand Down
18 changes: 2 additions & 16 deletions htdocs/core/modules/cheque/mod_chequereceipt_mint.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
/* Copyright (C) 2015 Juanjo Menent <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
*
* 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
Expand Down Expand Up @@ -73,7 +74,7 @@ public function getExample()
* Checks if the numbers already in the database do not
* cause conflicts that would prevent this numbering working.
*
* @param Object $object Object we need next value for
* @param RemiseCheque $object Object we need next value for
* @return boolean false if conflict, true if ok
*/
public function canBeActivated($object)
Expand Down Expand Up @@ -150,19 +151,4 @@ public function getNextValue($objsoc, $object)
dol_syslog(__METHOD__." return ".$this->prefix.$yymm."-".$num);
return $this->prefix.$yymm."-".$num;
}


// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return next free value
*
* @param Societe $objsoc Object third party
* @param string $objforref Object for number to search
* @return string Next free value
*/
public function chequereceipt_get_num($objsoc, $objforref)
{
// phpcs:enable
return $this->getNextValue($objsoc, $objforref);
}
}
17 changes: 1 addition & 16 deletions htdocs/core/modules/cheque/mod_chequereceipt_thyme.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2015 Juanjo Menent <[email protected]>
* Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2019-2024 Frédéric France <frederic.france@free.fr>
*
* 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
Expand Down Expand Up @@ -131,19 +131,4 @@ public function getNextValue($objsoc, $object)

return $numFinal;
}


// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return next free value
*
* @param Societe $objsoc Object third party
* @param string $objforref Object for number to search
* @return string Next free value
*/
public function chequereceipt_get_num($objsoc, $objforref)
{
// phpcs:enable
return $this->getNextValue($objsoc, $objforref);
}
}
20 changes: 3 additions & 17 deletions htdocs/core/modules/commande/mod_commande_marbre.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/* Copyright (C) 2005-2010 Laurent Destailleur <[email protected]>
* Copyright (C) 2005-2009 Regis Houssin <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
*
* 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
Expand Down Expand Up @@ -88,7 +89,7 @@ public function getExample()
* Checks if the numbers already in the database do not
* cause conflicts that would prevent this numbering working.
*
* @param Object $object Object we need next value for
* @param Commande $object Object we need next value for
* @return boolean false if conflict, true if ok
*/
public function canBeActivated($object)
Expand Down Expand Up @@ -125,7 +126,7 @@ public function canBeActivated($object)
* Return next free value
*
* @param Societe $objsoc Object thirdparty
* @param Object $object Object we need next value for
* @param Commande $object Object we need next value for
* @return string|-1 Value if OK, -1 if KO
*/
public function getNextValue($objsoc, $object)
Expand Down Expand Up @@ -165,19 +166,4 @@ public function getNextValue($objsoc, $object)
dol_syslog("mod_commande_marbre::getNextValue return ".$this->prefix.$yymm."-".$num);
return $this->prefix.$yymm."-".$num;
}


// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return next free value
*
* @param Societe $objsoc Object third party
* @param string $objforref Object for number to search
* @return string|-1 Next free value, -1 if KO
*/
public function commande_get_num($objsoc, $objforref)
{
// phpcs:enable
return $this->getNextValue($objsoc, $objforref);
}
}
Loading
Loading