TemplateFilters::description()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
dl 0
loc 17
rs 9.4285
c 2
b 1
f 0
cc 1
eloc 11
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @copyright   Copyright (c) 2016 ublaboo <[email protected]>
7
 * @author      Pavel Janda <[email protected]>
8
 * @package     Ublaboo
9
 */
10
11
namespace Ublaboo\ApiDocu;
12
13
class TemplateFilters
14
{
15
	public static function common(string $filter): ?string
16
	{
17
		if (method_exists(__CLASS__, $filter)) {
18
			$args = func_get_args();
19
			array_shift($args);
20
			return call_user_func_array([__CLASS__, $filter], $args);
21
		}
22
	}
23
24
25
	public static function description(string $text): string
26
	{
27
		$text = nl2br($text);
28
		$text = str_replace(["\n", "\n\r", "\r\n", "\r"], '', $text);
29
30
		$text = preg_replace_callback('/<json><br \/>(.*?)<\/json>/s', function ($item) {
31
			$s = '<br><pre class="apiDocu-json">' . str_replace('<br>', '', end($item)) . '</pre>';
32
			$s = preg_replace('/(\s)"([^"]+)"/', '$1<span class="apiDocu-string">"$2"</span>', $s);
33
			$s = preg_replace('/\/\/(.*?)<br \/>/', '<span class="apiDocu-comment">//$1</span><br>', $s);
34
35
			return $s;
36
		}, $text);
37
38
		$text = preg_replace('/\*\*([^*]*)\*\*/', '<strong>$1</strong>', $text);
39
40
		return (string) $text;
41
	}
42
}
43