Completed
Push — master ( a64231...f74f4e )
by Pavel
02:39
created

TemplateFilters::description()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

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