LSformRule_compare: code cleaning

This commit is contained in:
Benjamin Renard 2021-08-25 09:41:05 +02:00
parent fed9acfedd
commit 26c0026cfc

View file

@ -17,8 +17,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
******************************************************************************/
******************************************************************************/
/** /**
* Règle de validation par comparaison de valeurs. * Règle de validation par comparaison de valeurs.
@ -27,11 +26,24 @@
*/ */
class LSformRule_compare extends LSformRule { class LSformRule_compare extends LSformRule {
// Validate values one by one or all together
const validate_one_by_one = False;
// CLI parameters autocompleters // CLI parameters autocompleters
protected static $cli_params_autocompleters = array( protected static $cli_params_autocompleters = array(
'operator' => null, 'operator' => null,
); );
// Operators mapping
static protected $_operators = array(
'eq' => '==',
'neq' => '!=',
'gt' => '>',
'gte' => '>=',
'lt' => '<',
'lte' => '<='
);
/** /**
* Retourne l'operateur de comparaison. * Retourne l'operateur de comparaison.
* *
@ -42,20 +54,11 @@ class LSformRule_compare extends LSformRule {
*/ */
private static function _findOperator($operator_name) { private static function _findOperator($operator_name) {
$_operators = array( if (empty(self :: $operator_name)) {
'eq' => '==',
'neq' => '!=',
'gt' => '>',
'gte' => '>=',
'lt' => '<',
'lte' => '<='
);
if (empty($operator_name)) {
return '=='; return '==';
} elseif (isset($_operators[$operator_name])) { } elseif (isset(self :: $_operators[$operator_name])) {
return $_operators[$operator_name]; return self :: $_operators[$operator_name];
} elseif (in_array($operator_name, $_operators)) { } elseif (in_array($operator_name, self :: $_operators)) {
return $operator_name; return $operator_name;
} else { } else {
return '=='; return '==';
@ -72,7 +75,7 @@ class LSformRule_compare extends LSformRule {
* *
* @return boolean true si la valeur est valide, false sinon * @return boolean true si la valeur est valide, false sinon
*/ */
public static function validate($value, $options=array(), &$formElement) { public static function validate($values, $options=array(), &$formElement) {
$operator = LSconfig :: get('params.operator', null, 'string', $options); $operator = LSconfig :: get('params.operator', null, 'string', $options);
if (!$operator) { if (!$operator) {
LSerror :: addErrorCode('LSformRule_01',array('type' => 'compare', 'param' => 'operator')); LSerror :: addErrorCode('LSformRule_01',array('type' => 'compare', 'param' => 'operator'));