From 76a6d6a6fe0bd304ef8facc44a2194a2f6492873 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 28 Aug 2011 17:40:51 +0000 Subject: [PATCH] Qual: Optimize PHP Code sniffer rules --- dev/codesniffer/ruleset.xml | 8 +++++++- dev/skeletons/build_class_from_table.php | 16 ++++++++-------- dev/skeletons/modMyModule.class.php | 24 ++++++++++++++---------- dev/skeletons/skeleton_class.class.php | 2 +- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/dev/codesniffer/ruleset.xml b/dev/codesniffer/ruleset.xml index 13fa58777b9..b5b3d90d4b2 100755 --- a/dev/codesniffer/ruleset.xml +++ b/dev/codesniffer/ruleset.xml @@ -33,7 +33,7 @@ - + @@ -169,8 +169,14 @@ + + 0 + + + 0 + 0 diff --git a/dev/skeletons/build_class_from_table.php b/dev/skeletons/build_class_from_table.php index 2a35ef22401..5d3f2e143a1 100644 --- a/dev/skeletons/build_class_from_table.php +++ b/dev/skeletons/build_class_from_table.php @@ -151,7 +151,7 @@ $targetcontent=$sourcecontent; $targetcontent=preg_replace('/skeleton_class\.class\.php/', $classmin.'.class.php', $targetcontent); $targetcontent=preg_replace('/\$element=\'skeleton\'/', '\$element=\''.$classmin.'\'', $targetcontent); $targetcontent=preg_replace('/\$table_element=\'skeleton\'/', '\$table_element=\''.$classmin.'\'', $targetcontent); -$targetcontent=preg_replace('/Skeleton_class/', $classname, $targetcontent); +$targetcontent=preg_replace('/Skeleton_Class/', $classname, $targetcontent); // Substitute comments $targetcontent=preg_replace('/This file is an example to create a new class file/', 'Put here description of this class', $targetcontent); @@ -206,7 +206,7 @@ foreach($property as $key => $prop) if ($addfield) { $varprop.="\t\t\$sql.= \"".$prop['field']; - if ($i < sizeof($property)) $varprop.=","; + if ($i < count($property)) $varprop.=","; $varprop.="\";"; $varprop.="\n"; } @@ -233,7 +233,7 @@ foreach($property as $key => $prop) $varprop.='".(! isset($this->'.$prop['field'].') || dol_strlen($this->'.$prop['field'].')==0?\'NULL\':$this->db->idate('; $varprop.="\$this->".$prop['field'].""; $varprop.='))."'; - if ($i < sizeof($property)) $varprop.=","; + if ($i < count($property)) $varprop.=","; $varprop.="\";"; } elseif ($prop['ischar']) @@ -241,7 +241,7 @@ foreach($property as $key => $prop) $varprop.='".(! isset($this->'.$prop['field'].')?\'NULL\':"\'".'; $varprop.='$this->db->escape($this->'.$prop['field'].')'; $varprop.='."\'")."'; - if ($i < sizeof($property)) $varprop.=","; + if ($i < count($property)) $varprop.=","; $varprop.='";'; } else @@ -249,7 +249,7 @@ foreach($property as $key => $prop) $varprop.='".(! isset($this->'.$prop['field'].')?\'NULL\':"\'".'; $varprop.="\$this->".$prop['field'].""; $varprop.='."\'")."'; - if ($i < sizeof($property)) $varprop.=","; + if ($i < count($property)) $varprop.=","; $varprop.='";'; } $varprop.="\n"; @@ -287,7 +287,7 @@ foreach($property as $key => $prop) $varprop.=".\""; } - if ($i < sizeof($property)) $varprop.=','; + if ($i < count($property)) $varprop.=','; $varprop.='";'; $varprop.="\n"; } @@ -306,7 +306,7 @@ foreach($property as $key => $prop) { $varprop.="\t\t\$sql.= \" "; $varprop.="t.".$prop['field']; - if ($i < sizeof($property)) $varprop.=","; + if ($i < count($property)) $varprop.=","; $varprop.="\";"; $varprop.="\n"; } @@ -385,7 +385,7 @@ $targetcontent=preg_replace('/skeleton_class\.class\.php/', $classmin.'.class.ph $targetcontent=preg_replace('/skeleton_script\.php/', $classmin.'_script.php', $targetcontent); $targetcontent=preg_replace('/\$element=\'skeleton\'/', '\$element=\''.$classmin.'\'', $targetcontent); $targetcontent=preg_replace('/\$table_element=\'skeleton\'/', '\$table_element=\''.$classmin.'\'', $targetcontent); -$targetcontent=preg_replace('/Skeleton_class/', $classname, $targetcontent); +$targetcontent=preg_replace('/Skeleton_Class/', $classname, $targetcontent); // Substitute comments $targetcontent=preg_replace('/This file is an example to create a new class file/', 'Put here description of this class', $targetcontent); diff --git a/dev/skeletons/modMyModule.class.php b/dev/skeletons/modMyModule.class.php index b46ac911c19..13509c8d4c7 100644 --- a/dev/skeletons/modMyModule.class.php +++ b/dev/skeletons/modMyModule.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2009 Laurent Destailleur + * Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2005-2010 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -38,8 +38,9 @@ include_once(DOL_DOCUMENT_ROOT ."/includes/modules/DolibarrModules.class.php"); class modMyModule extends DolibarrModules { /** - * \brief Constructor. Define names, constants, directories, boxes, permissions - * \param DB Database handler + * Constructor. Define names, constants, directories, boxes, permissions + * + * @param DoliDB $DB Database handler */ function modMyModule($DB) { @@ -232,7 +233,8 @@ class modMyModule extends DolibarrModules /** * Function called when module is enabled. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. - * It also creates data directories. + * It also creates data directories + * * @return int 1 if OK, 0 if KO */ function init() @@ -247,7 +249,8 @@ class modMyModule extends DolibarrModules /** * Function called when module is disabled. * Remove from database constants, boxes and permissions from Dolibarr database. - * Data directories are not deleted. + * Data directories are not deleted + * * @return int 1 if OK, 0 if KO */ function remove() @@ -259,11 +262,12 @@ class modMyModule extends DolibarrModules /** - * \brief Create tables, keys and data required by module - * Files llx_table1.sql, llx_table1.key.sql llx_data.sql with create table, create keys - * and create data commands must be stored in directory /mymodule/sql/ - * This function is called by this->init. - * \return int <=0 if KO, >0 if OK + * Create tables, keys and data required by module + * Files llx_table1.sql, llx_table1.key.sql llx_data.sql with create table, create keys + * and create data commands must be stored in directory /mymodule/sql/ + * This function is called by this->init + * + * @return int <=0 if KO, >0 if OK */ function load_tables() { diff --git a/dev/skeletons/skeleton_class.class.php b/dev/skeletons/skeleton_class.class.php index 847b4f487cd..8bf001e0e9a 100644 --- a/dev/skeletons/skeleton_class.class.php +++ b/dev/skeletons/skeleton_class.class.php @@ -31,7 +31,7 @@ /** - * \class Skeleton_class + * \class Skeleton_Class * \brief Put here description of your class * \remarks Put here some comments */