diff options
Diffstat (limited to 'includes/Cdb_PHP.php')
-rw-r--r-- | includes/Cdb_PHP.php | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/includes/Cdb_PHP.php b/includes/Cdb_PHP.php index 02be65f3..a38b9a86 100644 --- a/includes/Cdb_PHP.php +++ b/includes/Cdb_PHP.php @@ -73,10 +73,10 @@ class CdbFunctions { public static function hash( $s ) { $h = 5381; for ( $i = 0; $i < strlen( $s ); $i++ ) { - $h5 = ($h << 5) & 0xffffffff; + $h5 = ( $h << 5 ) & 0xffffffff; // Do a 32-bit sum // Inlined here for speed - $sum = ($h & 0x3fffffff) + ($h5 & 0x3fffffff); + $sum = ( $h & 0x3fffffff ) + ( $h5 & 0x3fffffff ); $h = ( ( $sum & 0x40000000 ? 1 : 0 ) @@ -126,6 +126,7 @@ class CdbReader_PHP extends CdbReader { /** * @param $fileName string + * @throws MWException */ function __construct( $fileName ) { $this->fileName = $fileName; @@ -137,7 +138,7 @@ class CdbReader_PHP extends CdbReader { } function close() { - if( isset( $this->handle ) ) { + if ( isset( $this->handle ) ) { fclose( $this->handle ); } unset( $this->handle ); @@ -179,7 +180,7 @@ class CdbReader_PHP extends CdbReader { protected function read( $length, $pos ) { if ( fseek( $this->handle, $pos ) == -1 ) { // This can easily happen if the internal pointers are incorrect - throw new MWException( + throw new MWException( 'Seek failed, file "' . $this->fileName . '" may be corrupted.' ); } @@ -198,12 +199,13 @@ class CdbReader_PHP extends CdbReader { /** * Unpack an unsigned integer and throw an exception if it needs more than 31 bits * @param $s - * @return + * @throws MWException + * @return mixed */ protected function unpack31( $s ) { $data = unpack( 'V', $s ); if ( $data[1] > 0x7fffffff ) { - throw new MWException( + throw new MWException( 'Error in CDB file "' . $this->fileName . '", integer too big.' ); } return $data[1]; @@ -330,10 +332,10 @@ class CdbWriter_PHP extends CdbWriter { */ public function close() { $this->finish(); - if( isset($this->handle) ) { + if ( isset( $this->handle ) ) { fclose( $this->handle ); } - if ( wfIsWindows() && file_exists($this->realFileName) ) { + if ( wfIsWindows() && file_exists( $this->realFileName ) ) { unlink( $this->realFileName ); } if ( !rename( $this->tmpFileName, $this->realFileName ) ) { @@ -349,7 +351,7 @@ class CdbWriter_PHP extends CdbWriter { protected function write( $buf ) { $len = fwrite( $this->handle, $buf ); if ( $len !== strlen( $buf ) ) { - $this->throwException( 'Error writing to CDB file "'.$this->tmpFileName.'".' ); + $this->throwException( 'Error writing to CDB file "' . $this->tmpFileName . '".' ); } } @@ -361,7 +363,7 @@ class CdbWriter_PHP extends CdbWriter { $newpos = $this->pos + $len; if ( $newpos > 0x7fffffff ) { $this->throwException( - 'A value in the CDB file "'.$this->tmpFileName.'" is too large.' ); + 'A value in the CDB file "' . $this->tmpFileName . '" is too large.' ); } $this->pos = $newpos; } @@ -390,10 +392,10 @@ class CdbWriter_PHP extends CdbWriter { */ protected function addbegin( $keylen, $datalen ) { if ( $keylen > 0x7fffffff ) { - $this->throwException( 'Key length too long in file "'.$this->tmpFileName.'".' ); + $this->throwException( 'Key length too long in file "' . $this->tmpFileName . '".' ); } if ( $datalen > 0x7fffffff ) { - $this->throwException( 'Data length too long in file "'.$this->tmpFileName.'".' ); + $this->throwException( 'Data length too long in file "' . $this->tmpFileName . '".' ); } $buf = pack( 'VV', $keylen, $datalen ); $this->write( $buf ); @@ -409,7 +411,7 @@ class CdbWriter_PHP extends CdbWriter { // Calculate the number of items that will be in each hashtable $counts = array_fill( 0, 256, 0 ); foreach ( $this->hplist as $item ) { - ++ $counts[ 255 & $item['h'] ]; + ++ $counts[255 & $item['h']]; } // Fill in $starts with the *end* indexes @@ -448,9 +450,11 @@ class CdbWriter_PHP extends CdbWriter { $hp = $packedTables[$starts[$i] + $u]; $where = CdbFunctions::unsignedMod( CdbFunctions::unsignedShiftRight( $hp['h'], 8 ), $len ); - while ( $hashtable[$where]['p'] ) - if ( ++$where == $len ) + while ( $hashtable[$where]['p'] ) { + if ( ++$where == $len ) { $where = 0; + } + } $hashtable[$where] = $hp; } @@ -468,14 +472,14 @@ class CdbWriter_PHP extends CdbWriter { // Write the pointer array at the start of the file rewind( $this->handle ); if ( ftell( $this->handle ) != 0 ) { - $this->throwException( 'Error rewinding to start of file "'.$this->tmpFileName.'".' ); + $this->throwException( 'Error rewinding to start of file "' . $this->tmpFileName . '".' ); } $this->write( $final ); } /** * Clean up the temp file and throw an exception - * + * * @param $msg string * @throws MWException */ |