Wrapper::html()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
/**
4
 * This software package is licensed under `AGPL, Commercial` license[s].
5
 *
6
 * @package maslosoft/zamm
7
 * @license AGPL, Commercial
8
 *
9
 * @copyright Copyright (c) Peter Maselkowski <[email protected]>
10
 * @link https://maslosoft.com/zamm/
11
 */
12
13
namespace Maslosoft\Zamm\Helpers;
14
15
/**
16
 * Wrapper
17
 * @property Wrapper $md Get markdown wrapped code
18
 * @property Wrapper $html Get html `pre` wrapped code
19
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
20
 */
21
class Wrapper
22
{
23
24
	public $md;
25
	public $html;
26
	protected $text = '';
27
	protected $isMd = false;
28
	protected $isHtml = false;
29
30
	public function __construct($text)
31
	{
32
		unset($this->md);
33
		unset($this->html);
34
		$this->text = $text;
35
	}
36
37
	public function __get($name)
38
	{
39
		return $this->$name();
40
	}
41
42
	public function md()
43
	{
44
		$this->isMd = true;
45
		return $this;
46
	}
47
48
	/**
49
	 * Get code for HTML formatting.
50
	 * @return Wrapper
51
	 */
52
	public function html()
53
	{
54
		$this->isHtml = true;
55
		return $this;
56
	}
57
58
	public function __toString()
59
	{
60
		if ($this->isMd)
61
		{
62
			return <<<TEXT
63
64
```php
65
$this->text
66
```
67
68
TEXT;
69
		}
70
		if ($this->isHtml)
71
		{
72
			$text = htmlspecialchars($this->text);
73
			return <<<TEXT
74
<pre class="php">$text</pre>
75
TEXT;
76
		}
77
		return $this->text;
78
	}
79
80
}
81