From afaa111d2216f92230689523418c12e23a6f3111 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Mon, 18 Jul 2016 15:13:56 +0200 Subject: [PATCH] code style --- lib/i18n.php | 4 ++-- lib/persistence.php | 14 +++++++++----- lib/privatebin/data.php | 12 ++++++------ lib/trafficlimiter.php | 2 +- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/lib/i18n.php b/lib/i18n.php index c788f2ea..0195f975 100644 --- a/lib/i18n.php +++ b/lib/i18n.php @@ -306,7 +306,7 @@ class i18n case 'zh': return ($n > 1 ? 1 : 0); case 'pl': - return ($n == 1 ? 0 : $n%10 >= 2 && $n %10 <=4 && ($n%100 < 10 || $n%100 >= 20) ? 1 : 2); + return ($n == 1 ? 0 : $n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2); // en, de default: return ($n != 1 ? 1 : 0); @@ -386,7 +386,7 @@ class i18n protected static function _matchLanguage($a, $b) { $a = explode('-', $a); $b = explode('-', $b); - for ($i=0, $n=min(count($a), count($b)); $i<$n; $i++) + for ($i=0, $n = min(count($a), count($b)); $i < $n; ++$i) { if ($a[$i] !== $b[$i]) break; } diff --git a/lib/persistence.php b/lib/persistence.php index 9dcc59dc..675891a5 100644 --- a/lib/persistence.php +++ b/lib/persistence.php @@ -45,13 +45,16 @@ abstract class persistence * @access public * @static * @param string $filename - * @return void + * @return string */ public static function getPath($filename = null) { - if(strlen($filename)) { + if (strlen($filename)) + { return self::$_path . DIRECTORY_SEPARATOR . $filename; - } else { + } + else + { return self::$_path; } } @@ -92,7 +95,7 @@ abstract class persistence $writtenBytes = @file_put_contents( $file, 'Allow from none' . PHP_EOL . - 'Deny from all'. PHP_EOL, + 'Deny from all' . PHP_EOL, LOCK_EX ); if ($writtenBytes === false || $writtenBytes < 30) { @@ -116,7 +119,8 @@ abstract class persistence self::_initialize(); $file = self::$_path . DIRECTORY_SEPARATOR . $filename; $writtenBytes = @file_put_contents($file, $data, LOCK_EX); - if ($writtenBytes === false || $writtenBytes < strlen($data)) { + if ($writtenBytes === false || $writtenBytes < strlen($data)) + { throw new Exception('unable to write to file ' . $file, 13); } @chmod($file, 0640); // protect file access diff --git a/lib/privatebin/data.php b/lib/privatebin/data.php index 285c538d..90503953 100644 --- a/lib/privatebin/data.php +++ b/lib/privatebin/data.php @@ -42,7 +42,7 @@ class privatebin_data extends privatebin_abstract array_key_exists('dir', $options) ) self::$_dir = $options['dir'] . DIRECTORY_SEPARATOR; // if needed initialize the singleton - if(!(self::$_instance instanceof privatebin_data)) { + if (!(self::$_instance instanceof privatebin_data)) { self::$_instance = new self; self::_init(); } @@ -74,7 +74,7 @@ class privatebin_data extends privatebin_abstract */ public function read($pasteid) { - if(!$this->exists($pasteid)) return false; + if (!$this->exists($pasteid)) return false; $paste = json_decode( file_get_contents(self::_dataid2path($pasteid) . $pasteid) ); @@ -111,7 +111,7 @@ class privatebin_data extends privatebin_abstract $dir = dir($discdir); while (false !== ($filename = $dir->read())) { - if (is_file($discdir.$filename)) @unlink($discdir.$filename); + if (is_file($discdir . $filename)) @unlink($discdir . $filename); } $dir->close(); @@ -289,7 +289,7 @@ class privatebin_data extends privatebin_abstract file_put_contents( self::$_dir . '.htaccess', 'Allow from none' . PHP_EOL . - 'Deny from all'. PHP_EOL + 'Deny from all' . PHP_EOL ); } } @@ -311,8 +311,8 @@ class privatebin_data extends privatebin_abstract */ private static function _dataid2path($dataid) { - return self::$_dir . substr($dataid,0,2) . DIRECTORY_SEPARATOR . - substr($dataid,2,2) . DIRECTORY_SEPARATOR; + return self::$_dir . substr($dataid, 0, 2) . DIRECTORY_SEPARATOR . + substr($dataid, 2, 2) . DIRECTORY_SEPARATOR; } /** diff --git a/lib/trafficlimiter.php b/lib/trafficlimiter.php index 55e040f2..bd6f4fed 100644 --- a/lib/trafficlimiter.php +++ b/lib/trafficlimiter.php @@ -115,7 +115,7 @@ class trafficlimiter extends persistence $tl = $GLOBALS['traffic_limiter']; // purge file of expired IPs to keep it small - foreach($tl as $key => $time) + foreach ($tl as $key => $time) { if ($time + self::$_limit < $now) {