Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
25.00% |
2 / 8 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
CodeFunction | |
25.00% |
2 / 8 |
|
66.67% |
2 / 3 |
6.80 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getFunctionName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
functionBlockBodyImpl | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\Core\Mvc\Template\Plugin; |
6 | |
7 | use PeServer\Core\Collection\Arr; |
8 | use PeServer\Core\Text; |
9 | use PeServer\Core\Html\CodeHighlighter; |
10 | use PeServer\Core\Mvc\Template\Plugin\TemplateBlockFunctionBase; |
11 | use PeServer\Core\Mvc\Template\Plugin\TemplatePluginArgument; |
12 | |
13 | class 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 | } |