Completed
Push — master ( bf2930...494091 )
by David
07:08 queued 03:26
created

lib/Dwoo/Plugins/Blocks/PluginForeachelse.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Copyright (c) 2013-2016
4
 *
5
 * @category  Library
6
 * @package   Dwoo\Plugins\Blocks
7
 * @author    Jordi Boggiano <[email protected]>
8
 * @author    David Sanchez <[email protected]>
9
 * @copyright 2008-2013 Jordi Boggiano
10
 * @copyright 2013-2016 David Sanchez
11
 * @license   http://dwoo.org/LICENSE Modified BSD License
12
 * @version   1.3.0
13
 * @date      2016-09-19
14
 * @link      http://dwoo.org/
15
 */
16
17
namespace Dwoo\Plugins\Blocks;
18
19
use Dwoo\Compiler;
20
use Dwoo\Block\Plugin as BlockPlugin;
21
use Dwoo\ICompilable\Block as ICompilableBlock;
22
23
/**
24
 * This plugin serves as a {else} block specifically for the {foreach} plugin.
25
 * This software is provided 'as-is', without any express or implied warranty.
26
 * In no event will the authors be held liable for any damages arising from the use of this software.
27
 */
28 View Code Duplication
class PluginForeachelse extends BlockPlugin implements ICompilableBlock
0 ignored issues
show
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
{
30
    public function init()
31
    {
32
    }
33
34
    /**
35
     * @param Compiler $compiler
36
     * @param array    $params
37
     * @param string   $prepend
38
     * @param string   $append
39
     * @param string   $type
40
     *
41
     * @return string
42
     */
43
    public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
44
    {
45
        $with = &$compiler->findBlock('foreach', true);
46
47
        $params['initialized'] = true;
48
        $compiler->injectBlock($type, $params);
49
50
        return '';
51
    }
52
53
    /**
54
     * @param Compiler $compiler
55
     * @param array    $params
56
     * @param string   $prepend
57
     * @param string   $append
58
     * @param string   $content
59
     *
60
     * @return string
61
     */
62
    public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
63
    {
64
        if (!isset($params['initialized'])) {
65
            return '';
66
        }
67
68
        $block                      = &$compiler->getCurrentBlock();
69
        $block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE;
70
71
        return '';
72
    }
73
}
74