Skip to content

Commit

Permalink
Add :string method signature to compile method everywhere.
Browse files Browse the repository at this point in the history
  • Loading branch information
wisskid committed Mar 25, 2024
1 parent 43a3bc9 commit ccc9543
Show file tree
Hide file tree
Showing 50 changed files with 101 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/Compile/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,5 +229,5 @@ protected function convertScope($scope): int {
* @return string compiled code as a string
* @throws \Smarty\CompilerException
*/
abstract public function compile($args, Template $compiler, $parameter = array(), $tag = null, $function = null);
abstract public function compile($args, Template $compiler, $parameter = array(), $tag = null, $function = null): string;
}
3 changes: 2 additions & 1 deletion src/Compile/BlockCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class BlockCompiler extends Base {
* @throws CompilerException
* @throws Exception
*/
public function compile($args, Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, Template $compiler, $parameter = [], $tag = null, $function = null): string
{

if (!isset($tag[5]) || substr($tag, -5) !== 'close') {
$output = $this->compileOpeningTag($compiler, $args, $tag, $function);
Expand Down
2 changes: 1 addition & 1 deletion src/Compile/CompilerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface CompilerInterface {
* @return string compiled code as a string
* @throws \Smarty\CompilerException
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null);
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string;

public function isCacheable(): bool;
}
3 changes: 2 additions & 1 deletion src/Compile/DefaultHandlerFunctionCallCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class DefaultHandlerFunctionCallCompiler extends Base {
* @throws \Smarty\CompilerException
* @throws \Smarty\Exception
*/
public function compile($args, Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, Template $compiler, $parameter = [], $tag = null, $function = null): string
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
unset($_attr['nocache']);
Expand Down
3 changes: 2 additions & 1 deletion src/Compile/FunctionCallCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class FunctionCallCompiler extends Base {
* @throws \Smarty\CompilerException
* @throws \Smarty\Exception
*/
public function compile($args, Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, Template $compiler, $parameter = [], $tag = null, $function = null): string
{

// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
Expand Down
3 changes: 2 additions & 1 deletion src/Compile/ModifierCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class ModifierCompiler extends Base {
* @throws \Smarty\CompilerException
* @throws \Smarty\Exception
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{

$output = $parameter['value'];

Expand Down
3 changes: 2 additions & 1 deletion src/Compile/ObjectMethodCallCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class ObjectMethodCallCompiler extends Base {
* @throws \Smarty\CompilerException
* @throws \Smarty\Exception
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
unset($_attr['nocache']);
Expand Down
3 changes: 2 additions & 1 deletion src/Compile/PrintExpressionCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class PrintExpressionCompiler extends Base {
* @return string
* @throws \Smarty\Exception
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{

// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
Expand Down
5 changes: 4 additions & 1 deletion src/Compile/SpecialVariableCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class SpecialVariableCompiler extends Base {
* @return string compiled code
* @throws CompilerException
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{

$_index = preg_split("/\]\[/", substr($parameter, 1, strlen($parameter) - 2));
$variable = smarty_strtolower_ascii($compiler->getId($_index[0]));
Expand Down Expand Up @@ -127,5 +128,7 @@ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter =
}
return $compiled_ref;
}

return '';
}
}
4 changes: 2 additions & 2 deletions src/Compile/Tag/Append.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class Append extends Assign
* @return string compiled code
* @throws \Smarty\CompilerException
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null)
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null): string
{

// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
Expand Down
4 changes: 2 additions & 2 deletions src/Compile/Tag/Assign.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class Assign extends Base
* @return string compiled code
* @throws \Smarty\CompilerException
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null)
{
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null): string
{

$_nocache = false;
// check and get attributes
Expand Down
3 changes: 2 additions & 1 deletion src/Compile/Tag/BCPluginWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public function __construct($callback, bool $cacheable = true) {
/**
* @inheritDoc
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
return call_user_func($this->callback, $this->getAttributes($compiler, $args), $compiler->getSmarty());
}
}
2 changes: 1 addition & 1 deletion src/Compile/Tag/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Block extends Inheritance {
* @param \Smarty\Compiler\Template $compiler compiler object
* @param array $parameter array with compilation parameter
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null)
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null): string
{
if (!isset($compiler->_cache['blockNesting'])) {
$compiler->_cache['blockNesting'] = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/Compile/Tag/BlockClose.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class BlockClose extends Inheritance {
*
* @return bool true
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null)
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null): string
{
[$_attr, $_nocache, $_buffer, $_has_nocache_code, $_className] = $this->closeTag($compiler, ['block']);

Expand Down
2 changes: 1 addition & 1 deletion src/Compile/Tag/BreakTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class BreakTag extends Base {
* @return string compiled code
* @throws \Smarty\CompilerException
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null)
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null): string
{
[$levels, $foreachLevels] = $this->checkLevels($args, $compiler);
$output = "<?php ";
Expand Down
3 changes: 2 additions & 1 deletion src/Compile/Tag/Call.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class Call extends Base {
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
// save possible attributes
Expand Down
3 changes: 2 additions & 1 deletion src/Compile/Tag/Capture.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public static function compileSpecialVariable(
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$buffer = $_attr['name'] ?? "'default'";
Expand Down
3 changes: 2 additions & 1 deletion src/Compile/Tag/CaptureClose.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class CaptureClose extends Base {
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{

if (array_pop($compiler->_cache['capture_stack'])) {
// pop the virtual {nocache} tag from the stack.
Expand Down
3 changes: 2 additions & 1 deletion src/Compile/Tag/ConfigLoad.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class ConfigLoad extends Base {
* @return string compiled code
* @throws \Smarty\CompilerException
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) {
Expand Down
3 changes: 2 additions & 1 deletion src/Compile/Tag/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class Debug extends Base {
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
// check and get attributes, may trigger errors
$this->getAttributes($compiler, $args);

Expand Down
3 changes: 2 additions & 1 deletion src/Compile/Tag/ElseIfTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class ElseIfTag extends Base {
* @return string compiled code
* @throws \Smarty\CompilerException
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{

[$nesting, $nocache_pushed] = $this->closeTag($compiler, ['if', 'elseif']);

Expand Down
3 changes: 2 additions & 1 deletion src/Compile/Tag/ElseTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class ElseTag extends Base {
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
[$nesting, $compiler->tag_nocache] = $this->closeTag($compiler, ['if', 'elseif']);
$this->openTag($compiler, 'else', [$nesting, $compiler->tag_nocache]);
return '<?php } else { ?>';
Expand Down
3 changes: 2 additions & 1 deletion src/Compile/Tag/EvalTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class EvalTag extends Base {
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
if (isset($_attr['assign'])) {
Expand Down
3 changes: 2 additions & 1 deletion src/Compile/Tag/ExtendsTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class ExtendsTag extends Inheritance {
* @throws \Smarty\CompilerException
* @throws \Smarty\Exception
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) {
Expand Down
3 changes: 2 additions & 1 deletion src/Compile/Tag/ForClose.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class ForClose extends Base {
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
$compiler->loopNesting--;

[$openTag, $nocache_pushed] = $this->closeTag($compiler, ['for', 'forelse']);
Expand Down
3 changes: 2 additions & 1 deletion src/Compile/Tag/ForElse.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class ForElse extends Base {
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
[$tagName, $nocache_pushed] = $this->closeTag($compiler, ['for']);
$this->openTag($compiler, 'forelse', ['forelse', $nocache_pushed]);
return "<?php }} else { ?>";
Expand Down
3 changes: 2 additions & 1 deletion src/Compile/Tag/ForTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class ForTag extends Base {
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
$compiler->loopNesting++;
if ($parameter === 0) {
$this->required_attributes = ['start', 'to'];
Expand Down
3 changes: 2 additions & 1 deletion src/Compile/Tag/ForeachClose.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class ForeachClose extends Base {
* @return string compiled code
* @throws \Smarty\CompilerException
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
$compiler->loopNesting--;

[$openTag, $nocache_pushed, $localVariablePrefix, $item, $restore] = $this->closeTag($compiler, ['foreach', 'foreachelse']);
Expand Down
3 changes: 2 additions & 1 deletion src/Compile/Tag/ForeachElse.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class ForeachElse extends Base {
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{

[$openTag, $nocache_pushed, $localVariablePrefix, $item, $restore] = $this->closeTag($compiler, ['foreach']);
$this->openTag($compiler, 'foreachelse', ['foreachelse', $nocache_pushed, $localVariablePrefix, $item, false]);
Expand Down
3 changes: 2 additions & 1 deletion src/Compile/Tag/ForeachTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ class ForeachTag extends ForeachSection {
* @throws \Smarty\CompilerException
* @throws \Smarty\Exception
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
$compiler->loopNesting++;
// init
$this->isNamed = false;
Expand Down
5 changes: 3 additions & 2 deletions src/Compile/Tag/FunctionClose.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ class FunctionClose extends Base {
* @param array $args array with attributes from parser
* @param object|\Smarty\Compiler\Template $compiler compiler object
*
* @return bool true
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
$this->compiler = $compiler;
$saved_data = $this->closeTag($compiler, ['function']);
$_attr = $saved_data[0];
Expand Down
5 changes: 3 additions & 2 deletions src/Compile/Tag/FunctionTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ class FunctionTag extends Base {
* @param array $args array with attributes from parser
* @param \Smarty\Compiler\Template $compiler compiler object
*
* @return bool true
* @return string compiled code
* @throws \Smarty\CompilerException
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) {
Expand Down
3 changes: 2 additions & 1 deletion src/Compile/Tag/IfClose.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class IfClose extends Base {
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{

[$nesting, $nocache_pushed] = $this->closeTag($compiler, ['if', 'else', 'elseif']);

Expand Down
3 changes: 2 additions & 1 deletion src/Compile/Tag/IfTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class IfTag extends Base {
* @return string compiled code
* @throws \Smarty\CompilerException
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{

if ($compiler->tag_nocache) {
// push a {nocache} tag onto the stack to prevent caching of this block
Expand Down
3 changes: 2 additions & 1 deletion src/Compile/Tag/IncludeTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class IncludeTag extends Base {
* @throws \Smarty\CompilerException
* @throws \Smarty\Exception
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
$uid = $t_hash = null;
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
Expand Down
3 changes: 2 additions & 1 deletion src/Compile/Tag/Ldelim.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class Ldelim extends Base {
* @return string compiled code
* @throws \Smarty\CompilerException
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
$_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) {
$compiler->trigger_template_error('nocache option not allowed', null, true);
Expand Down
5 changes: 3 additions & 2 deletions src/Compile/Tag/Nocache.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ class Nocache extends Base {
* @param array $args array with attributes from parser
* @param \Smarty\Compiler\Template $compiler compiler object
*
* @return bool
* @return string
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
$this->openTag($compiler, 'nocache');
return '';
}
Expand Down
5 changes: 3 additions & 2 deletions src/Compile/Tag/NocacheClose.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ class NocacheClose extends Base {
* @param array $args array with attributes from parser
* @param \Smarty\Compiler\Template $compiler compiler object
*
* @return bool
* @return string
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null): string
{
$this->closeTag($compiler, ['nocache']);
return '';
}
Expand Down
Loading

0 comments on commit ccc9543

Please sign in to comment.