mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-22 09:22:22 +00:00
CodeSniffer
This commit is contained in:
@@ -90,19 +90,19 @@ class person extends Person_model
|
||||
public function load($personId)
|
||||
{
|
||||
//person_id auf gueltigkeit pruefen
|
||||
if(is_numeric($personId) && $personId != '')
|
||||
if (is_numeric($personId) && $personId != '')
|
||||
{
|
||||
$result = $this->getPerson($personId);
|
||||
|
||||
if(!is_object($result))
|
||||
if (!is_object($result))
|
||||
{
|
||||
$this->errormsg = "Fehler beim Lesen der Personendaten\n";
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
$row = $result->row();
|
||||
|
||||
if(isset($row))
|
||||
if (isset($row))
|
||||
{
|
||||
$this->person_id = $row->person_id;
|
||||
$this->sprache = $row->sprache;
|
||||
@@ -177,7 +177,7 @@ class person extends Person_model
|
||||
* auf Gueltigkeit.
|
||||
* @return true wenn ok, false im Fehlerfall
|
||||
**/
|
||||
protected function validate()
|
||||
public function validate()
|
||||
{
|
||||
$this->nachname = trim($this->nachname);
|
||||
$this->vorname = trim($this->vorname);
|
||||
@@ -271,8 +271,10 @@ class person extends Person_model
|
||||
$gewichtung = array(3, 7, 9, 0, 5, 8, 4, 2, 1, 6);
|
||||
$erg = 0;
|
||||
//Quersumme bilden
|
||||
for($i = 0; $i < 10; $i++)
|
||||
for ($i = 0; $i < 10; $i++)
|
||||
{
|
||||
$erg += $gewichtung[$i] * $this->svnr{$i};
|
||||
}
|
||||
|
||||
if ($this->svnr{3} != ($erg % 11)) //Vergleichen der Pruefziffer mit Quersumme Modulo 11
|
||||
{
|
||||
@@ -280,7 +282,7 @@ class person extends Person_model
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($this->svnr != '')
|
||||
{
|
||||
//Pruefen ob bereits ein Eintrag mit dieser SVNR vorhanden ist
|
||||
@@ -501,7 +503,6 @@ class person extends Person_model
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -40,16 +40,16 @@ class FHComplete_Sniffs_ControlStructures_ControlSignatureSniff extends PHP_Code
|
||||
protected function getPatterns()
|
||||
{
|
||||
return array(
|
||||
'try {EOL...}\s+catch (...)EOL...{EOL...EOL...}',
|
||||
'do+EOL...{EOL...EOL...} while (...);EOL',
|
||||
'tryEOL...{EOL...}EOL...catch (...)EOL...{EOL...}EOL',
|
||||
'doEOL...{EOL...EOL...}EOL...while (...);EOL',
|
||||
'while (...)EOL...{EOL',
|
||||
'for (...) {EOL',
|
||||
'for (...)EOL...{EOL',
|
||||
'if (...)EOL...{EOL',
|
||||
'foreach (...)EOL...{EOL',
|
||||
'}EOL...\s+else if (...)EOL...{EOL',
|
||||
'}EOL...\s+elseif (...)EOL...{EOL',
|
||||
'}EOL...\s+else+EOL...{EOL',
|
||||
'do+EOL...{EOL',
|
||||
'doEOL...{EOL',
|
||||
);
|
||||
|
||||
}//end getPatterns()
|
||||
|
||||
@@ -71,7 +71,7 @@ class FHComplete_Sniffs_NamingConventions_CamelCapsMethodNameSniff extends Gener
|
||||
$error = 'Method name "%s" is not in camel caps format';
|
||||
$className = $phpcsFile->getDeclarationName($currScope);
|
||||
$errorData = array($className.'::'.$methodName);
|
||||
$phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $errorData);
|
||||
$phpcsFile->addWarning($error, $stackPtr, 'NotCamelCaps', $errorData);
|
||||
$phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'no');
|
||||
} else {
|
||||
$phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'yes');
|
||||
|
||||
@@ -1,171 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Version 5
|
||||
*
|
||||
* FHComplete
|
||||
*/
|
||||
|
||||
if (class_exists('PHP_CodeSniffer_Standards_AbstractVariableSniff', true) === false) {
|
||||
throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractVariableSniff not found');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the naming of variables and member variables.
|
||||
*
|
||||
*/
|
||||
class FHComplete_Sniffs_NamingConventions_ValidVariableNameSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff {
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* Processes variables, we skip processing object properties because
|
||||
* they could come from things like PDO which doesn't follow the normal
|
||||
* conventions and causes additional failures.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
|
||||
* @param integer $stackPtr The position of the current token in the
|
||||
* stack passed in $tokens.
|
||||
* @return void
|
||||
*/
|
||||
protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
$varName = ltrim($tokens[$stackPtr]['content'], '$');
|
||||
|
||||
$phpReservedVars = array(
|
||||
'_SERVER',
|
||||
'_GET',
|
||||
'_POST',
|
||||
'_REQUEST',
|
||||
'_SESSION',
|
||||
'_ENV',
|
||||
'_COOKIE',
|
||||
'_FILES',
|
||||
'GLOBALS',
|
||||
);
|
||||
|
||||
// If it's a php reserved var, then its ok.
|
||||
if (in_array($varName, $phpReservedVars) === true) {
|
||||
return;
|
||||
}
|
||||
|
||||
// There is no way for us to know if the var is public or private,
|
||||
// so we have to ignore a leading underscore if there is one and just
|
||||
// check the main part of the variable name.
|
||||
$originalVarName = $varName;
|
||||
if (substr($varName, 0, 1) === '_') {
|
||||
$objOperator = $phpcsFile->findPrevious(array(T_WHITESPACE), ($stackPtr - 1), null, true);
|
||||
if ($tokens[$objOperator]['code'] === T_DOUBLE_COLON) {
|
||||
// The variable lives within a class, and is referenced like
|
||||
// this: MyClass::$_variable, so we don't know its scope.
|
||||
$inClass = true;
|
||||
} else {
|
||||
$inClass = $phpcsFile->hasCondition($stackPtr, array(T_TRAIT, T_CLASS, T_INTERFACE));
|
||||
}
|
||||
|
||||
if ($inClass === true) {
|
||||
$varName = ltrim($varName, '_');
|
||||
}
|
||||
}
|
||||
|
||||
// $title_for_layout is allowed on controllers
|
||||
$fileName = basename($phpcsFile->getFilename(), '.php');
|
||||
if ((substr($fileName, -10) === 'Controller') && ($varName == 'title_for_layout')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->_isValidVar($varName) === false) {
|
||||
$error = 'Variable "%s" is not in valid camel caps format';
|
||||
$data = array($originalVarName);
|
||||
$phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes class member variables.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
|
||||
* @param integer $stackPtr The position of the current token in the
|
||||
* stack passed in $tokens.
|
||||
* @return void
|
||||
*/
|
||||
protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the variable found within a double quoted string.
|
||||
*
|
||||
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
|
||||
* @param integer $stackPtr The position of the double quoted string.
|
||||
* @return void
|
||||
*/
|
||||
protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
$phpReservedVars = array(
|
||||
'_SERVER',
|
||||
'_GET',
|
||||
'_POST',
|
||||
'_REQUEST',
|
||||
'_SESSION',
|
||||
'_ENV',
|
||||
'_COOKIE',
|
||||
'_FILES',
|
||||
'GLOBALS',
|
||||
);
|
||||
|
||||
if (preg_match_all('|[^\\\]\$([a-zA-Z0-9_]+)|', $tokens[$stackPtr]['content'], $matches) !== 0) {
|
||||
foreach ($matches[1] as $varName) {
|
||||
// If it's a php reserved var, then its ok.
|
||||
if (in_array($varName, $phpReservedVars) === true) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// There is no way for us to know if the var is public or private,
|
||||
// so we have to ignore a leading underscore if there is one and just
|
||||
// check the main part of the variable name.
|
||||
$originalVarName = $varName;
|
||||
if (substr($varName, 0, 1) === '_') {
|
||||
if ($phpcsFile->hasCondition($stackPtr, array(T_CLASS, T_INTERFACE)) === true) {
|
||||
$varName = substr($varName, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_isValidVar($varName) === false) {
|
||||
$error = 'Variable "%s" is not in valid camel caps format';
|
||||
$data = array($originalVarName);
|
||||
$phpcsFile->addError($error, $stackPtr, 'StringVarNotCamelCaps', $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that a variable is a valid shape.
|
||||
*
|
||||
* Variables in FHComplete can either be $fooBar, $FooBar, $_fooBar, or $_FooBar.
|
||||
*
|
||||
* @param string $string The variable to check.
|
||||
* @param boolea $public Whether or not the variable is public.
|
||||
* @return boolean
|
||||
*/
|
||||
protected function _isValidVar($string, $public = true) {
|
||||
$firstChar = '[a-zA-Z]';
|
||||
if (!$public) {
|
||||
$firstChar = '[_]{1,2}' . $firstChar;
|
||||
}
|
||||
if (preg_match("|^$firstChar|", $string) === 0) {
|
||||
return false;
|
||||
}
|
||||
$firstStringCount = 1;
|
||||
if (preg_match("|^__|", $string)) {
|
||||
$firstStringCount = 2;
|
||||
}
|
||||
// Check that the name only contains legal characters.
|
||||
$legalChars = 'a-zA-Z0-9';
|
||||
if (preg_match("|[^$legalChars]|", substr($string, $firstStringCount)) > 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,6 +12,7 @@
|
||||
<exclude name="PSR1.Files.SideEffects" />
|
||||
<exclude name="Generic.WhiteSpace.DisallowTabIndent" />
|
||||
<exclude name="Squiz.ControlStructures.ControlSignature" />
|
||||
<exclude name="Squiz.Classes.ValidClassName" />
|
||||
<exclude name="Generic.ControlStructures.InlineControlStructure" />
|
||||
</rule>
|
||||
|
||||
@@ -22,7 +23,13 @@
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
|
||||
|
||||
|
||||
<!--
|
||||
<rule ref="Squiz.Classes.ValidClassName">
|
||||
<type>warning</type>
|
||||
</rule>
|
||||
Temporarily ignore until API docblock formatting and line length issues in core code are fixed.
|
||||
<rule ref="FHComplete.Commenting.FunctionComment.ParamCommentNotCapital">
|
||||
<severity>0</severity>
|
||||
|
||||
Reference in New Issue
Block a user