Nl2brFormat   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 18
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A nl2br() 0 16 3
1
<?php
2
/* @description     Transformation Style Sheets - Revolutionising PHP templating    *
3
 * @author          Tom Butler [email protected]                                             *
4
 * @copyright       2017 Tom Butler <[email protected]> | https://r.je/                      *
5
 * @license         http://www.opensource.org/licenses/bsd-license.php  BSD License *
6
 * @version         1.2                                                             */
7
namespace Transphporm\Formatter;
8
class Nl2brFormat {
9
	public function nl2br($var) {
10
		$parts = explode("\n", $var);
11
		$doc = new \DomDocument();
12
		$result = [];
13
14
		foreach ($parts as $key => $part) {
15
			$new = $doc->createTextNode($part);
16
			$result[] = $new;
17
			if ($key !== count($parts)-1) {
18
				$br = $doc->createElement('br');
19
				$result[] = $br;
20
			}
21
		}
22
23
		return $result;
24
	}
25
}
26