Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
25.00% covered (danger)
25.00%
2 / 8
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
CodeFunction
25.00% covered (danger)
25.00%
2 / 8
66.67% covered (warning)
66.67%
2 / 3
6.80
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFunctionName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 functionBlockBodyImpl
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace PeServer\Core\Mvc\Template\Plugin;
6
7use PeServer\Core\Collection\Arr;
8use PeServer\Core\Text;
9use PeServer\Core\Html\CodeHighlighter;
10use PeServer\Core\Mvc\Template\Plugin\TemplateBlockFunctionBase;
11use PeServer\Core\Mvc\Template\Plugin\TemplatePluginArgument;
12
13class CodeFunction extends TemplateBlockFunctionBase
14{
15    public function __construct(TemplatePluginArgument $argument)
16    {
17        parent::__construct($argument);
18    }
19
20    #region TemplateBlockFunctionBase
21
22    public function getFunctionName(): string
23    {
24        return 'code';
25    }
26
27    protected function functionBlockBodyImpl(string $content): string
28    {
29        $language = $this->params['language'] ?? Text::EMPTY;
30        $numbers = (string)($this->params['numbers'] ?? '');
31
32        $codeHighlighter = new CodeHighlighter();
33
34        $lineNumbers = $codeHighlighter->toNumbers($numbers);
35
36        $html = $codeHighlighter->toHtml($language, $content, $lineNumbers);
37
38        return $html;
39    }
40
41    #endregion
42}