cvs: pear /Validate Validate.php

From: Date: Mon, 08 Nov 2004 09:31:18 +0000
Subject: cvs: pear /Validate Validate.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-25764@lists.php.net to get a copy of this message
dufuz Mon Nov 8 04:31:18 2004 EDT Modified files: /pear/Validate Validate.php Log: Small amount of CS fixes http://cvs.php.net/diff.php/pear/Validate/Validate.php?r1=1.42&r2=1.43&ty=u Index: pear/Validate/Validate.php diff -u pear/Validate/Validate.php:1.42 pear/Validate/Validate.php:1.43 --- pear/Validate/Validate.php:1.42 Mon Nov 8 04:12:24 2004 +++ pear/Validate/Validate.php Mon Nov 8 04:31:12 2004 @@ -17,7 +17,7 @@ // | Pierre-Alain Joye <paj@pearfr.org> | // +----------------------------------------------------------------------+ // -// $Id: Validate.php,v 1.42 2004/11/08 09:12:24 dufuz Exp $ +// $Id: Validate.php,v 1.43 2004/11/08 09:31:12 dufuz Exp $ // // Methods for common data validations // @@ -49,8 +49,8 @@ */ function number($number, $options=array()) { - $decimal=$dec_prec=$min=$max= null; - if(is_array($options)){ + $decimal = $dec_prec = $min = $max = null; + if( is_array($options)) { extract($options); } @@ -117,7 +117,7 @@ { $format = null; $min_length = $max_length = 0; - if (is_array($options)){ + if (is_array($options)) { extract($options); } if ($format && !preg_match("|^[$format]*\$|s", $string)) { @@ -153,8 +153,8 @@ } if (preg_match( '!^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?!', - $url,$matches) - ) { + $url,$matches)) + { $scheme = $matches[2]; $authority = $matches[4]; if ( is_array($allowed_schemes) && @@ -365,7 +365,7 @@ } $t = 0; - for($i=0; $i< strlen($isbn)-1; $i++){ + for ($i = 0; $i < strlen($isbn) - 1; $i++){ $t += $isbn[$i]*(10-$i); } $f = $isbn[9]; @@ -582,9 +582,9 @@ } function _modf($val, $div) { - if( function_exists('bcmod') ){ + if (function_exists('bcmod')) { return bcmod($val,$div); - } else if (function_exists('fmod')) { + } elseif (function_exists('fmod')) { return fmod($val,$div); } $r = $a / $b; @@ -600,15 +600,16 @@ * @returns int returns product of number digits with weights */ function _mult_weights($number, &$weights) { - if (!is_array($weights)) + if (!is_array($weights)) { return -1; - + } $sum = 0; $count = min(count($weights), strlen($number)); - if ($count == 0) // empty string or weights array + if ($count == 0) { // empty string or weights array return -1; - for ($i=0; $i<$count; ++$i) { + } + for ($i = 0; $i < $count; ++$i) { $sum += intval(substr($number,$i,1)) * $weights[$i]; } @@ -628,16 +629,17 @@ function _get_control_number($number, &$weights, $modulo = 10, $subtract = 0, $allow_high = false) { // calc sum $sum = Validate::_mult_weights($number, $weights); - if ($sum == -1) + if ($sum == -1) { return -1; + } + $mod = Validate::_modf($sum, $modulo); // calculate control digit - $mod = Validate::_modf($sum, $modulo); /* calculate control digit */ - - if ($subtract > $mod) + if ($subtract > $mod) { $mod = $subtract - $mod; - - if ($allow_high === false) - $mod %= 10; /* change 10 to zero */ + } + if ($allow_high === false) { + $mod %= 10; // change 10 to zero + } return $mod; } @@ -651,21 +653,21 @@ * @returns bool **/ function _check_control_number($number, &$weights, $modulo = 10, $subtract = 0) { - if (strlen($number) < count($weights)) + if (strlen($number) < count($weights)) { return false; - + } $target_digit = substr($number, count($weights), 1); $control_digit = Validate::_get_control_number($number, $weights, $modulo, $subtract, $target_digit === 'X'); - if ($control_digit == -1) + if ($control_digit == -1) { return false; - - if ($target_digit === 'X' && $control_digit == 10) + } + if ($target_digit === 'X' && $control_digit == 10) { return true; - - if ($control_digit != $target_digit) + } + if ($control_digit != $target_digit) { return false; - + } return true; } @@ -716,12 +718,13 @@ list($class, $method) = explode('_', $opt['type'], 2); @include_once("Validate/$class.php"); if (!class_exists("Validate_$class") || - !in_array($method, get_class_methods("Validate_$class"))) { + !in_array($method, get_class_methods("Validate_$class"))) + { trigger_error("Invalid validation type Validate_$class::$method", E_USER_WARNING); continue; } $opt = array_slice($opt,1); - if (sizeof($opt) == 1){ + if (sizeof($opt) == 1) { $opt = array_pop($opt); } $valid[$var_name] = call_user_func(array("Validate_$class", $method), $data[$var_name],$opt);

« previous php.pear.cvs (#25764) next »