Completed
Push — master ( 9852e6...709b88 )
by Tom
02:32
created

Nl2br::getContent()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 10
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 10
loc 10
rs 9.4285
cc 3
eloc 7
nc 2
nop 1
1
<?php
2
namespace Transphporm\Formatter;
3
class Nl2br {
4
	public function nl2br($var) {
0 ignored issues
show
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
5
		$parts = explode("\n", $var);
6
		$doc = new \DomDocument();
7
		$result = [];
8
		
9
		foreach ($parts as $key => $part) {
10
			$new = $doc->createTextNode($part);
11
			$result[] = $new;
12
			if ($key !== count($parts)-1) {
13
				$br = $doc->createElement('br');
14
				$result[] = $br;
15
			}
16
		}
17
18
		return $result;
19
	}
20
}
21