Completed
Push — master ( fe350e...be5f46 )
by smiley
04:14
created

Code   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 33
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 16 4
1
<?php
2
/**
3
 * Class Code
4
 *
5
 * @filesource   Code.php
6
 * @created      25.04.2018
7
 * @package      chillerlan\BBCode\Output\HTML
8
 * @author       smiley <[email protected]>
9
 * @copyright    2018 smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\BBCode\Output\HTML;
14
15
class Code extends HTMLModuleAbstract{
16
17
	/**
18
	 * @var array
19
	 */
20
	protected $tags = ['code', 'pre', 'css', 'php', 'sql', 'xml', 'html', 'js', 'json', 'nsis'];
21
22
	/**
23
	 * @var array
24
	 */
25
	protected $noparse = ['code', 'pre', 'css', 'php', 'sql', 'xml', 'html', 'js', 'json', 'nsis'];
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
		$id   = $this->randomID();
39
		$desc = $this->getAttribute('desc');
40
41
		// @todo
42
		return '<div data-id="'.$id.'" class="expander code-header '.$this->tag.'">'.($desc ? ' - <span>'.$desc.'</span>' : '').'</div>'
43
		       .'<pre id="'.$id.'" class="code-body" style="display:'.($this->getAttribute('hide') ? 'none' : 'block').';">'
44
		       .'<code class="language-'.$this->tag.'">'.$this->content.'</code></pre>'; // sanitize
45
	}
46
47
}
48