Fix: Codesniffer

This commit is contained in:
Laurent Destailleur 2013-04-10 12:20:45 +02:00
parent bc1469ff29
commit ba93a4bfe2
21 changed files with 45 additions and 394 deletions

View File

@ -1,21 +0,0 @@
README (English)
--------------------------------
This directory contains example of PHPCheckStyle configuration
to use for quality assurance on PHP developpement.
To run PHPCheckstyle in eclipse, you must:
- install plugin PHP Tools integration http://www.phpsrc.org/eclipse/pti/
- Unzip PHPCheckStyle archive into a directory.
- Go in Eclipse - Window - Preferences - Dynamic Languages - Validator
Choose External PHP Script,
Set path ro run.php file for localhost
Choose a PHP version,
Set parameter string with
--src %f --config "phpstandard.cfg.xml" --format console
Choose php as Filename extension
Check Print PHP output to console
Then add patern
* %f INFO Line:%n - %m Warning
* %f WARNING Line:%n - %m Warning
* %f ERROR Line:%n - %m Error

View File

@ -1,316 +0,0 @@
<?xml version="1.0"?>
<!DOCTYPE phpstandard SYSTEM "phpstandard.dtd">
<!-- somewhat inspired by java checkstyle -->
<phpcheckstyle-configuration>
<!-- **************** -->
<!-- Naming -->
<!-- **************** -->
<!-- Check Constant Naming -->
<!-- Disabled to avoid warning with $sql="SELECT ..."
<test name="constantNaming" regexp="/^[A-Z_][A-Z_]*[A-Z_]$/" level="ERROR"/>
-->
<!-- Check Variable Naming -->
<test name="variableNaming" regexp="/^[a-zA-Z_][a-zA-Z0-9_]*$/" />
<!-- Check Function Naming -->
<test name="functionNaming" regexp="/^[a-z_]/" level="WARNING"/>
<!-- Check Private Function Naming -->
<test name="privateFunctionNaming" regexp="/^[a-z_]/" level="ERROR"/>
<!-- Checks the constuctor naming -->
<!-- old = old style (constructor = name of the class) -->
<!-- new = "__construct()" -->
<test name="constructorNaming">
<property name="naming" value="old"/>
</test>
<!-- Check Class Naming -->
<test name="classNaming" regexp="/^[A-Z]/" level="WARNING"/>
<!-- **************** -->
<!-- PHP Tags -->
<!-- **************** -->
<!-- Test if a short php code open tag is used (? instead of ?php ). -->
<test name="noShortPhpCodeTag"/>
<!-- Test if a PHP closing file is present at the end of a file -->
<!-- <test name="noFileCloseTag"/> -->
<!-- Test if a file finish with some inner HTML (OK for some view but could provoque "header already sent" error) -->
<!-- <test name="noFileFinishHTML" level="ERROR" /> -->
<!-- **************** -->
<!-- Comments -->
<!-- **************** -->
<!-- Check if some C style comments are used (#) -->
<test name="noShellComments"/>
<!-- Tests that every function and class is immediately preceded by a docblock. A property "excludePrivateMembers" can be set if you want to disable docblocks for private member functions. -->
<test name="docBlocks">
<property name="excludePrivateMembers" value="true"/>
<property name="testReturn" value="true"/>
<property name="testParam" value="true"/>
<property name="testThrow" value="true"/>
</test>
<!-- **************** -->
<!-- Indentation -->
<!-- **************** -->
<!-- Tests to make sure that a line does not contain the tab character. -->
<!-- <test name="noTabs"/> -->
<!-- Test to make sure that every control structure is included within a {} block, even if it is syntactically optional. -->
<!-- <test name="controlStructNeedCurly"/> -->
<!-- Check the position of the open curly brace in a control structure (if) -->
<!-- sl = same line -->
<!-- nl = new line -->
<test name="controlStructOpenCurly">
<property name="position" value="nl"/>
</test>
<!-- Check the position of the close curly brace -->
<test name="controlCloseCurly" level="INFO">
</test>
<!-- Check the position of the open curly brace after a function -->
<!-- sl = same line -->
<!-- nl = new line -->
<test name="funcDefinitionOpenCurly">
<property name="position" value="nl"/>
</test>
<!-- Check the position of the else -->
<!-- sl = same line -->
<!-- nl = new line -->
<test name="controlStructElse">
<property name="position" value="nl"/>
</test>
<!-- **************** -->
<!-- Spaces -->
<!-- **************** -->
<!-- Tests that the control statements ("if", "else", "while", "for", etc.)
are followed by a space before the opening parenthesis.
PEAR standard stipulates this to distinguish it from function calls.
-->
<!--
<test name="spaceAfterControlStmt"/>
-->
<!-- Check that there is no space after a function name in a function call -->
<!-- <test name="noSpaceAfterFunctionName" level="INFO"></test> -->
<!-- Check for the (required) presence of a white space after some tokens (like ,) -->
<!--
<test name="checkWhiteSpaceAfter">
<exception value="."/>
</test>
-->
<!-- Check for the (required) presence of a white space before some tokens -->
<!--
<test name="checkWhiteSpaceBefore">
<exception value="."/>
<exception value=":"/>
</test>
-->
<!-- Check that there is no space before before some tokens -->
<!--
<test name="noSpaceBeforeToken" level="INFO">
</test>
-->
<!-- Check that there is no space after some tokens -->
<!--
<test name="noSpaceAfterToken" level="INFO">
</test>
-->
<!-- **************** -->
<!-- Metrics -->
<!-- **************** -->
<!-- Check that the lenght of the line doesn't pass the max value -->
<test name="lineLength" level="INFO">
<property name="maxLineLength" value="160"/>
</test>
<!-- Checks that the lenght (in lines) of a function doesn't pass the max value -->
<test name="functionLength" level="INFO">
<property name="maxLength" value="500"/>
</test>
<!-- Checks for excessive parameters in a function declaration -->
<!-- <test name="functionMaxParameters">
<property name="maxParameters" value="4"/>
</test> -->
<!-- Check Cyclomatic Complexity -->
<!-- see http://www.aivosto.com/project/help/pm-complexity.html -->
<test name="cyclomaticComplexity">
<!-- Level raising a warning -->
<property name="warningLevel" value="10"/>
<!-- Level raising an error -->
<property name="errorLevel" value="20"/>
</test>
<!-- **************** -->
<!-- Other -->
<!-- **************** -->
<!-- All arguments with default values should be at the end -->
<test name="defaultValuesOrder"/>
<!-- Check for prohibited functions -->
<!-- @see http://www.php.net/manual/en/indexes.php -->
<test name="checkProhibitedFunctions">
<item value="echo"/>
<item value="system"/>
<item value="print_r"/>
<item value="var_dump"/>
<item value="dl"/>
<!--<item value="exec"/>-->
<item value="passthru"/>
<!-- <item value="delete"/> We disable because of false report when using method delete -->
<item value="ereg_replace"/>
<item value="ereg"/>
<item value="eregi"/>
<!-- <item value="copy"/> -->
<!-- <item value="fwrite"/> -->
</test>
<!-- Check for prohibited tokens -->
<!-- @see http://www.php.net/manual/en/tokens.php -->
<test name="checkProhibitedTokens">
<item value="T_BAD_CHARACTER"/>
<item value="T_DECLARE"/>
<item value="T_ENDDECLARE"/>
<item value="T_ENDFOR"/>
<item value="T_ENDFOREACH"/>
<item value="T_ENDIF"/>
<item value="T_ENDSWITCH"/>
<item value="T_ENDWHILE"/>
<item value="T_HALT_COMPILER"/>
<item value="T_OLD_FUNCTION"/>
<!-- <item value="T_PRINT"/> -->
<!-- Same thing as the noShortPhpCodeTag rule -->
<!-- <item value="T_OPEN_TAG_WITH_ECHO"/> -->
<!-- <item value="T_INLINE_HTML"/> -->
<!-- <item value="T_ECHO"/> -->
</test>
<!-- Check for silenced errors before function calls (@function) -->
<test name="checkSilencedError">
<exception value="rename"/> <!-- Exceptions to this rule -->
<exception value="mkdir"/>
<exception value="chmod"/>
</test>
<!-- Check for encapsed variables inside a String ("$a") -->
<test name="encapsedVariablesInsideString">
</test>
<!-- Avoid passing parameters by reference -->
<test name="avoidPassingReferences">
</test>
<test name="showTODOs">
</test>
<!-- Use boolean operators (&&) instead of logical operators (AND) -->
<test name="useBooleanOperators">
</test>
<!-- Check empty block like if ($a) {} -->
<test name="checkEmptyBlock">
<!-- <exception value="catch"/> -->
</test>
<!-- Check empty statement ( ;; ) -->
<test name="checkEmptyStatement">
</test>
<!-- Check for the presence of heredoc -->
<test name="checkHeredoc">
</test>
<!-- Check for braces around code blocs (if, else, elseif, do, while, for, foreach) -->
<!--
<test name="needBraces">
</test>
-->
<!-- Switch need a default value -->
<test name="switchNeedDefault">
</test>
<!-- Switch case should have a break -->
<!-- <test name="switchCaseNeedBreak">
</test> -->
<!-- Switch default value should be at the end -->
<test name="switchDefaultOrder">
</test>
<!--
Avoid using unary operators (++) inside a control statement
With the exception of for iterators, all variable incrementation or decrementation should occur in their own toplevel statement to increase readability.
-->
<test name="checkUnaryOperator">
<exception value="for"/>
</test>
<!--
With inner assignments it is difficult to see all places where a variable is set.
With the exception of for iterators, all assignments should occur in their own toplevel statement to increase readability.
-->
<test name="checkInnerAssignment">
<exception value="for"/>
</test>
<!-- Detect unused private functions (detecting unused public ones is more difficult) -->
<test name="checkUnusedPrivateFunctions">
</test>
<!-- Detect unused variables -->
<test name="checkUnusedVariables">
</test>
<!-- Detect unused function parameters -->
<test name="checkUnusedFunctionParameters">
</test>
<!-- Only one class declaration per PHP file -->
<test name="oneClassPerFile">
</test>
<!-- ******************* -->
<!-- Optimisation -->
<!-- ******************* -->
<!-- Only one class declaration per PHP file -->
<test name="functionInsideLoop">
</test>
</phpcheckstyle-configuration>

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT phpcheckstyle-configuration (test+)>
<!ELEMENT test (property*,item*,exception*)>
<!ATTLIST test name CDATA "">
<!ATTLIST test regexp CDATA "">
<!ATTLIST test level CDATA "">
<!ELEMENT property (#PCDATA)>
<!ATTLIST property value CDATA "">
<!ATTLIST property name CDATA "">
<!ELEMENT item (#PCDATA)>
<!ATTLIST item value CDATA "">
<!ELEMENT exception (#PCDATA)>
<!ATTLIST exception value CDATA "">

View File

@ -2783,7 +2783,6 @@ class Commande extends CommonOrder
* Update value of extrafields on the proposal
*
* @param User $user Object user that modify
* @param double $remise Amount discount
* @return int <0 if ko, >0 if ok
*/
function update_extrafields($user)

View File

@ -175,11 +175,10 @@ class mailing_thirdparties_services_expired extends MailingTargets
* For example if this selector is used to extract 500 different
* emails from a text file, this function must return 500.
*
* @param int $filter Filter
* @param string $option Option
* @param string $sql Request
* @return int Number of recipients
*/
function getNbOfRecipients($sql,$filter=1,$option='')
function getNbOfRecipients($sql='')
{
$now=dol_now();

View File

@ -146,6 +146,7 @@ class ProductFournisseur extends Product
* @param string $charges costs affering to product
* @param float $remise_percent Discount regarding qty (percent)
* @param float $remise Discount regarding qty (amount)
* @param int $newnpr Set NPR or not
* @return int <0 if KO, >=0 if OK
*/
function update_buyprice($qty, $buyprice, $user, $price_base_type, $fourn, $availability, $ref_fourn, $tva_tx, $charges=0, $remise_percent=0, $remise=0, $newnpr=0)

View File

@ -202,7 +202,7 @@ if (isset($_POST["ajoutercolonne"]) && ($object->format == "D" || $object->forma
//on rajoute la valeur dans les valeurs
$datesbase = explode(",",$object->sujet);
$taillebase = sizeof($datesbase);
$taillebase = count($datesbase);
//recherche de l'endroit de l'insertion de la nouvelle date dans les dates deja entrées dans le tableau
if ($nouvelledate < $datesbase[0]) {
@ -210,7 +210,9 @@ if (isset($_POST["ajoutercolonne"]) && ($object->format == "D" || $object->forma
} elseif ($nouvelledate > $datesbase[$taillebase-1]) {
$cleinsertion = count($datesbase);
} else {
for ($i = 0; $i < count($datesbase); $i++) {
$nbdatesbase=count($datesbase);
for ($i = 0; $i < $nbdatesbase; $i++)
{
$j = $i + 1;
if ($nouvelledate > $datesbase[$i] && $nouvelledate < $datesbase[$j]) {
$cleinsertion = $j;

View File

@ -340,7 +340,7 @@ class Opensurveysondage extends CommonObject
* @param string $numsondageadmin Num sondage to delete
* @return int <0 if KO, >0 if OK
*/
function delete($user, $notrigger=0, $numsondageadmin)
function delete($user, $notrigger, $numsondageadmin)
{
global $conf, $langs;
$error=0;

View File

@ -120,8 +120,8 @@ function get_server_name()
/**
* is_error
*
* @param unknown_type $cerr
* @return boolean
* @param string $cerr Error value
* @return boolean Error key found or not
*/
function is_error($cerr)
{
@ -147,7 +147,7 @@ function validateEmail($email)
{
$pattern = '/^(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){255,})(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){65,}@)(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22))(?:\\.(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\\]))$/iD';
return (bool)preg_match($pattern, $email);
return (bool) preg_match($pattern, $email);
}
@ -188,15 +188,16 @@ function getUrlSondage($id, $admin = false)
/**
* Generate a random id
*
* @return void
* Generate a random id
*
* @param string $car Char to generate key
* @return void
*/
function dol_survey_random($car)
{
$string = "";
$chaine = "abcdefghijklmnopqrstuvwxyz123456789";
srand((double)microtime()*1000000);
srand((double) microtime()*1000000);
for($i=0; $i<$car; $i++) {
$string .= $chaine[rand()%strlen($chaine)];
}
@ -229,7 +230,7 @@ function ajouter_sondage($origin)
if ($_SESSION["formatsondage"]=="D"||$_SESSION["formatsondage"]=="D+") {
//Calcul de la date de fin du sondage
$taille_tableau=sizeof($_SESSION["totalchoixjour"])-1;
$taille_tableau=count($_SESSION["totalchoixjour"])-1;
$date_fin=$_SESSION["totalchoixjour"][$taille_tableau]+200000;
}

View File

@ -257,9 +257,9 @@ if (issetAndNoEmpty('choixjourajout')) {
// Si le test est passé, alors on insere la valeur dans la variable de session qui contient les dates
if ($journeuf && issetAndNoEmpty('choixjourajout') === true) {
array_push ($_SESSION["totalchoixjour"],mktime (0,0,0, $_SESSION["mois"], $_POST["choixjourajout"][0], $_SESSION["annee"]));
sort ($_SESSION["totalchoixjour"]);
$cle=array_search (mktime (0,0,0, $_SESSION["mois"], $_POST["choixjourajout"][0], $_SESSION["annee"]), $_SESSION["totalchoixjour"]);
array_push($_SESSION["totalchoixjour"], dol_mktime(0, 0, 0, $_SESSION["mois"], $_POST["choixjourajout"][0], $_SESSION["annee"]));
sort($_SESSION["totalchoixjour"]);
$cle=array_search(dol_mktime(0, 0, 0, $_SESSION["mois"], $_POST["choixjourajout"][0], $_SESSION["annee"]), $_SESSION["totalchoixjour"]);
//On sauvegarde les heures deja entrées
for ($i = 0; $i < $cle; $i++) {
@ -540,7 +540,7 @@ if (issetAndNoEmpty('totalchoixjour', $_SESSION) && (!issetAndNoEmpty('choixheur
//s'il n'y a pas d'erreur et que le bouton de creation est activé, on demande confirmation
if (!$erreur && (GETPOST('choixheures') || GETPOST('choixheures_x'))) {
$taille_tableau=sizeof($_SESSION["totalchoixjour"])-1;
$taille_tableau=count($_SESSION["totalchoixjour"])-1;
$jour_arret = $_SESSION["totalchoixjour"][$taille_tableau]+200000;
$date_fin=dol_print_date($jour_arret, 'dayhourtext');

View File

@ -162,7 +162,7 @@ print '</script>'."\n";
print '<br>'."\n";
#affichage du cochage par défaut
// Check or not
$cocheplus='';
if ($_SESSION["canedit"]) $cocheplus="checked";

View File

@ -64,7 +64,6 @@ $now=dol_now();
$nbcolonnes=substr_count($object->sujet,',')+1;
$toutsujet=explode(",",$object->sujet);
#$toutsujet=str_replace("°","'",$toutsujet);
// affichage des sujets du sondage
$input.=$langs->trans("Name").";";
@ -139,15 +138,15 @@ if ($resql)
else dol_print_error($db);
$filesize = strlen( $input );
$filesize = strlen($input);
$filename=$numsondage."_".dol_print_date($now,'%Y%m%d%H%M').".csv";
header( 'Content-Type: text/csv; charset=utf-8' );
header( 'Content-Length: '.$filesize );
header( 'Content-Disposition: attachment; filename="'.$filename.'"' );
header( 'Cache-Control: max-age=10' );
header('Content-Type: text/csv; charset=utf-8');
header('Content-Length: '.$filesize);
header('Content-Disposition: attachment; filename="'.$filename.'"');
header('Cache-Control: max-age=10');
echo $input;
exit;

View File

@ -69,13 +69,13 @@ if (! empty($conf->global->MEMBER_PAYONLINE_SENDEMAIL) && preg_match('/MEM=',$fu
$sendto=$conf->global->MEMBER_PAYONLINE_SENDEMAIL;
$from=$conf->global->MAILING_EMAIL_FROM;
require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
$mailfile = new CMailFile(
$mailfile = new CMailFile(
'New subscription payed',
$sendto,
$from,
'New subscription payed '.$fulltag
);
);
$result=$mailfile->sendfile();
if ($result)
{

View File

@ -99,7 +99,7 @@ if (! empty($conf->global->MEMBER_PAYONLINE_SENDEMAIL) && preg_match('/MEM=',$fu
$sendto=$conf->global->MEMBER_PAYONLINE_SENDEMAIL;
$from=$conf->global->MAILING_EMAIL_FROM;
require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
$mailfile = new CMailFile(
$mailfile = new CMailFile(
'New subscription payed',
$sendto,
$from,

View File

@ -77,7 +77,7 @@ if (! empty($conf->global->MEMBER_PAYONLINE_SENDEMAIL) && preg_match('/MEM=',$fu
$sendto=$conf->global->MEMBER_PAYONLINE_SENDEMAIL;
$from=$conf->global->MAILING_EMAIL_FROM;
require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
$mailfile = new CMailFile(
$mailfile = new CMailFile(
'New subscription payed',
$sendto,
$from,

View File

@ -136,7 +136,7 @@ if ($PAYPALTOKEN)
$sendto=$conf->global->MEMBER_PAYONLINE_SENDEMAIL;
$from=$conf->global->MAILING_EMAIL_FROM;
require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
$mailfile = new CMailFile(
$mailfile = new CMailFile(
'New subscription payed',
$sendto,
$from,

View File

@ -118,11 +118,11 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase
/**
* testWSInvoices_xxx
* testWSInvoicesXxx
*
* @return int
*/
public function testWSInvoices_xxx()
public function testWSInvoicesXxx()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;

View File

@ -118,11 +118,11 @@ class WebservicesOrdersTest extends PHPUnit_Framework_TestCase
/**
* testWSOrder_xxx
* testWSOrderXxx
*
* @return int
*/
public function testWSOrder_xxx()
public function testWSOrderXxx()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
@ -178,11 +178,11 @@ class WebservicesOrdersTest extends PHPUnit_Framework_TestCase
/**
* testWSOther_GetVersions
* testWSOtherGetVersions
*
* @return int
*/
public function testWSOther_GetVersions()
public function testWSOtherGetVersions()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;

View File

@ -118,11 +118,11 @@ class WebservicesOtherTest extends PHPUnit_Framework_TestCase
/**
* testWSOther_GetVersions
* testWSOtherGetVersions
*
* @return int
*/
public function testWSOther_GetVersions()
public function testWSOtherGetVersions()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;

View File

@ -118,11 +118,11 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase
/**
* testWSThirdparty_xxx
* testWSThirdpartyXxx
*
* @return int
*/
public function testWSThirdparty_xxx()
public function testWSThirdpartyXxx()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;

View File

@ -118,11 +118,11 @@ class WebservicesUserTest extends PHPUnit_Framework_TestCase
/**
* testWSUser_xxx
* testWSUserXxx
*
* @return int
*/
public function testWSUser_xxx()
public function testWSUserXxx()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;