Qual: Reduce cyclomatic complexity

This commit is contained in:
Laurent Destailleur 2011-09-20 21:07:29 +00:00
parent 4aa0898066
commit e11ca0f95a
3 changed files with 226 additions and 208 deletions

View File

@ -59,8 +59,8 @@ class Menubase
* Constructor * Constructor
* *
* @param DoliDB $DB Database handler * @param DoliDB $DB Database handler
* @param string $menu_handler * @param string $menu_handler Menu handler
* @param string $type * @param string $type Type
*/ */
function Menubase($DB,$menu_handler='',$type='') function Menubase($DB,$menu_handler='',$type='')
{ {
@ -167,9 +167,10 @@ class Menubase
} }
/** /**
* Update menu entry into database * Update menu entry into database.
* @param user User that modify *
* @param notrigger 0=no, 1=yes (no update trigger) * @param User $user User that modify
* @param int $notrigger 0=no, 1=yes (no update trigger)
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function update($user=0, $notrigger=0) function update($user=0, $notrigger=0)
@ -302,10 +303,11 @@ class Menubase
} }
/* /**
* \brief Delete object in database * Delete object in database
* \param user User that delete *
* \return int <0 if KO, >0 if OK * @param User $user User that delete
* @return int <0 if KO, >0 if OK
*/ */
function delete($user) function delete($user)
{ {
@ -360,10 +362,11 @@ class Menubase
/** /**
* Complete this->newmenu with menu entry found in $tab * Complete this->newmenu with menu entry found in $tab
* *
* @param $tab * @param array $tab Tab array
* @param $pere * @param int $pere Id of parent
* @param $rang * @param int $rang Rang
* @param $myleftmenu Value for left that defined leftmenu * @param string $myleftmenu Value for left that defined leftmenu
* @return void
*/ */
function recur($tab, $pere, $rang, $myleftmenu) function recur($tab, $pere, $rang, $myleftmenu)
{ {
@ -401,10 +404,12 @@ class Menubase
/** /**
* Load tabMenu array * Load tabMenu array
* @param type_user 0=Internal,1=External,2=All *
* @param mainmenu Value for mainmenu that defined top menu * @param string $mainmenu Value for mainmenu that defined top menu
* @param menu_handler Name of menu_handler used (auguria, eldy...) * @param string $myleftmenu Left menu name
* @param tabMenu If array with menu entries already loaded, we put this array here (in most cases, it's empty) * @param int $type_user 0=Internal,1=External,2=All
* @param string $menu_handler Name of menu_handler used (auguria, eldy...)
* @param array &$tabMenu If array with menu entries already loaded, we put this array here (in most cases, it's empty)
* @return array Return array with menu entries for top menu * @return array Return array with menu entries for top menu
*/ */
function menuTopCharger($mainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu=null) function menuTopCharger($mainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu=null)
@ -449,13 +454,14 @@ class Menubase
} }
/** /**
* Load entries found in database in a menu array * Load entries found in database in a menu array.
* @param $newmenu Menu array to complete *
* @param $mainmenu Value for mainmenu that defined top menu of left menu * @param array $newmenu Menu array to complete
* @param $myleftmenu Value that defined leftmenu * @param string $mainmenu Value for mainmenu that defined top menu of left menu
* @param $type_user 0=Internal,1=External,2=All * @param string $myleftmenu Value that defined leftmenu
* @param $menu_handler Name of menu_handler used (auguria, eldy...) * @param int $type_user 0=Internal,1=External,2=All
* @param $tabMenu If array with menu entries already loaded, we put this array here (in most cases, it's empty) * @param string $menu_handler Name of menu_handler used (auguria, eldy...)
* @param array &$tabMenu If array with menu entries already loaded, we put this array here (in most cases, it's empty)
* @return array Menu array for particular mainmenu value or full tabArray * @return array Menu array for particular mainmenu value or full tabArray
*/ */
function menuLeftCharger($newmenu, $mainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu=null) function menuLeftCharger($newmenu, $mainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu=null)
@ -496,11 +502,12 @@ class Menubase
/** /**
* Load entries found in database in a menu array * Load entries found in database in a menu array.
* @param $myleftmenu Value for left that defined leftmenu *
* @param $type_user 0=Internal,1=External,2=All * @param string $myleftmenu Value for left that defined leftmenu
* @param $menu_handler Name of menu_handler used (auguria, eldy...) * @param int $type_user 0=Internal,1=External,2=All
* @param $tabMenu If array with menu entries already load, we put this array here (in most cases, it's empty) * @param string $menu_handler Name of menu_handler used (auguria, eldy...)
* @param array &$tabMenu If array with menu entries already load, we put this array here (in most cases, it's empty)
* @return int >0 if OK, <0 if KO * @return int >0 if OK, <0 if KO
*/ */
function menuLoad($myleftmenu, $type_user, $menu_handler, &$tabMenu=array()) function menuLoad($myleftmenu, $type_user, $menu_handler, &$tabMenu=array())

View File

@ -73,14 +73,14 @@ class Import
$dir = $dirroot.'/includes/modules'; $dir = $dirroot.'/includes/modules';
// Search available exports // Search available exports
$handle=@opendir($dir); $handle=@opendir(dol_osencode($dir));
if (is_resource($handle)) if (! is_resource($handle)) continue;
{
// Search module files // Search module files
while (($file = readdir($handle))!==false) while (($file = readdir($handle))!==false)
{ {
if (preg_match("/^(mod.*)\.class\.php/i",$file,$reg)) if (! preg_match("/^(mod.*)\.class\.php/i",$file,$reg)) continue;
{
$modulename=$reg[1]; $modulename=$reg[1];
// Defined if module is enabled // Defined if module is enabled
@ -88,9 +88,9 @@ class Import
$part=strtolower(preg_replace('/^mod/i','',$modulename)); $part=strtolower(preg_replace('/^mod/i','',$modulename));
if (empty($conf->$part->enabled)) $enabled=false; if (empty($conf->$part->enabled)) $enabled=false;
if ($enabled) if (empty($enabled)) continue;
{
// Chargement de la classe // Init load class
$file = $dir."/".$modulename.".class.php"; $file = $dir."/".$modulename.".class.php";
$classname = $modulename; $classname = $modulename;
require_once($file); require_once($file);
@ -117,10 +117,7 @@ class Import
//print $bool." $perm[0]"."<br>"; //print $bool." $perm[0]"."<br>";
*/ */
// Permissions ok // Load lang file
// if ($bool)
// {
// Charge fichier lang en rapport
$langtoload=$module->getLangFilesArray(); $langtoload=$module->getLangFilesArray();
if (is_array($langtoload)) if (is_array($langtoload))
{ {
@ -157,15 +154,11 @@ class Import
dol_syslog("Import loaded for module ".$modulename." with index ".$i.", dataset=".$module->import_code[$r].", nb of fields=".count($module->import_fields_code[$r])); dol_syslog("Import loaded for module ".$modulename." with index ".$i.", dataset=".$module->import_code[$r].", nb of fields=".count($module->import_fields_code[$r]));
$i++; $i++;
// }
}
}
}
}
} }
} }
} }
closedir($handle); closedir($handle);
}
return 1; return 1;
} }

View File

@ -116,10 +116,10 @@ class User extends CommonObject
/** /**
* Load a user from database with its id or ref (login) * Load a user from database with its id or ref (login)
* *
* @param id Si defini, id a utiliser pour recherche * @param int $id Si defini, id a utiliser pour recherche
* @param login Si defini, login a utiliser pour recherche * @param string $login Si defini, login a utiliser pour recherche
* @param sid Si defini, sid a utiliser pour recherche * @param strinf $sid Si defini, sid a utiliser pour recherche
* @param $loadpersonalconf Also load personal conf of user (in $user->conf->xxx) * @param int $loadpersonalconf Also load personal conf of user (in $user->conf->xxx)
* @return int <0 if KO, 0 not found, >0 if OK * @return int <0 if KO, 0 not found, >0 if OK
*/ */
function fetch($id='', $login='',$sid='',$loadpersonalconf=1) function fetch($id='', $login='',$sid='',$loadpersonalconf=1)
@ -269,9 +269,9 @@ class User extends CommonObject
/** /**
* Ajoute un droit a l'utilisateur * Ajoute un droit a l'utilisateur
* *
* @param rid id du droit a ajouter * @param int $rid id du droit a ajouter
* @param allmodule Ajouter tous les droits du module allmodule * @param string $allmodule Ajouter tous les droits du module allmodule
* @param allperms Ajouter tous les droits du module allmodule, perms allperms * @param string $allperms Ajouter tous les droits du module allmodule, perms allperms
* @return int > 0 si ok, < 0 si erreur * @return int > 0 si ok, < 0 si erreur
*/ */
function addrights($rid,$allmodule='',$allperms='') function addrights($rid,$allmodule='',$allperms='')
@ -368,9 +368,9 @@ class User extends CommonObject
/** /**
* Retire un droit a l'utilisateur * Retire un droit a l'utilisateur
* *
* @param rid id du droit a retirer * @param int $rid Id du droit a retirer
* @param allmodule Retirer tous les droits du module allmodule * @param string $allmodule Retirer tous les droits du module allmodule
* @param allperms Retirer tous les droits du module allmodule, perms allperms * @param string $allperms Retirer tous les droits du module allmodule, perms allperms
* @return int > 0 si ok, < 0 si erreur * @return int > 0 si ok, < 0 si erreur
*/ */
function delrights($rid,$allmodule='',$allperms='') function delrights($rid,$allmodule='',$allperms='')
@ -463,6 +463,8 @@ class User extends CommonObject
/** /**
* Clear all permissions array of user * Clear all permissions array of user
*
* @return void
*/ */
function clearrights() function clearrights()
{ {
@ -476,7 +478,8 @@ class User extends CommonObject
/** /**
* Load permissions granted to user into object user * Load permissions granted to user into object user
* *
* @param moduletag Limit permission for a particular module ('' by default means load all permissions) * @param string $moduletag Limit permission for a particular module ('' by default means load all permissions)
* @return void
*/ */
function getrights($moduletag='') function getrights($moduletag='')
{ {
@ -599,6 +602,7 @@ class User extends CommonObject
/** /**
* Change status of a user * Change status of a user
* *
* @param int $statut Status to set
* @return int <0 if KO, 0 if nothing is done, >0 if OK * @return int <0 if KO, 0 if nothing is done, >0 if OK
*/ */
function setstatus($statut) function setstatus($statut)
@ -706,8 +710,8 @@ class User extends CommonObject
/** /**
* Create a user into database * Create a user into database
* *
* @param user Objet user qui demande la creation * @param User $user Objet user qui demande la creation
* @param notrigger 1 ne declenche pas les triggers, 0 sinon * @param int $notrigger 1 ne declenche pas les triggers, 0 sinon
* @return int <0 si KO, id compte cree si OK * @return int <0 si KO, id compte cree si OK
*/ */
function create($user,$notrigger=0) function create($user,$notrigger=0)
@ -834,9 +838,9 @@ class User extends CommonObject
/** /**
* Create a user from a contact object. User will be internal but if contact is linked to a third party, user will be external * Create a user from a contact object. User will be internal but if contact is linked to a third party, user will be external
* *
* @param contact Object for source contact * @param Contact $contact Object for source contact
* @param login Login to force * @param string $login Login to force
* @param password Password to force * @param string $password Password to force
* @return int <0 if error, if OK returns id of created user * @return int <0 if error, if OK returns id of created user
*/ */
function create_from_contact($contact,$login='',$password='') function create_from_contact($contact,$login='',$password='')
@ -902,8 +906,8 @@ class User extends CommonObject
/** /**
* Create a user into database from a member object * Create a user into database from a member object
* *
* @param member Object member source * @param Adherent $member Object member source
* @param login Login to force * @param string $login Login to force
* @return int <0 if KO, if OK, return id of created account * @return int <0 if KO, if OK, return id of created account
*/ */
function create_from_member($member,$login='') function create_from_member($member,$login='')
@ -1005,10 +1009,10 @@ class User extends CommonObject
/** /**
* Update a user into databse (and also password if this->pass is defined) * Update a user into databse (and also password if this->pass is defined)
* *
* @param user User qui fait la mise a jour * @param User $user User qui fait la mise a jour
* @param notrigger 1 ne declenche pas les triggers, 0 sinon * @param int $notrigger 1 ne declenche pas les triggers, 0 sinon
* @param nosyncmember 0=Synchronize linked member (standard info), 1=Do not synchronize linked member * @param int $nosyncmember 0=Synchronize linked member (standard info), 1=Do not synchronize linked member
* @param nosyncmemberpass 0=Synchronize linked member (password), 1=Do not synchronize linked member * @param int $nosyncmemberpass 0=Synchronize linked member (password), 1=Do not synchronize linked member
* @return int <0 si KO, >=0 si OK * @return int <0 si KO, >=0 si OK
*/ */
function update($user,$notrigger=0,$nosyncmember=0,$nosyncmemberpass=0) function update($user,$notrigger=0,$nosyncmember=0,$nosyncmemberpass=0)
@ -1198,7 +1202,7 @@ class User extends CommonObject
$sql.= " tms = tms"; // La date de derniere modif doit changer sauf pour la mise a jour de date de derniere connexion $sql.= " tms = tms"; // La date de derniere modif doit changer sauf pour la mise a jour de date de derniere connexion
$sql.= " WHERE rowid = ".$this->id; $sql.= " WHERE rowid = ".$this->id;
dol_syslog ("Update last login date for user->id=".$this->id." ".$sql, LOG_DEBUG); dol_syslog("Update last login date for user->id=".$this->id." ".$sql, LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -1217,11 +1221,11 @@ class User extends CommonObject
/** /**
* Change password of a user * Change password of a user
* *
* @param user Object user of user making change * @param User $user Object user of user making change
* @param password New password in clear text (to generate if not provided) * @param string $password New password in clear text (to generate if not provided)
* @param changelater 1=Change password only after clicking on confirm email * @param int $changelater 1=Change password only after clicking on confirm email
* @param notrigger 1=Does not launch triggers * @param int $notrigger 1=Does not launch triggers
* @param nosyncmember Do not synchronize linked member * @param int $nosyncmember Do not synchronize linked member
* @return string If OK return clear password, 0 if no change, < 0 if error * @return string If OK return clear password, 0 if no change, < 0 if error
*/ */
function setPassword($user, $password='', $changelater=0, $notrigger=0, $nosyncmember=0) function setPassword($user, $password='', $changelater=0, $notrigger=0, $nosyncmember=0)
@ -1346,9 +1350,9 @@ class User extends CommonObject
/** /**
* Envoie mot de passe par mail * Envoie mot de passe par mail
* *
* @param user Object user de l'utilisateur qui fait l'envoi * @param User $user Object user de l'utilisateur qui fait l'envoi
* @param password Nouveau mot de passe * @param string $password Nouveau mot de passe
* @param changelater 1=Change password only after clicking on confirm email * @param int $changelater 1=Change password only after clicking on confirm email
* @return int < 0 si erreur, > 0 si ok * @return int < 0 si erreur, > 0 si ok
*/ */
function send_password($user, $password='', $changelater=0) function send_password($user, $password='', $changelater=0)
@ -1411,8 +1415,19 @@ class User extends CommonObject
$mesg.= "If you didn't ask anything, just forget this email\n\n"; $mesg.= "If you didn't ask anything, just forget this email\n\n";
dol_syslog("User::send_password url=".$url); dol_syslog("User::send_password url=".$url);
} }
$mailfile = new CMailFile($subject,$this->email,$conf->notification->email_from,$mesg, $mailfile = new CMailFile(
array(),array(),array(),'', '', 0, $msgishtml); $subject,
$this->email,
$conf->notification->email_from,
$mesg,
array(),
array(),
array(),
'',
'',
0,
$msgishtml
);
if ($mailfile->sendfile()) if ($mailfile->sendfile())
{ {
@ -1474,6 +1489,8 @@ class User extends CommonObject
/** /**
* Update clicktodial info * Update clicktodial info
*
* @return void
*/ */
function update_clicktodial() function update_clicktodial()
{ {
@ -1510,9 +1527,9 @@ class User extends CommonObject
/** /**
* Add user into a group * Add user into a group
* *
* @param group Id of group * @param Group $group Id of group
* @param entity Entity * @param int $entity Entity
* @param notrigger Disable triggers * @param int $notrigger Disable triggers
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function SetInGroup($group, $entity, $notrigger=0) function SetInGroup($group, $entity, $notrigger=0)
@ -1571,9 +1588,9 @@ class User extends CommonObject
/** /**
* Remove a user from a group * Remove a user from a group
* *
* @param group Id of group * @param Group $group Id of group
* @param entity Entity * @param int $entity Entity
* @param notrigger Disable triggers * @param int $notrigger Disable triggers
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function RemoveFromGroup($group, $entity, $notrigger=0) function RemoveFromGroup($group, $entity, $notrigger=0)
@ -1628,8 +1645,8 @@ class User extends CommonObject
* Return a link to the user card (with optionnaly the picto) * Return a link to the user card (with optionnaly the picto)
* Use this->id,this->nom, this->prenom * Use this->id,this->nom, this->prenom
* *
* @param withpicto Include picto in link (0=No picto, 1=Inclut le picto dans le lien, 2=Picto seul) * @param int $withpicto Include picto in link (0=No picto, 1=Inclut le picto dans le lien, 2=Picto seul)
* @param option On what the link point to * @param string $option On what the link point to
* @return string String with URL * @return string String with URL
*/ */
function getNomUrl($withpicto=0,$option='') function getNomUrl($withpicto=0,$option='')
@ -1656,8 +1673,8 @@ class User extends CommonObject
/** /**
* Renvoie login clicable (avec eventuellement le picto) * Renvoie login clicable (avec eventuellement le picto)
* *
* @param withpicto Inclut le picto dans le lien * @param int $withpicto Inclut le picto dans le lien
* @param option Sur quoi pointe le lien * @param string $option Sur quoi pointe le lien
* @return string Chaine avec URL * @return string Chaine avec URL
*/ */
function getLoginUrl($withpicto=0,$option='') function getLoginUrl($withpicto=0,$option='')
@ -1683,9 +1700,9 @@ class User extends CommonObject
/** /**
* Return full name (civility+' '+name+' '+lastname) * Return full name (civility+' '+name+' '+lastname)
* *
* @param langs Language object for translation of civility * @param Translate $langs Language object for translation of civility
* @param option 0=No option, 1=Add civility * @param int $option 0=No option, 1=Add civility
* @param nameorder -1=Auto, 0=Lastname+Firstname, 1=Firstname+Lastname * @param int $nameorder -1=Auto, 0=Lastname+Firstname, 1=Firstname+Lastname
* @return string String with full name * @return string String with full name
*/ */
function getFullName($langs,$option=0,$nameorder=-1) function getFullName($langs,$option=0,$nameorder=-1)
@ -1722,7 +1739,7 @@ class User extends CommonObject
/** /**
* Retourne le libelle du statut d'un user (actif, inactif) * Retourne le libelle du statut d'un user (actif, inactif)
* *
* @param mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long
* @return string Label of status * @return string Label of status
*/ */
function getLibStatut($mode=0) function getLibStatut($mode=0)
@ -1733,8 +1750,8 @@ class User extends CommonObject
/** /**
* Renvoi le libelle d'un statut donne * Renvoi le libelle d'un statut donne
* *
* @param statut Id statut * @param int $statut Id statut
* @param mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
* @return string Label of status * @return string Label of status
*/ */
function LibStatut($statut,$mode=0) function LibStatut($statut,$mode=0)
@ -1779,8 +1796,8 @@ class User extends CommonObject
/** /**
* Retourne chaine DN complete dans l'annuaire LDAP pour l'objet * Retourne chaine DN complete dans l'annuaire LDAP pour l'objet
* *
* @param info Info string loaded by _load_ldap_info * @param string $info Info string loaded by _load_ldap_info
* @param mode 0=Return full DN (uid=qqq,ou=xxx,dc=aaa,dc=bbb) * @param int $mode 0=Return full DN (uid=qqq,ou=xxx,dc=aaa,dc=bbb)
* 1= * 1=
* 2=Return key only (uid=qqq) * 2=Return key only (uid=qqq)
* @return string DN * @return string DN
@ -1907,7 +1924,8 @@ class User extends CommonObject
/** /**
* Load info of user object * Load info of user object
* *
* @param id id of user to load * @param int $id Id of user to load
* @return void
*/ */
function info($id) function info($id)
{ {
@ -1971,7 +1989,7 @@ class User extends CommonObject
/** /**
* Return number of existing users * Return number of existing users
* *
* @param limitTo limit to 'active' or 'superadmin' users * @param string $limitTo Limit to 'active' or 'superadmin' users
* @return int Number of users * @return int Number of users
*/ */
function getNbOfUsers($limitTo='') function getNbOfUsers($limitTo='')