Passed
Push — master ( 231b74...b288a1 )
by WEBEWEB
04:16
created

syntaxHighlighter()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of the syntaxhighligter-bundle package.
5
 *
6
 * (c) 2018 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\SyntaxHighlighterBundle\Twig\Extension;
13
14
use Twig_Extension;
15
use WBW\Library\Core\Utility\Argument\StringUtility;
16
17
/**
18
 * Abstract SyntaxHighlighter Twig extension.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Bundle\SyntaxHighlighterBundle\Twig\Extension
22
 * @abstract
23
 */
24
abstract class AbstractSyntaxHighlighterTwigExtension extends Twig_Extension {
25
26
    /**
27
     * Constructor.
28
     */
29
    protected function __construct() {
30
        // NOTHING TO DO.
31
    }
32
33
    /**
34
     * Displays a SyntaxHighlighter.
35
     *
36
     * @param string $language The language.
37
     * @param string $content The content.
38
     * @return string Returns the SyntaxHightlighter.
39
     */
40
    protected function syntaxHighlighter($language, $content) {
41
42
        // Initialize the template.
43
        $template = "<pre %attributes%>\n%innerHTML%\n</pre>";
44
45
        // Initialize the attributes.
46
        $attributes = [];
47
48
        $attributes["class"][] = "brush:";
49
        $attributes["class"][] = (null !== $language ? $language : "php") . ";";
0 ignored issues
show
introduced by
The condition null !== $language is always true.
Loading history...
50
51
        // Return the HTML.
52
        return StringUtility::replace($template, ["%attributes%", "%innerHTML%"], [StringUtility::parseArray($attributes), $content]);
53
    }
54
55
}
56