PluginA::postProcessing()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 4
nc 3
nop 5
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
 * Outputs a html &lt;a&gt; tag
25
 * <pre>
26
 *  * href : the target URI where the link must point
27
 *  * rest : any other attributes you want to add to the tag can be added as named parameters
28
 * </pre>.
29
 * Example :
30
 * <code>
31
 * {* Create a simple link out of an url variable and add a special class attribute: *}
32
 * {a $url class="external" /}
33
 * {* Mark a link as active depending on some other variable : *}
34
 * {a $link.url class=tif($link.active "active"); $link.title /}
35
 * {* This is similar to: <a href="{$link.url}" class="{if $link.active}active{/if}">{$link.title}</a> *}
36
 * </code>
37
 * This software is provided 'as-is', without any express or implied warranty.
38
 * In no event will the authors be held liable for any damages arising from the use of this software.
39
 */
40
class PluginA extends BlockPlugin implements ICompilableBlock
41
{
42
    /**
43
     * @param       $href
44
     * @param array $rest
45
     */
46
    public function init($href, array $rest = array())
0 ignored issues
show
Unused Code introduced by
The parameter $href is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $rest is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
47
    {
48
    }
49
50
    /**
51
     * @param Compiler $compiler
52
     * @param array    $params
53
     * @param string   $prepend
54
     * @param string   $append
55
     * @param string   $type
56
     *
57
     * @return string
58
     */
59
    public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
60
    {
61
        $p = $compiler->getCompiledParams($params);
62
63
        $out = Compiler::PHP_OPEN . 'echo \'<a ' . self::paramsToAttributes($p, "'", $compiler);
64
65
        return $out . '>\';' . Compiler::PHP_CLOSE;
66
    }
67
68
    /**
69
     * @param Compiler $compiler
70
     * @param array    $params
71
     * @param string   $prepend
72
     * @param string   $append
73
     * @param string   $content
74
     *
75
     * @return string
76
     */
77
    public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
78
    {
79
        $p = $compiler->getCompiledParams($params);
80
81
        // no content was provided so use the url as display text
82
        if ($content == '') {
83
            // merge </a> into the href if href is a string
84
            if (substr($p['href'], - 1) === '"' || substr($p['href'], - 1) === '\'') {
85
                return Compiler::PHP_OPEN . 'echo ' . substr($p['href'], 0, - 1) . '</a>' . substr($p['href'], - 1) . ';' . Compiler::PHP_CLOSE;
86
            }
87
88
            // otherwise append
89
            return Compiler::PHP_OPEN . 'echo ' . $p['href'] . '.\'</a>\';' . Compiler::PHP_CLOSE;
90
        }
91
92
        // return content
93
        return $content . '</a>';
94
    }
95
}
96