Completed
Push — master ( 494091...32c874 )
by David
27s
created

PluginStripTags::compile()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 4
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright (c) 2013-2017
4
 *
5
 * @category  Library
6
 * @package   Dwoo\Plugins\Functions
7
 * @author    Jordi Boggiano <[email protected]>
8
 * @author    David Sanchez <[email protected]>
9
 * @copyright 2008-2013 Jordi Boggiano
10
 * @copyright 2013-2017 David Sanchez
11
 * @license   http://dwoo.org/LICENSE Modified BSD License
12
 * @version   1.3.3
13
 * @date      2017-01-07
14
 * @link      http://dwoo.org/
15
 */
16
17
namespace Dwoo\Plugins\Functions;
18
19
use Dwoo\Compiler;
20
use Dwoo\ICompilable;
21
use Dwoo\Plugin;
22
23
/**
24
 * Removes all html tags
25
 * <pre>
26
 *  * value: the string to process
27
 *  * addspace: if true, a space is added in place of every removed tag
28
 *  * allowable_tags: specify tags which should not be stripped
29
 * </pre>
30
 * This software is provided 'as-is', without any express or implied warranty.
31
 * In no event will the authors be held liable for any damages arising from the use of this software.
32
 */
33
class PluginStripTags extends Plugin implements ICompilable
34
{
35
    /**
36
     * @param Compiler    $compiler
37
     * @param string      $value
38
     * @param bool        $addspace
39
     * @param null|string $allowable_tags
40
     *
41
     * @return string
42
     */
43
    public static function compile(Compiler $compiler, $value, $addspace = true, $allowable_tags = null)
0 ignored issues
show
Unused Code introduced by
The parameter $compiler 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...
44
    {
45
        if ($addspace === 'true') {
46
            if ("null" == $allowable_tags) {
47
                return "preg_replace('#<[^>]*>#', ' ', $value)";
48
            }
49
50
            return "preg_replace('#<\\s*\\/?(" . $allowable_tags . ")\\s*[^>]*?>#im', ' ', $value)";
51
        }
52
53
        return "strip_tags($value, $allowable_tags)";
54
    }
55
}