Convert to PSR-2 coding style (using phpcs-fixer)
This commit is contained in:
@@ -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)) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user