Code::transform()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
/**
3
 * Class Code
4
 *
5
 * @filesource   Code.php
6
 * @created      25.04.2018
7
 * @package      chillerlan\BBCode\Output\Markdown
8
 * @author       smiley <[email protected]>
9
 * @copyright    2018 smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\BBCode\Output\Markdown;
14
15
class Code extends MarkdownModuleAbstract{
16
17
	/**
18
	 * @var array
19
	 */
20
	protected $tags = ['noparse', 'code', 'pre', 'css', 'php', 'sql', 'xml', 'html', 'js', 'json'];
21
22
	/**
23
	 * @var array
24
	 */
25
	protected $noparse = ['noparse', 'code', 'pre', 'css', 'php', 'sql', 'xml', 'html', 'js', 'json'];
26
27
	/**
28
	 * @return string
29
	 */
30
	protected function transform():string{
31
32
		if(empty($this->content)){
33
			return '';
34
		}
35
36
		$this->clearPseudoClosingTags();
37
38
		$exceptions = [
39
			'js'      => 'javascript',
40
			'pre'     => '',
41
			'code'    => '',
42
			'noparse' => '',
43
		];
44
45
		$lang = $exceptions[$this->tag] ?? $this->tag;
46
47
		return PHP_EOL.'```'.$lang.PHP_EOL.$this->content.PHP_EOL.'```'.PHP_EOL;
48
	}
49
50
}
51