whitespace

This commit is contained in:
Simon Wisselink
2022-09-22 23:55:25 +02:00
parent 2aa0b3f855
commit 965275d04f
15 changed files with 112 additions and 112 deletions

View File

@ -21,16 +21,16 @@
*/
function smarty_modifier_count($arrayOrObject, $mode = 0)
{
/*
* @see https://www.php.net/count
* > Prior to PHP 8.0.0, if the parameter was neither an array nor an object that implements the Countable interface,
* > 1 would be returned, unless value was null, in which case 0 would be returned.
*/
/*
* @see https://www.php.net/count
* > Prior to PHP 8.0.0, if the parameter was neither an array nor an object that implements the Countable interface,
* > 1 would be returned, unless value was null, in which case 0 would be returned.
*/
if ($arrayOrObject instanceof Countable || is_array($arrayOrObject)) {
return count($arrayOrObject, (int) $mode);
} elseif ($arrayOrObject === null) {
return 0;
}
return 1;
if ($arrayOrObject instanceof Countable || is_array($arrayOrObject)) {
return count($arrayOrObject, (int) $mode);
} elseif ($arrayOrObject === null) {
return 0;
}
return 1;
}

View File

@ -19,5 +19,5 @@
* @return string with compiled code
*/
function smarty_modifiercompiler_nl2br($params) {
return 'nl2br((string) ' . $params[0] . ', (bool) ' . ($params[1] ?? true) . ')';
return 'nl2br((string) ' . $params[0] . ', (bool) ' . ($params[1] ?? true) . ')';
}

View File

@ -19,5 +19,5 @@
* @return string with compiled code
*/
function smarty_modifiercompiler_round($params) {
return 'round((float) ' . $params[0] . ', (int) ' . ($params[1] ?? 0) . ', (int) ' . ($params[2] ?? PHP_ROUND_HALF_UP) . ')';
return 'round((float) ' . $params[0] . ', (int) ' . ($params[1] ?? 0) . ', (int) ' . ($params[2] ?? PHP_ROUND_HALF_UP) . ')';
}

View File

@ -19,5 +19,5 @@
* @return string with compiled code
*/
function smarty_modifiercompiler_str_repeat($params) {
return 'str_repeat((string) ' . $params[0] . ', (int) ' . $params[1] . ')';
return 'str_repeat((string) ' . $params[0] . ', (int) ' . $params[1] . ')';
}

View File

@ -19,5 +19,5 @@
* @return string with compiled code
*/
function smarty_modifiercompiler_strlen($params) {
return 'strlen((string) ' . $params[0] . ')';
return 'strlen((string) ' . $params[0] . ')';
}

View File

@ -109,9 +109,9 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
if (!is_object($compiler->smarty->security_policy)
|| $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)
) {
trigger_error('Using php-function "' . $modifier . '" as a modifier is deprecated and will be ' .
'removed in a future release. Use Smarty::registerPlugin to explicitly register ' .
'a custom modifier.', E_USER_DEPRECATED);
trigger_error('Using php-function "' . $modifier . '" as a modifier is deprecated and will be ' .
'removed in a future release. Use Smarty::registerPlugin to explicitly register ' .
'a custom modifier.', E_USER_DEPRECATED);
$output = "{$modifier}({$params})";
}
$compiler->known_modifier_type[ $modifier ] = $type;

View File

@ -21,7 +21,7 @@ class CompileAppendTest extends PHPUnit_Smarty
$this->smarty->addPluginsDir("../../../__shared/PHPunitplugins/");
$this->smarty->addTemplateDir("../../../__shared/templates/");
$this->smarty->addTemplateDir("./templates_tmp");
$this->smarty->registerPlugin('modifier', 'var_export', 'var_export');
$this->smarty->registerPlugin('modifier', 'var_export', 'var_export');
}
public function testInit()

View File

@ -21,7 +21,7 @@ class CompileAssignTest extends PHPUnit_Smarty
$this->smarty->addPluginsDir("../../../__shared/PHPunitplugins/");
$this->smarty->addTemplateDir("../../../__shared/templates/");
$this->smarty->addTemplateDir("./templates_tmp");
$this->smarty->registerPlugin('modifier', 'var_export', 'var_export');
$this->smarty->registerPlugin('modifier', 'var_export', 'var_export');
}
public function testInit()

View File

@ -21,7 +21,7 @@ class CompileIfTest extends PHPUnit_Smarty
$this->smarty->addPluginsDir("../../../__shared/PHPunitplugins/");
$this->smarty->addTemplateDir("../../../__shared/templates/");
$this->smarty->addTemplateDir("./templates_tmp");
$this->smarty->registerPlugin('modifier', 'var_export', 'var_export');
$this->smarty->registerPlugin('modifier', 'var_export', 'var_export');
}
public function testInit()

View File

@ -12,37 +12,37 @@
*/
class PluginModifierCountTest extends PHPUnit_Smarty
{
public function setUp(): void
{
$this->setUpSmarty(dirname(__FILE__));
}
public function setUp(): void
{
$this->setUpSmarty(dirname(__FILE__));
}
public function testArray()
{
$tpl = $this->smarty->createTemplate('string:count:{$v|count}');
$tpl->assign("v", array(1, 2, 3));
$this->assertEquals("count:3", $this->smarty->fetch($tpl));
}
public function testArray()
{
$tpl = $this->smarty->createTemplate('string:count:{$v|count}');
$tpl->assign("v", array(1, 2, 3));
$this->assertEquals("count:3", $this->smarty->fetch($tpl));
}
public function testEmptyArray()
{
$tpl = $this->smarty->createTemplate('string:count:{$v|count}');
$tpl->assign("v", array());
$this->assertEquals("count:0", $this->smarty->fetch($tpl));
}
public function testEmptyArray()
{
$tpl = $this->smarty->createTemplate('string:count:{$v|count}');
$tpl->assign("v", array());
$this->assertEquals("count:0", $this->smarty->fetch($tpl));
}
public function testNull()
{
$tpl = $this->smarty->createTemplate('string:count:{$v|count}');
$tpl->assign("v", null);
$this->assertEquals("count:0", $this->smarty->fetch($tpl));
}
public function testNull()
{
$tpl = $this->smarty->createTemplate('string:count:{$v|count}');
$tpl->assign("v", null);
$this->assertEquals("count:0", $this->smarty->fetch($tpl));
}
public function testString()
{
$tpl = $this->smarty->createTemplate('string:count:{$v|count}');
$tpl->assign("v", "string");
$this->assertEquals("count:1", $this->smarty->fetch($tpl));
}
public function testString()
{
$tpl = $this->smarty->createTemplate('string:count:{$v|count}');
$tpl->assign("v", "string");
$this->assertEquals("count:1", $this->smarty->fetch($tpl));
}
}

View File

@ -14,7 +14,7 @@ class PluginModifierExplodeTest extends \PHPUnit_Smarty
public function setUp(): void
{
$this->setUpSmarty(__DIR__);
$this->smarty->registerPlugin('modifier', 'json_encode', 'json_encode');
$this->smarty->registerPlugin('modifier', 'json_encode', 'json_encode');
}
/**

View File

@ -12,22 +12,22 @@
*/
class PluginModifierNl2brTest extends PHPUnit_Smarty
{
public function setUp(): void
{
$this->setUpSmarty(dirname(__FILE__));
}
public function setUp(): void
{
$this->setUpSmarty(dirname(__FILE__));
}
public function testDefault()
{
$tpl = $this->smarty->createTemplate('string:{$v|nl2br}');
$tpl->assign("v", "Line1\nLine2");
$this->assertEquals("Line1<br />\nLine2", $this->smarty->fetch($tpl));
}
public function testDefault()
{
$tpl = $this->smarty->createTemplate('string:{$v|nl2br}');
$tpl->assign("v", "Line1\nLine2");
$this->assertEquals("Line1<br />\nLine2", $this->smarty->fetch($tpl));
}
public function testNoXHTML()
{
$tpl = $this->smarty->createTemplate('string:{$v|nl2br:false}');
$tpl->assign("v", "Line1\nLine2");
$this->assertEquals("Line1<br>\nLine2", $this->smarty->fetch($tpl));
}
public function testNoXHTML()
{
$tpl = $this->smarty->createTemplate('string:{$v|nl2br:false}');
$tpl->assign("v", "Line1\nLine2");
$this->assertEquals("Line1<br>\nLine2", $this->smarty->fetch($tpl));
}
}

View File

@ -12,22 +12,22 @@
*/
class PluginModifierStrRepeatTest extends PHPUnit_Smarty
{
public function setUp(): void
{
$this->setUpSmarty(dirname(__FILE__));
}
public function setUp(): void
{
$this->setUpSmarty(dirname(__FILE__));
}
public function testDefault()
{
$tpl = $this->smarty->createTemplate('string:{$v|str_repeat:2}');
$tpl->assign("v", "foo");
$this->assertEquals("foofoo", $this->smarty->fetch($tpl));
}
public function testDefault()
{
$tpl = $this->smarty->createTemplate('string:{$v|str_repeat:2}');
$tpl->assign("v", "foo");
$this->assertEquals("foofoo", $this->smarty->fetch($tpl));
}
public function testZeroTimes()
{
$tpl = $this->smarty->createTemplate('string:{$v|str_repeat:0}');
$tpl->assign("v", "foo");
$this->assertEquals("", $this->smarty->fetch($tpl));
}
public function testZeroTimes()
{
$tpl = $this->smarty->createTemplate('string:{$v|str_repeat:0}');
$tpl->assign("v", "foo");
$this->assertEquals("", $this->smarty->fetch($tpl));
}
}

View File

@ -18,7 +18,7 @@ class MathTest extends PHPUnit_Smarty
public function setUp(): void
{
$this->setUpSmarty(dirname(__FILE__));
$this->smarty->registerPlugin('modifier', 'sin', 'sin');
$this->smarty->registerPlugin('modifier', 'sin', 'sin');
}
public function testInit()
@ -133,36 +133,36 @@ class MathTest extends PHPUnit_Smarty
$this->assertEquals($expected, $this->smarty->fetch($tpl));
}
public function testBackticksIllegal()
{
$this->expectException(PHPUnit\Framework\Error\Warning::class);
$expected = "22.00";
$tpl = $this->smarty->createTemplate('eval:{$x = "4"}{$y = "5.5"}{math equation="`ls` x * y" x=$x y=$y}');
$this->assertEquals($expected, $this->smarty->fetch($tpl));
}
public function testBackticksIllegal()
{
$this->expectException(PHPUnit\Framework\Error\Warning::class);
$expected = "22.00";
$tpl = $this->smarty->createTemplate('eval:{$x = "4"}{$y = "5.5"}{math equation="`ls` x * y" x=$x y=$y}');
$this->assertEquals($expected, $this->smarty->fetch($tpl));
}
public function testDollarSignsIllegal()
{
$this->expectException(PHPUnit\Framework\Error\Warning::class);
$expected = "22.00";
$tpl = $this->smarty->createTemplate('eval:{$x = "4"}{$y = "5.5"}{math equation="$" x=$x y=$y}');
$this->assertEquals($expected, $this->smarty->fetch($tpl));
}
public function testDollarSignsIllegal()
{
$this->expectException(PHPUnit\Framework\Error\Warning::class);
$expected = "22.00";
$tpl = $this->smarty->createTemplate('eval:{$x = "4"}{$y = "5.5"}{math equation="$" x=$x y=$y}');
$this->assertEquals($expected, $this->smarty->fetch($tpl));
}
public function testBracketsIllegal()
{
$this->expectException(PHPUnit\Framework\Error\Warning::class);
$expected = "I";
$tpl = $this->smarty->createTemplate('eval:{$x = "0"}{$y = "1"}{math equation="((y/x).(x))[x]" x=$x y=$y}');
$this->assertEquals($expected, $this->smarty->fetch($tpl));
}
public function testBracketsIllegal()
{
$this->expectException(PHPUnit\Framework\Error\Warning::class);
$expected = "I";
$tpl = $this->smarty->createTemplate('eval:{$x = "0"}{$y = "1"}{math equation="((y/x).(x))[x]" x=$x y=$y}');
$this->assertEquals($expected, $this->smarty->fetch($tpl));
}
public function testRand()
{
$tpl = $this->smarty->createTemplate('eval:{$x = "0"}{math equation="x * rand()" x=$x}');
// this assertion may seem silly, but it serves to prove that using rand() without a parameter
// will not trigger a security error (see https://github.com/smarty-php/smarty/issues/794)
$this->assertEquals("0", $this->smarty->fetch($tpl));
}
public function testRand()
{
$tpl = $this->smarty->createTemplate('eval:{$x = "0"}{math equation="x * rand()" x=$x}');
// this assertion may seem silly, but it serves to prove that using rand() without a parameter
// will not trigger a security error (see https://github.com/smarty-php/smarty/issues/794)
$this->assertEquals("0", $this->smarty->fetch($tpl));
}
}

View File

@ -18,7 +18,7 @@ class ModifierIssue327Test extends PHPUnit_Smarty
public function setUp(): void
{
$this->setUpSmarty(dirname(__FILE__));
$this->smarty->registerPlugin('modifier', 'substr', 'substr');
$this->smarty->registerPlugin('modifier', 'substr', 'substr');
}
public function testInit()