Completed
Push — master ( f86360...4e757b )
by Peter
03:09
created

Wrapper::__toString()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
rs 9.4285
cc 3
eloc 12
nc 3
nop 0
1
<?php
2
3
/*
4
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace Maslosoft\Zamm\Helpers;
10
11
/**
12
 * Wrapper
13
 * @property Wrapper $md Get markdown wrapped code
14
 * @property Wrapper $html Get html `pre` wrapped code
15
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
16
 */
17
class Wrapper
18
{
19
20
	private $text = '';
21
	private $isMd = false;
22
	private $isHtml = false;
23
24
	public function __construct($text)
25
	{
26
		$this->text = $text;
27
	}
28
29
	public function __get($name)
30
	{
31
		return $this->$name();
32
	}
33
34
	public function md()
35
	{
36
		$this->isMd = true;
37
		return $this;
38
	}
39
40
	public function html()
41
	{
42
		$this->isHtml = true;
43
		return $this;
44
	}
45
46
	public function __toString()
47
	{
48
		if ($this->isMd)
49
		{
50
			return <<<TEXT
51
```php
52
$this->text
53
```
54
TEXT;
55
		}
56
		if ($this->isHtml)
57
		{
58
			return <<<TEXT
59
<pre>
60
$this->text
61
</pre>
62
TEXT;
63
		}
64
		return $this->text;
65
	}
66
67
}
68