cvs: pear /Validate/Validate FR.php

From: Date: Mon, 17 Feb 2003 10:56:41 +0000
Subject: cvs: pear /Validate/Validate FR.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-8908@lists.php.net to get a copy of this message
mansion Mon Feb 17 05:56:41 2003 EDT Modified files: /pear/Validate/Validate FR.php Log: Cosmetic CS fixes, phpdoc fixes. Index: pear/Validate/Validate/FR.php diff -u pear/Validate/Validate/FR.php:1.7 pear/Validate/Validate/FR.php:1.8 --- pear/Validate/Validate/FR.php:1.7 Sun Feb 16 23:25:35 2003 +++ pear/Validate/Validate/FR.php Mon Feb 17 05:56:41 2003 @@ -14,15 +14,13 @@ // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Pierre-Alain Joye <paj@pearfr.org> | -// | | -// | | // +----------------------------------------------------------------------+ // -// $Id: FR.php,v 1.7 2003/02/17 04:25:35 pajoye Exp $ +// $Id: FR.php,v 1.8 2003/02/17 10:56:41 mansion Exp $ // // Specific validation methods for data used in France -// -require_once "Validate.php"; + +require_once("Validate.php"); define('VALIDATE_FR_SSN_MODULUS', 97); @@ -48,32 +46,31 @@ $regexp = "/^([12])(\d\d)(\d\d)(\d\d|2a|2b)(\d\d\d)(\d\d\d)(\d\d)$/"; - if ( ! preg_match($regexp,$str,$parts) ) { + if (!preg_match($regexp,$str,$parts)) { return false; } // special case for Corsica and DOM not 100% sure, but cannot test from a db :) - if( $parts[4]=='2a' || $parts[4]=='2b' || $parts[4]=='9a' - || $parts[4]=='9b' || $parts[4]=='9c' || $parts[4]=='9d' - ){ - if (strlen($str)==15){ + if ($parts[4] == '2a' || $parts[4] == '2b' || $parts[4] == '9a' || + $parts[4] == '9b' || $parts[4] == '9c' || $parts[4] == '9d') { + if (strlen($str) == 15) { return true; } else { return false; } } - if($parts[2]<1 || $parts[2]>99){ + if ($parts[2] < 1 || $parts[2] > 99) { return false; } - if($parts[3]<1 || $parts[3]>12){ + if ($parts[3] < 1 || $parts[3] > 12) { return false; } - if($parts[4]<1 || $parts[4]>99){ + if ($parts[4] < 1 || $parts[4] > 99) { return false; } - // Person borned outside France (region code==99), have to check insee country code + // Person born outside France (region code==99), have to check insee country code // To do /* if($parts[4]==99){ @@ -86,7 +83,7 @@ $num = $parts[1].$parts[2].$parts[3].$parts[4].$parts[5].$parts[6]; $key = VALIDATE_FR_SSN_MODULUS - Validate::_modf($num,VALIDATE_FR_SSN_MODULUS); - return $key==$parts[7]?true:false; + return ($key == $parts[7]) ? true : false; } /** @@ -103,49 +100,49 @@ * @param string $aCodeGuichet number or an array containaing the 'number'=>1234 * @param string $aNoCompte number or an array containaing the 'number'=>1234 * @param string $number number or an array containaing the 'number'=>1234 - * @return bool true if number is valid, otherwise false + * @return bool true if number is valid, otherwise false * @author Pierre-Alain Joye <paj@pearfr.org> */ function rib($rib) { - if(is_array($rib)) { + if (is_array($rib)) { $codebanque=$codeguichet=$nocompte=$key=''; extract($rib); } else { return false; } - $chars = array('/[AJ]/','/[BKZ]/','/[CLT]/','/[DMU]/','/[ENV]/','/[FOW]/','/[GPX]/','/[HQY]/','/[IRZ]/'); - $values = array('1','2','3','4','5','6','7','8','9'); + $chars = array('/[AJ]/','/[BKZ]/','/[CLT]/','/[DMU]/','/[ENV]/','/[FOW]/','/[GPX]/','/[HQY]/','/[IRZ]/'); + $values = array('1','2','3','4','5','6','7','8','9'); - $codebank = preg_replace('/[^0-9]/','',$codebanque); - $officecode = preg_replace('/[^0-9]/','',$codeguichet); - $account = preg_replace($chars,$values,$nocompte); + $codebank = preg_replace('/[^0-9]/', '', $codebanque); + $officecode = preg_replace('/[^0-9]/', '', $codeguichet); + $account = preg_replace($chars, $values, $nocompte); - if (strlen($codebank)!=5){ + if (strlen($codebank) != 5){ return false; } - if (strlen($officecode)!=5){ + if (strlen($officecode) != 5){ return false; } - if (strlen($account)>11){ + if (strlen($account) > 11){ return false; } $l = $codebank.$officecode.$account; - $a1 = substr($l,0,7); - $b1 = substr($l,7,7); - $c1 = substr($l,14,7); + $a1 = substr($l, 0, 7); + $b1 = substr($l, 7, 7); + $c1 = substr($l, 14, 7); - $key = 97 - Validate::_modf((62*$a1+34*$b1+3*$c1),97); + $key = 97 - Validate::_modf((62*$a1+34*$b1+3*$c1), 97); - if ($key==0){ + if ($key == 0){ $key = 97; } - return $key==intval($key); + return $key == intval($key); } @@ -155,31 +152,29 @@ * * @param string $siren number or an array containaing the 'number'=>1234 * @return bool true if number is valid, otherwise false - * @author Damien Seguy, added by Pierre-Alain Joye <paj@pearfr.org> + * @author Damien Seguy <dams@nexen.net> */ function siren($siren) { $siren = str_replace(' ', '', $siren); - if (!preg_match("/^(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)$/", - $siren, $match)) { + if (!preg_match("/^(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)$/", $siren, $match)) { return false; } $match[2] *= 2; $match[4] *= 2; $match[6] *= 2; $match[8] *= 2; - $somme = 0; + $sum = 0; - for ($i = 1; $i<count($match); $i++) { + for ($i = 1; $i < count($match); $i++) { if ($match[$i] > 9) { $a = (int)substr($match[$i], 0, 1); $b = (int)substr($match[$i], 1, 1); $match[$i] = $a + $b; } - $somme += $match[$i]; + $sum += $match[$i]; } - - return (($somme % 10) == 0); + return (($sum % 10) == 0); } /** @@ -188,20 +183,15 @@ * * @param string $siret number or an array containaing the 'number'=>1234 * @return bool true if number is valid, otherwise false - * @author Damien Seguy, added by Pierre-Alain Joye <paj@pearfr.org> + * @author Damien Seguy <dams@nexen.net> */ function siret($siret) { $siret = str_replace(' ', '', $siret); - if ( - !preg_match( - "/^(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)$/", - $siret, $match - ) - ) { + if (!preg_match("/^(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)$/", $siret, $match)) { return false; } else { - if( !Validate_FR::siren(implode('', array_slice($match, 1,9))) ) { + if (!Validate_FR::siren(implode('', array_slice($match, 1,9)))) { return false; } } @@ -212,21 +202,17 @@ $match[9] *= 2; $match[11] *= 2; $match[13] *= 2; + $sum = 0; - $somme = 0; - - for ($i = 1; $i<count($match); $i++) { + for ($i = 1; $i < count($match); $i++) { if ($match[$i] > 9) { $a = (int)substr($match[$i], 0, 1); $b = (int)substr($match[$i], 1, 1); $match[$i] = $a + $b; } - $somme += $match[$i]; + $sum += $match[$i]; } - - return ( ($somme % 10) == 0 ); - + return (($sum % 10) == 0); } - } -?> +?> \ No newline at end of file

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