From 54f96b9938112940840222a776ee2a621c895849 Mon Sep 17 00:00:00 2001 From: Sobak Date: Thu, 21 Jul 2016 17:09:48 +0200 Subject: [PATCH 1/6] Introduce PSR-4 autoloading --- .gitignore | 1 + composer.json | 11 ++-- index.php | 4 +- lib/auto.php | 38 -------------- lib/configuration.php | 5 ++ .../abstract.php => data/AbstractData.php} | 4 +- lib/{privatebin => data}/data.php | 6 ++- lib/{privatebin => data}/db.php | 10 +++- lib/filter.php | 7 ++- lib/i18n.php | 4 +- lib/model.php | 16 +++++- lib/model/{abstract.php => AbstractModel.php} | 12 ++++- lib/model/comment.php | 11 +++- lib/model/paste.php | 11 +++- lib/persistence.php | 4 ++ lib/privatebin.php | 6 ++- lib/purgelimiter.php | 2 + lib/request.php | 2 + lib/serversalt.php | 4 ++ lib/sjcl.php | 2 + lib/trafficlimiter.php | 2 + lib/view.php | 4 ++ lib/vizhash16x16.php | 2 + tpl/bootstrap-compact.php | 50 +++++++++---------- tpl/bootstrap-dark-page.php | 48 +++++++++--------- tpl/bootstrap-dark.php | 48 +++++++++--------- tpl/bootstrap-page.php | 48 +++++++++--------- tpl/bootstrap.php | 48 +++++++++--------- tpl/page.php | 48 +++++++++--------- tst/auto.php | 8 --- tst/bootstrap.php | 5 +- tst/configuration.php | 3 ++ tst/filter.php | 3 ++ tst/i18n.php | 3 ++ tst/jsonApi.php | 8 ++- tst/model.php | 15 ++++-- tst/phpunit.xml | 2 +- tst/privatebin.php | 8 ++- tst/privatebin/data.php | 5 +- tst/privatebin/db.php | 31 ++++++------ tst/privatebinWithDb.php | 8 ++- tst/purgelimiter.php | 3 ++ tst/request.php | 3 ++ tst/serversalt.php | 3 ++ tst/sjcl.php | 3 ++ tst/trafficlimiter.php | 3 ++ tst/view.php | 4 ++ tst/vizhash16x16.php | 4 ++ 48 files changed, 342 insertions(+), 238 deletions(-) delete mode 100644 lib/auto.php rename lib/{privatebin/abstract.php => data/AbstractData.php} (98%) rename lib/{privatebin => data}/data.php (98%) rename lib/{privatebin => data}/db.php (99%) rename lib/model/{abstract.php => AbstractModel.php} (91%) delete mode 100644 tst/auto.php diff --git a/.gitignore b/.gitignore index 9a3d92c..0323182 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Ignore data/, tmp/ and vendor/ data/ +!lib/data/ tmp/ vendor/ # Ignore for safety diff --git a/composer.json b/composer.json index 1280da3..bd94adf 100644 --- a/composer.json +++ b/composer.json @@ -1,15 +1,14 @@ { "name": "privatebin/privatebin", "description": "PrivateBin is a minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted/decrypted in the browser using 256 bit AES in Galois Counter mode (GCM).", - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/PrivateBin/PrivateBin" - } - ], "license":"zlib-acknowledgement", "require-dev": { "codacy/coverage": "dev-master", "codeclimate/php-test-reporter": "dev-master" + }, + "autoload": { + "psr-4": { + "PrivateBin\\": "lib/" + } } } diff --git a/index.php b/index.php index 06c3617..ec40497 100644 --- a/index.php +++ b/index.php @@ -14,5 +14,5 @@ define('PATH', ''); define('PUBLIC_PATH', dirname(__FILE__)); -require PATH . 'lib/auto.php'; -new privatebin; +require __DIR__ . '/vendor/autoload.php'; +new PrivateBin\privatebin; diff --git a/lib/auto.php b/lib/auto.php deleted file mode 100644 index 30ef778..0000000 --- a/lib/auto.php +++ /dev/null @@ -1,38 +0,0 @@ -_conf, $this->_getStore()); + $paste = new paste($this->_conf, $this->_getStore()); if ($pasteId !== null) $paste->setId($pasteId); return $paste; } @@ -76,10 +80,18 @@ class model */ private function _getStore() { + // FIXME + // Workaround so that config value don't need to be changed + $callable = str_replace( + array('privatebin_data', 'privatebin_db'), + array('PrivateBin\\data\\data', 'PrivateBin\\data\\db'), + $this->_conf->getKey('class', 'model') + ); + if ($this->_store === null) { $this->_store = forward_static_call( - array($this->_conf->getKey('class', 'model'), 'getInstance'), + array($callable, 'getInstance'), $this->_conf->getSection('model_options') ); } diff --git a/lib/model/abstract.php b/lib/model/AbstractModel.php similarity index 91% rename from lib/model/abstract.php rename to lib/model/AbstractModel.php index 5e0435d..c7979b2 100644 --- a/lib/model/abstract.php +++ b/lib/model/AbstractModel.php @@ -10,12 +10,20 @@ * @version 0.22 */ +namespace PrivateBin\Model; + +use Exception; +use PrivateBin\configuration; +use PrivateBin\data\AbstractData; +use PrivateBin\sjcl; +use stdClass; + /** * model_abstract * * Abstract model for PrivateBin objects. */ -abstract class model_abstract +abstract class AbstractModel { /** * Instance ID. @@ -57,7 +65,7 @@ abstract class model_abstract * @param privatebin_abstract $storage * @return void */ - public function __construct(configuration $configuration, privatebin_abstract $storage) + public function __construct(configuration $configuration, AbstractData $storage) { $this->_conf = $configuration; $this->_store = $storage; diff --git a/lib/model/comment.php b/lib/model/comment.php index 011649d..42057ab 100644 --- a/lib/model/comment.php +++ b/lib/model/comment.php @@ -10,12 +10,19 @@ * @version 0.22 */ +namespace PrivateBin\model; + +use Exception; +use PrivateBin\sjcl; +use PrivateBin\trafficlimiter; +use PrivateBin\vizhash16x16; + /** * model_comment * * Model of a PrivateBin comment. */ -class model_comment extends model_abstract +class comment extends AbstractModel { /** * Instance's parent. @@ -118,7 +125,7 @@ class model_comment extends model_abstract * @throws Exception * @return void */ - public function setPaste(model_paste $paste) + public function setPaste(paste $paste) { $this->_paste = $paste; $this->_data->meta->pasteid = $paste->getId(); diff --git a/lib/model/paste.php b/lib/model/paste.php index 57b86b6..4294614 100644 --- a/lib/model/paste.php +++ b/lib/model/paste.php @@ -10,12 +10,19 @@ * @version 0.22 */ +namespace PrivateBin\model; + +use Exception; +use PrivateBin\privatebin; +use PrivateBin\serversalt; +use PrivateBin\sjcl; + /** * model_paste * * Model of a PrivateBin paste. */ -class model_paste extends model_abstract +class paste extends AbstractModel { /** * Get paste data. @@ -130,7 +137,7 @@ class model_paste extends model_abstract { throw new Exception('Invalid data.', 62); } - $comment = new model_comment($this->_conf, $this->_store); + $comment = new comment($this->_conf, $this->_store); $comment->setPaste($this); $comment->setParentId($parentId); if ($commentId !== null) $comment->setId($commentId); diff --git a/lib/persistence.php b/lib/persistence.php index d65f844..28259de 100644 --- a/lib/persistence.php +++ b/lib/persistence.php @@ -10,6 +10,10 @@ * @version 0.22 */ +namespace PrivateBin; + +use Exception; + /** * persistence * diff --git a/lib/privatebin.php b/lib/privatebin.php index eb6f9cb..f1f15a8 100644 --- a/lib/privatebin.php +++ b/lib/privatebin.php @@ -10,6 +10,10 @@ * @version 0.22 */ +namespace PrivateBin; + +use Exception; + /** * privatebin * @@ -419,7 +423,7 @@ class privatebin } // translate all the formatter options - $formatters = array_map(array('i18n', 'translate'), $this->_conf->getSection('formatter_options')); + $formatters = array_map(array('PrivateBin\\i18n', 'translate'), $this->_conf->getSection('formatter_options')); // set language cookie if that functionality was enabled $languageselection = ''; diff --git a/lib/purgelimiter.php b/lib/purgelimiter.php index d8c595a..36fa9ce 100644 --- a/lib/purgelimiter.php +++ b/lib/purgelimiter.php @@ -10,6 +10,8 @@ * @version 0.22 */ +namespace PrivateBin; + /** * purgelimiter * diff --git a/lib/request.php b/lib/request.php index 1339e84..d5d9c9d 100644 --- a/lib/request.php +++ b/lib/request.php @@ -10,6 +10,8 @@ * @version 0.22 */ +namespace PrivateBin; + /** * request * diff --git a/lib/serversalt.php b/lib/serversalt.php index 91cfcdc..fe28fef 100644 --- a/lib/serversalt.php +++ b/lib/serversalt.php @@ -10,6 +10,10 @@ * @version 0.22 */ +namespace PrivateBin; + +use Exception; + /** * serversalt * diff --git a/lib/sjcl.php b/lib/sjcl.php index ae09c9c..cc79cea 100644 --- a/lib/sjcl.php +++ b/lib/sjcl.php @@ -10,6 +10,8 @@ * @version 0.22 */ +namespace PrivateBin; + /** * sjcl * diff --git a/lib/trafficlimiter.php b/lib/trafficlimiter.php index b0fc5a7..ed1f534 100644 --- a/lib/trafficlimiter.php +++ b/lib/trafficlimiter.php @@ -10,6 +10,8 @@ * @version 0.22 */ +namespace PrivateBin; + /** * trafficlimiter * diff --git a/lib/view.php b/lib/view.php index 4595200..a63c2d2 100644 --- a/lib/view.php +++ b/lib/view.php @@ -10,6 +10,10 @@ * @version 0.22 */ +namespace PrivateBin; + +use Exception; + /** * view * diff --git a/lib/vizhash16x16.php b/lib/vizhash16x16.php index 47b725d..314a399 100644 --- a/lib/vizhash16x16.php +++ b/lib/vizhash16x16.php @@ -11,6 +11,8 @@ * @version 0.0.4 beta PrivateBin 0.22 */ +namespace PrivateBin; + /** * vizhash16x16 * diff --git a/tpl/bootstrap-compact.php b/tpl/bootstrap-compact.php index e39652e..7d299ad 100644 --- a/tpl/bootstrap-compact.php +++ b/tpl/bootstrap-compact.php @@ -5,7 +5,7 @@ - <?php echo i18n::_('PrivateBin'); ?> + <?php echo PrivateBin\i18n::_('PrivateBin'); ?>
@@ -202,9 +202,9 @@ endif; ?> - - -
@@ -238,16 +238,16 @@ endif; ?>
-

-

+

-

- in the browser using 256 bits AES. More information on the project page.'); ?> + in the browser using 256 bits AES. More information on the project page.'); ?>

diff --git a/tpl/bootstrap-dark-page.php b/tpl/bootstrap-dark-page.php index 8f264cd..10cb75d 100644 --- a/tpl/bootstrap-dark-page.php +++ b/tpl/bootstrap-dark-page.php @@ -5,7 +5,7 @@ - <?php echo i18n::_('PrivateBin'); ?> + <?php echo PrivateBin\i18n::_('PrivateBin'); ?>
  • checked="checked" /> - +
  • checked="checked" /> - +
  • checked="checked" /> - +
  • diff --git a/tpl/bootstrap-dark-page.php b/tpl/bootstrap-dark-page.php index 10cb75d..5ea66f9 100644 --- a/tpl/bootstrap-dark-page.php +++ b/tpl/bootstrap-dark-page.php @@ -11,9 +11,9 @@ + if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?> @@ -72,8 +72,8 @@ endif; ?> @@ -102,8 +102,8 @@ if ($DISCUSSION): ?> @@ -137,8 +137,8 @@ endif; ?> @@ -158,13 +158,13 @@ if (strlen($LANGUAGESELECTION)): ?> diff --git a/tpl/bootstrap-dark.php b/tpl/bootstrap-dark.php index 3444647..2e0aae1 100644 --- a/tpl/bootstrap-dark.php +++ b/tpl/bootstrap-dark.php @@ -11,9 +11,9 @@ + if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?> @@ -72,8 +72,8 @@ endif; ?> @@ -102,8 +102,8 @@ if ($DISCUSSION): ?> @@ -137,8 +137,8 @@ endif; ?> @@ -158,13 +158,13 @@ if (strlen($LANGUAGESELECTION)): ?> diff --git a/tpl/bootstrap-page.php b/tpl/bootstrap-page.php index 1bcf4ec..e4d979e 100644 --- a/tpl/bootstrap-page.php +++ b/tpl/bootstrap-page.php @@ -11,9 +11,9 @@ + if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?> @@ -72,8 +72,8 @@ endif; ?> @@ -102,8 +102,8 @@ if ($DISCUSSION): ?> @@ -137,8 +137,8 @@ endif; ?> @@ -158,13 +158,13 @@ if (strlen($LANGUAGESELECTION)): ?> diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index e246418..ea1476f 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -11,9 +11,9 @@ + if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?> @@ -72,8 +72,8 @@ endif; ?> @@ -102,8 +102,8 @@ if ($DISCUSSION): ?> @@ -137,8 +137,8 @@ endif; ?> @@ -158,13 +158,13 @@ if (strlen($LANGUAGESELECTION)): ?> diff --git a/tpl/page.php b/tpl/page.php index 897f9a4..3cdae63 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -7,9 +7,9 @@ + if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?> @@ -70,8 +70,8 @@ endif; ?> @@ -85,11 +85,11 @@ endif; ?> /> if ($DISCUSSION): ?> @@ -101,19 +101,19 @@ endif; ?>
    diff --git a/tst/bootstrap.php b/tst/bootstrap.php index d1cb374..af03a15 100644 --- a/tst/bootstrap.php +++ b/tst/bootstrap.php @@ -2,13 +2,21 @@ use PrivateBin\serversalt; -error_reporting( E_ALL | E_STRICT ); +error_reporting(E_ALL | E_STRICT); // change this, if your php files and data is outside of your webservers document root -if (!defined('PUBLIC_PATH')) define('PUBLIC_PATH', '..'); -if (!defined('PATH')) define('PATH', '..' . DIRECTORY_SEPARATOR); -if (!defined('CONF')) define('CONF', PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini'); -if (!is_file(CONF)) copy(CONF . '.sample', CONF); +if (!defined('PUBLIC_PATH')) { + define('PUBLIC_PATH', '..'); +} +if (!defined('PATH')) { + define('PATH', '..' . DIRECTORY_SEPARATOR); +} +if (!defined('CONF')) { + define('CONF', PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini'); +} +if (!is_file(CONF)) { + copy(CONF . '.sample', CONF); +} require PATH . 'vendor/autoload.php'; @@ -103,8 +111,9 @@ class helper $example = self::getPaste(); // the JSON shouldn't contain the salt unset($example['meta']['salt']); - if (count($meta)) + if (count($meta)) { $example['meta'] = $meta; + } $example['comments'] = array(); $example['comment_count'] = 0; $example['comment_offset'] = 0; @@ -157,19 +166,19 @@ class helper { $path .= DIRECTORY_SEPARATOR; $dir = dir($path); - while(false !== ($file = $dir->read())) { - if($file != '.' && $file != '..') { - if(is_dir($path . $file)) { + while (false !== ($file = $dir->read())) { + if ($file != '.' && $file != '..') { + if (is_dir($path . $file)) { self::rmdir($path . $file); - } elseif(is_file($path . $file)) { - if(!@unlink($path . $file)) { + } elseif (is_file($path . $file)) { + if (!@unlink($path . $file)) { throw new Exception('Error deleting file "' . $path . $file . '".'); } } } } $dir->close(); - if(!@rmdir($path)) { + if (!@rmdir($path)) { throw new Exception('Error deleting directory "' . $path . '".'); } } @@ -181,8 +190,9 @@ class helper */ public static function confBackup() { - if (!is_file(CONF . '.bak') && is_file(CONF)) + if (!is_file(CONF . '.bak') && is_file(CONF)) { rename(CONF, CONF . '.bak'); + } } /** @@ -192,8 +202,9 @@ class helper */ public static function confRestore() { - if (is_file(CONF . '.bak')) + if (is_file(CONF . '.bak')) { rename(CONF . '.bak', CONF); + } } /** @@ -209,7 +220,7 @@ class helper $ini = fopen($pathToFile, 'a'); foreach ($values as $section => $options) { fwrite($ini, "[$section]" . PHP_EOL); - foreach($options as $option => $setting) { + foreach ($options as $option => $setting) { if (is_null($setting)) { continue; } elseif (is_string($setting)) { diff --git a/tst/configGenerator.php b/tst/configGenerator.php index 64081d5..a0fc088 100755 --- a/tst/configGenerator.php +++ b/tst/configGenerator.php @@ -388,7 +388,8 @@ class configurationTestGenerator * constructor, generates the configuration test * @param array $options */ - public function __construct($options) { + public function __construct($options) + { $this->_options = $options; // generate all possible combinations of options: options^settings $this->_generateConfigurations(); @@ -418,7 +419,7 @@ class configurationTestGenerator while (list($path, $setting) = each($test['conditions'])) { if ($path == 'steps' && !in_array($step, $setting)) { continue 2; - } elseif($path != 'steps') { + } elseif ($path != 'steps') { list($section, $option) = explode('/', $path); if ($fullOptions[$section][$option] !== $setting) { continue 2; @@ -653,7 +654,8 @@ EOT; * @throws Exception * @return array */ - private function _addSetting(&$configuration, &$setting, &$section, &$option) { + private function _addSetting(&$configuration, &$setting, &$section, &$option) + { if (++$this->_iterationCount > self::MAX_ITERATIONS) { echo 'max iterations reached, stopping', PHP_EOL; return $configuration; diff --git a/tst/configuration.php b/tst/configuration.php index 8ee44cb..43950bb 100644 --- a/tst/configuration.php +++ b/tst/configuration.php @@ -135,5 +135,4 @@ class configurationTest extends PHPUnit_Framework_TestCase $conf = new configuration; $this->assertEquals('PrivateBin\data\db', $conf->getKey('class', 'model'), 'old db class gets renamed'); } - } diff --git a/tst/jsonApi.php b/tst/jsonApi.php index ccfc220..0c57236 100644 --- a/tst/jsonApi.php +++ b/tst/jsonApi.php @@ -28,8 +28,9 @@ class jsonApiTest extends PHPUnit_Framework_TestCase $_POST = array(); $_GET = array(); $_SERVER = array(); - if ($this->_model->exists(helper::getPasteId())) + if ($this->_model->exists(helper::getPasteId())) { $this->_model->delete(helper::getPasteId()); + } helper::confRestore(); } @@ -263,5 +264,4 @@ class jsonApiTest extends PHPUnit_Framework_TestCase $content = ob_get_contents(); $this->assertEquals('{}', $content, 'does not output nasty data'); } - } diff --git a/tst/model.php b/tst/model.php index 6fc9ec8..4244253 100644 --- a/tst/model.php +++ b/tst/model.php @@ -227,31 +227,23 @@ class modelTest extends PHPUnit_Framework_TestCase $paste = helper::getPaste(array('expire_date' => time() + 3600)); $keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'x', 'y', 'z'); $ids = array(); - foreach ($keys as $key) - { + foreach ($keys as $key) { $ids[$key] = substr(md5($key), 0, 16); $store->delete($ids[$key]); $this->assertFalse($store->exists($ids[$key]), "paste $key does not yet exist"); - if (in_array($key, array('x', 'y', 'z'))) - { + if (in_array($key, array('x', 'y', 'z'))) { $this->assertTrue($store->create($ids[$key], $paste), "store $key paste"); - } - else - { + } else { $this->assertTrue($store->create($ids[$key], $expired), "store $key paste"); } $this->assertTrue($store->exists($ids[$key]), "paste $key exists after storing it"); } $this->_model->purge(10); - foreach ($ids as $key => $id) - { - if (in_array($key, array('x', 'y', 'z'))) - { + foreach ($ids as $key => $id) { + if (in_array($key, array('x', 'y', 'z'))) { $this->assertTrue($this->_model->getPaste($id)->exists(), "paste $key exists after purge"); $this->_model->getPaste($id)->delete(); - } - else - { + } else { $this->assertFalse($this->_model->getPaste($id)->exists(), "paste $key was purged"); } } diff --git a/tst/privatebin.php b/tst/privatebin.php index eccffdf..c3848a3 100644 --- a/tst/privatebin.php +++ b/tst/privatebin.php @@ -27,8 +27,9 @@ class privatebinTest extends PHPUnit_Framework_TestCase $_POST = array(); $_GET = array(); $_SERVER = array(); - if ($this->_model->exists(helper::getPasteId())) + if ($this->_model->exists(helper::getPasteId())) { $this->_model->delete(helper::getPasteId()); + } helper::confRestore(); } diff --git a/tst/privatebin/data.php b/tst/privatebin/data.php index 9248a7a..79a2b09 100644 --- a/tst/privatebin/data.php +++ b/tst/privatebin/data.php @@ -73,30 +73,22 @@ class privatebin_dataTest extends PHPUnit_Framework_TestCase $paste = helper::getPaste(array('expire_date' => time() + 3600)); $keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'x', 'y', 'z'); $ids = array(); - foreach ($keys as $key) - { + foreach ($keys as $key) { $ids[$key] = substr(md5($key), 0, 16); $this->assertFalse($this->_model->exists($ids[$key]), "paste $key does not yet exist"); - if (in_array($key, array('x', 'y', 'z'))) - { + if (in_array($key, array('x', 'y', 'z'))) { $this->assertTrue($this->_model->create($ids[$key], $paste), "store $key paste"); - } - else - { + } else { $this->assertTrue($this->_model->create($ids[$key], $expired), "store $key paste"); } $this->assertTrue($this->_model->exists($ids[$key]), "paste $key exists after storing it"); } $this->_model->purge(10); - foreach ($ids as $key => $id) - { - if (in_array($key, array('x', 'y', 'z'))) - { + foreach ($ids as $key => $id) { + if (in_array($key, array('x', 'y', 'z'))) { $this->assertTrue($this->_model->exists($id), "paste $key exists after purge"); $this->_model->delete($id); - } - else - { + } else { $this->assertFalse($this->_model->exists($id), "paste $key was purged"); } } diff --git a/tst/privatebin/db.php b/tst/privatebin/db.php index 6a48b02..b5bf8f3 100644 --- a/tst/privatebin/db.php +++ b/tst/privatebin/db.php @@ -22,7 +22,9 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase public function tearDown() { /* Tear Down Routine */ - if (is_dir(PATH . 'data')) helper::rmdir(PATH . 'data'); + if (is_dir(PATH . 'data')) { + helper::rmdir(PATH . 'data'); + } } public function testDatabaseBasedDataStoreWorks() @@ -78,31 +80,23 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase $paste = helper::getPaste(array('expire_date' => time() + 3600)); $keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'x', 'y', 'z'); $ids = array(); - foreach ($keys as $key) - { + foreach ($keys as $key) { $ids[$key] = substr(md5($key), 0, 16); $this->_model->delete($ids[$key]); $this->assertFalse($this->_model->exists($ids[$key]), "paste $key does not yet exist"); - if (in_array($key, array('x', 'y', 'z'))) - { + if (in_array($key, array('x', 'y', 'z'))) { $this->assertTrue($this->_model->create($ids[$key], $paste), "store $key paste"); - } - else - { + } else { $this->assertTrue($this->_model->create($ids[$key], $expired), "store $key paste"); } $this->assertTrue($this->_model->exists($ids[$key]), "paste $key exists after storing it"); } $this->_model->purge(10); - foreach ($ids as $key => $id) - { - if (in_array($key, array('x', 'y', 'z'))) - { + foreach ($ids as $key => $id) { + if (in_array($key, array('x', 'y', 'z'))) { $this->assertTrue($this->_model->exists($id), "paste $key exists after purge"); $this->_model->delete($id); - } - else - { + } else { $this->assertFalse($this->_model->exists($id), "paste $key was purged"); } } diff --git a/tst/privatebinWithDb.php b/tst/privatebinWithDb.php index 569454f..9df0a24 100644 --- a/tst/privatebinWithDb.php +++ b/tst/privatebinWithDb.php @@ -24,7 +24,9 @@ class privatebinWithDbTest extends privatebinTest { /* Setup Routine */ $this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data'; - if(!is_dir($this->_path)) mkdir($this->_path); + if (!is_dir($this->_path)) { + mkdir($this->_path); + } $this->_options['dsn'] = 'sqlite:' . $this->_path . DIRECTORY_SEPARATOR . 'tst.sq3'; $this->_model = db::getInstance($this->_options); $this->reset(); diff --git a/tst/purgelimiter.php b/tst/purgelimiter.php index ffe816a..127698b 100644 --- a/tst/purgelimiter.php +++ b/tst/purgelimiter.php @@ -10,7 +10,9 @@ class purgelimiterTest extends PHPUnit_Framework_TestCase { /* Setup Routine */ $this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data'; - if(!is_dir($this->_path)) mkdir($this->_path); + if (!is_dir($this->_path)) { + mkdir($this->_path); + } purgelimiter::setPath($this->_path); } diff --git a/tst/serversalt.php b/tst/serversalt.php index 9e3ac97..7b5c67a 100644 --- a/tst/serversalt.php +++ b/tst/serversalt.php @@ -16,13 +16,17 @@ class serversaltTest extends PHPUnit_Framework_TestCase { /* Setup Routine */ $this->_path = PATH . 'data'; - if(!is_dir($this->_path)) mkdir($this->_path); + if (!is_dir($this->_path)) { + mkdir($this->_path); + } serversalt::setPath($this->_path); $this->_otherPath = $this->_path . DIRECTORY_SEPARATOR . 'foo'; $this->_invalidPath = $this->_path . DIRECTORY_SEPARATOR . 'bar'; - if(!is_dir($this->_invalidPath)) mkdir($this->_invalidPath); + if (!is_dir($this->_invalidPath)) { + mkdir($this->_invalidPath); + } $this->_invalidFile = $this->_invalidPath . DIRECTORY_SEPARATOR . 'salt.php'; } @@ -40,18 +44,18 @@ class serversaltTest extends PHPUnit_Framework_TestCase $salt = serversalt::get(); // mcrypt mock - if (!function_exists('mcrypt_create_iv')) - { - if (!defined('MCRYPT_DEV_URANDOM')) define('MCRYPT_DEV_URANDOM', 1); + if (!function_exists('mcrypt_create_iv')) { + if (!defined('MCRYPT_DEV_URANDOM')) { + define('MCRYPT_DEV_URANDOM', 1); + } function mcrypt_create_iv($int, $flag) { $randomSalt = ''; - for($i = 0; $i < $int; ++$i) { + for ($i = 0; $i < $int; ++$i) { $randomSalt .= base_convert(mt_rand(), 10, 16); } // hex2bin requires an even length, pad if necessary - if (strlen($randomSalt) % 2) - { + if (strlen($randomSalt) % 2) { $randomSalt = '0' . $randomSalt; } return hex2bin($randomSalt); diff --git a/tst/vizhash16x16.php b/tst/vizhash16x16.php index 005332e..a0e0850 100644 --- a/tst/vizhash16x16.php +++ b/tst/vizhash16x16.php @@ -13,7 +13,9 @@ class vizhash16x16Test extends PHPUnit_Framework_TestCase { /* Setup Routine */ $this->_path = PATH . 'data'; - if(!is_dir($this->_path)) mkdir($this->_path); + if (!is_dir($this->_path)) { + mkdir($this->_path); + } $this->_file = $this->_path . DIRECTORY_SEPARATOR . 'vizhash.png'; serversalt::setPath($this->_path); } @@ -22,7 +24,7 @@ class vizhash16x16Test extends PHPUnit_Framework_TestCase { /* Tear Down Routine */ chmod($this->_path, 0700); - if(!@unlink($this->_file)) { + if (!@unlink($this->_file)) { throw new Exception('Error deleting file "' . $this->_file . '".'); } helper::rmdir($this->_path);