Clean PHP8 compatibility errors detected by PHPstan

This commit is contained in:
Benjamin Renard 2022-12-31 02:31:21 +01:00
parent 7f862c9765
commit 38fa02619d
32 changed files with 60 additions and 60 deletions

1
.gitignore vendored
View file

@ -3,3 +3,4 @@ upgrade.log
*~
vendor
/src/local.*
tests-report.xml

View file

@ -549,7 +549,7 @@ class LSform extends LSlog_staticLoggerClass {
*
* @retval LSformElement
*/
public function addElement($type,$name,$label,$params=array(),&$attr_html) {
public function addElement($type,$name,$label,$params,&$attr_html) {
$elementType='LSformElement_'.$type;
LSsession :: loadLSclass($elementType);
if (!class_exists($elementType)) {

View file

@ -365,7 +365,7 @@ class LSformElement extends LSlog_staticLoggerClass {
*
* @retval boolean True on success, False otherwise
*/
protected function split_autocomplete_attr_values($attr_value="", $multiple_value_delimiter="|", &$attr_values, &$last_attr_value) {
protected function split_autocomplete_attr_values($attr_value, $multiple_value_delimiter, &$attr_values, &$last_attr_value) {
$attr_values = explode($multiple_value_delimiter, $attr_value);
if (count($attr_values) > 1 && !$this -> getParam('multiple', false, 'bool')) {
self :: log_error("The attribute ".$this -> name." is not multivalued.");

View file

@ -50,7 +50,7 @@ class LSformRule extends LSlog_staticLoggerClass {
*
* @return boolean True if value is valid, False otherwise
*/
public static function validate_values($rule_name, $values, $options=array(), &$formElement) {
public static function validate_values($rule_name, $values, $options, &$formElement) {
// Compute PHP class name of the rule
$rule_class = "LSformRule_".$rule_name;
@ -93,7 +93,7 @@ class LSformRule extends LSlog_staticLoggerClass {
*
* @return boolean True if value is valid, False otherwise
*/
public static function validate($value, $options=array(), &$formElement) {
public static function validate($value, $options, &$formElement) {
return false;
}

View file

@ -36,7 +36,7 @@ class LSformRule_LSformElement_select_validValue extends LSformRule {
*
* @return boolean true if the value is valide, false if not
*/
public static function validate($value, $options=array(), &$formElement) {
public static function validate($value, $options, &$formElement) {
$ret = $formElement -> isValidValue($value);
if ($ret===False) return False;
return True;

View file

@ -42,7 +42,7 @@ class LSformRule_alphanumeric extends LSformRule {
*
* @return boolean true si la valeur est valide, false sinon
*/
public static function validate($value, $options=array(), &$formElement) {
public static function validate($value, $options, &$formElement) {
if (LSconfig :: get('params.withAccents', false, 'bool', $options)) {
$regex = '/(*UTF8)^[0-9\p{L}]+$/';

View file

@ -46,7 +46,7 @@ class LSformRule_callable extends LSformRule {
*
* @return boolean true if the value is valid, false otherwise
*/
public static function validate($value, $options=array(), &$formElement) {
public static function validate($value, $options, &$formElement) {
$callable = LSconfig :: get('params.callable', null, null, $options);
if (is_callable($callable))
return call_user_func_array(

View file

@ -35,34 +35,39 @@ class LSformRule_compare extends LSformRule {
);
// Operators mapping
static protected $_operators = array(
'eq' => '==',
'neq' => '!=',
'gt' => '>',
'gte' => '>=',
'lt' => '<',
'lte' => '<='
static protected $_operators_aliases = array(
'==' => 'eq',
'!=' => 'neq',
'>' => 'gt',
'>=' => 'gte',
'<' => 'lt',
'<=' => 'lte',
);
static protected $_operators_to_compare_function = array(
'eq' => function($a, $b) {return floatval($a) == floatval($b);},
'neq' => function($a, $b) {return floatval($a) != floatval($b);},
'gt' => function($a, $b) {return $a > $b;},
'gte' => function($a, $b) {return $a >= $b;},
'lt' => function($a, $b) {return $a < $b;},
'lte' => function($a, $b) {return $a <= $b;},
);
/**
* Retourne l'operateur de comparaison.
* Return the compare function associated with the specified operator
*
* @access private
* @param string Nom de l'operateur
* @param string The operator name
*
* @return string Operateur à utiliser
* @return function The compare function
*/
private static function _findOperator($operator_name) {
if (empty(self :: $operator_name)) {
return '==';
} elseif (isset(self :: $_operators[$operator_name])) {
return self :: $_operators[$operator_name];
} elseif (in_array($operator_name, self :: $_operators)) {
return $operator_name;
} else {
return '==';
}
private static function _findOperatorCompareFunction($operator_name) {
if (empty($operator_name))
$operator_name = 'eq';
elseif (isset(self :: $_operators_aliases[$operator_name]))
$operator_name = self :: $_operators_aliases[$operator_name];
elseif (!isset(self :: $_operators_to_compare_function[$operator_name]))
$operator_name = 'eq';
return self :: $_operators_to_compare_function[$operator_name];
}
/**
@ -75,19 +80,13 @@ class LSformRule_compare extends LSformRule {
*
* @return boolean true si la valeur est valide, false sinon
*/
public static function validate($values, $options=array(), &$formElement) {
public static function validate($values, $options, &$formElement) {
$operator = LSconfig :: get('params.operator', null, 'string', $options);
if (!$operator) {
LSerror :: addErrorCode('LSformRule_01',array('type' => 'compare', 'param' => 'operator'));
return;
}
$operator = self :: _findOperator($operator);
if ('==' != $operator && '!=' != $operator) {
$compareFn = create_function('$a, $b', 'return floatval($a) ' . $operator . ' floatval($b);');
}
else {
$compareFn = create_function('$a, $b', 'return $a ' . $operator . ' $b;');
}
$compareFn = self :: _findOperatorCompareFunction($operator);
return $compareFn($values[0], $values[1]);
}

View file

@ -44,7 +44,7 @@ class LSformRule_date extends LSformRule {
*
* @return boolean True si les données sont valide, False sinon.
*/
public static function validate($value, $options=array(), &$formElement) {
public static function validate($value, $options, &$formElement) {
$special_values = LSconfig :: get('params.special_values', array(), null, $options);
if (in_array($value, $special_values))
return true;

View file

@ -42,7 +42,7 @@ class LSformRule_differentPassword extends LSformRule {
*
* @return boolean true si la valeur est valide, false sinon
*/
public static function validate($value, $options=array(), &$formElement) {
public static function validate($value, $options, &$formElement) {
$otherPasswordAttributes = LSconfig :: get('params.otherPasswordAttributes', null, null, $options);
if (!is_null($otherPasswordAttributes)) {
// Load LSattr_ldap_password

View file

@ -43,7 +43,7 @@ class LSformRule_email extends LSformRule {
*
* @return boolean true si la valeur est valide, false sinon
*/
public static function validate($value, $options=array(), &$formElement) {
public static function validate($value, $options, &$formElement) {
return checkEmail(
$value,
LSconfig :: get('params.domain', null, null, $options),

View file

@ -44,7 +44,7 @@ class LSformRule_filesize extends LSformRule {
*
* @return boolean true si la valeur est valide, false sinon
*/
public static function validate($value, $options=array(), &$formElement) {
public static function validate($value, $options, &$formElement) {
// According to PHP doc, strlen() returns the number of bytes rather
// than the number of characters in a string.
// See: https://www.php.net/manual/en/function.strlen.php

View file

@ -40,7 +40,7 @@ class LSformRule_imagefile extends LSformRule {
*
* @return boolean true si la valeur est valide, false sinon
*/
public static function validate($value, $options=array(), &$formElement) {
public static function validate($value, $options, &$formElement) {
$file = LSsession :: getTmpFile($value);
$mimetype = mime_content_type($file);

View file

@ -48,7 +48,7 @@ class LSformRule_imagesize extends LSformRule {
*
* @return boolean true si la valeur est valide, false sinon
*/
public static function validate($value, $options=array(), &$formElement) {
public static function validate($value, $options, &$formElement) {
$file = LSsession :: getTmpFile($value);
list($width, $height, $type, $attr) = getimagesize($file);
self :: log_debug("validate(): image size is $width x $height, type=$type, attr='$attr'");

View file

@ -45,7 +45,7 @@ class LSformRule_inarray extends LSformRule {
*
* @return boolean true if the value is valid, false otherwise
*/
public static function validate($value, $options=array(), &$formElement) {
public static function validate($value, $options, &$formElement) {
$possible_values = LSconfig :: get('params.possible_values', null, null, $options);
$reverse = LSconfig :: get('params.reverse', false, 'bool', $options);
if (!is_array($possible_values)) {

View file

@ -48,7 +48,7 @@ class LSformRule_integer extends LSformRule{
*
* @return boolean true if the value is valided, false otherwise
*/
public static function validate($value, $options=array(), &$formElement) {
public static function validate($value, $options, &$formElement) {
$max = LSconfig :: get('params.max', null, 'int', $options);
if(is_int($max) && $max != 0 && $value > $max) {
self :: log_debug("value is too higth ($value > $max)");

View file

@ -46,7 +46,7 @@ class LSformRule_ldapSearchURI extends LSformRule {
*
* @return boolean true if the value is valid, false otherwise
*/
public static function validate($value, $options=array(), &$formElement) {
public static function validate($value, $options, &$formElement) {
self :: log_trace("validate($value): options = ".varDump($options));
$uri_parts = explode('?', $value);

View file

@ -36,7 +36,7 @@ class LSformRule_lettersonly extends LSformRule {
*
* @return boolean true si la valeur est valide, false sinon
*/
public static function validate($value, $options=array(), &$formElement) {
public static function validate($value, $options, &$formElement) {
$regex = '/^[a-zA-Z]+$/';
LSsession :: loadLSclass('LSformRule_regex');
return LSformRule_regex :: validate($value,$regex,$formElement);

View file

@ -42,7 +42,7 @@ class LSformRule_maxlength extends LSformRule {
*
* @return boolean true si la valeur est valide, false sinon
*/
public static function validate($value, $options=array(), &$formElement) {
public static function validate($value, $options, &$formElement) {
$limit = LSconfig :: get('params.limit', null, 'int', $options);
if(is_null($limit)) {
LSerror :: addErrorCode('LSformRule_01',array('type' => 'maxlength', 'param' => 'limit'));

View file

@ -44,7 +44,7 @@ class LSformRule_mimetype extends LSformRule {
*
* @return boolean true si la valeur est valide, false sinon
*/
public static function validate($value, $options=array(), &$formElement) {
public static function validate($value, $options, &$formElement) {
$file = LSsession :: getTmpFile($value);
$real_mimetype = mime_content_type($file);

View file

@ -42,7 +42,7 @@ class LSformRule_minlength extends LSformRule {
*
* @return boolean true si la valeur est valide, false sinon
*/
public static function validate($value, $options=array(), &$formElement) {
public static function validate($value, $options, &$formElement) {
$limit = LSconfig :: get('params.limit', null, 'int', $options);
if(is_null($limit)) {
LSerror :: addErrorCode('LSformRule_01',array('type' => 'minlength', 'param' => 'limit'));

View file

@ -36,7 +36,7 @@ class LSformRule_nonzero extends LSformRule {
*
* @return boolean true si la valeur est valide, false sinon
*/
public static function validate($value, $options=array(), &$formElement) {
public static function validate($value, $options, &$formElement) {
$regex = '/^-?[1-9][0-9]*/';
LSsession :: loadLSclass('LSformRule_regex');
return LSformRule_regex :: validate($value,$regex,$formElement);

View file

@ -36,7 +36,7 @@ class LSformRule_nopunctuation extends LSformRule {
*
* @return boolean true si la valeur est valide, false sinon
*/
public static function validate($value, $options=array(), &$formElement) {
public static function validate($value, $options, &$formElement) {
$regex = '/^[^().\/\*\^\?#!@$%+=,\"\'><~\[\]{}]+$/';
LSsession :: loadLSclass('LSformRule_regex');
return LSformRule_regex :: validate($value,$regex,$formElement);

View file

@ -45,7 +45,7 @@ class LSformRule_numberOfValues extends LSformRule {
*
* @return boolean true if the value is valide, false if not
*/
public static function validate($value, $options=array(), &$formElement) {
public static function validate($value, $options, &$formElement) {
$max_values = LSconfig :: get('params.max', null, 'int', $options);
$min_values = LSconfig :: get('params.min', null, 'int', $options);
if(is_null($max_values) && is_null($min_values)) {

View file

@ -36,7 +36,7 @@ class LSformRule_numeric extends LSformRule{
*
* @return boolean true si la valeur est valide, false sinon
*/
public static function validate($value, $options=array(), &$formElement) {
public static function validate($value, $options, &$formElement) {
$regex = '/(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/';
LSsession :: loadLSclass('LSformRule_regex');
return LSformRule_regex :: validate($value,$regex,$formElement);

View file

@ -52,7 +52,7 @@ class LSformRule_password extends LSformRule {
*
* @return boolean true si la valeur est valide, false sinon
*/
public static function validate($value, $options=array(), &$formElement) {
public static function validate($value, $options, &$formElement) {
$errors = array();
$maxLength = LSconfig :: get('params.maxLength', null, 'int', $options);

View file

@ -43,7 +43,7 @@ class LSformRule_rangelength extends LSformRule {
*
* @return boolean true si la valeur est valide, false sinon
*/
public static function validate($value, $options=array(), &$formElement) {
public static function validate($value, $options, &$formElement) {
$limits = LSconfig :: get('params.limits', null, null, $options);
if(!is_array($limits) || count($limits) != 2) {
LSerror :: addErrorCode('LSformRule_01',array('type' => 'rangelength', 'param' => 'limits'));

View file

@ -42,7 +42,7 @@ class LSformRule_regex extends LSformRule {
*
* @return boolean true si la valeur est valide, false sinon
*/
public static function validate($value, $options=array(), &$formElement) {
public static function validate($value, $options, &$formElement) {
if (is_array($options)) {
$regex = LSconfig :: get('params.regex', null, 'string', $options);
if (!is_string($regex)) {

View file

@ -36,7 +36,7 @@ class LSformRule_required extends LSformRule {
*
* @return boolean true si la valeur est valide, false sinon
*/
public static function validate($value, $options=array(), &$formElement) {
public static function validate($value, $options, &$formElement) {
return ((string)$value != '');
}

View file

@ -36,7 +36,7 @@ class LSformRule_ssh_pub_key extends LSformRule {
*
* @return boolean true if the value is valide, false if not
*/
public static function validate($value, $options=array(), &$formElement) {
public static function validate($value, $options, &$formElement) {
if (preg_match('/^(ssh-[a-z0-9]+) +([^ ]+) +(.*)$/', $value, $m)) {
$data=@base64_decode($m[2]);
if (is_string($data))

View file

@ -36,7 +36,7 @@ class LSformRule_telephonenumber extends LSformRule {
*
* @return boolean true si la valeur est valide, false sinon
*/
public static function validate($value, $options=array(), &$formElement) {
public static function validate($value, $options, &$formElement) {
$regex = '/^(01|02|03|04|05|06|08|09)[0-9]{8}$/';
LSsession :: loadLSclass('LSformRule_regex');
return LSformRule_regex :: validate($value,$regex,$formElement);

View file

@ -54,7 +54,7 @@ class LSformRule_zxcvbn extends LSformRule {
*
* @return boolean True if value is valid, False otherwise
*/
public static function validate($value, $options=array(), &$formElement) {
public static function validate($value, $options, &$formElement) {
$zxcvbn = new Zxcvbn();
$userData = array();
$userDataAttrs = LSconfig :: get('params.userDataAttrs', array(), 'array', $options);