Completed
Push — master ( 1a6713...36ba73 )
by mw
04:56
created

PreTextFormatter::format()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 0
cts 11
cp 0
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 10
nc 4
nop 1
crap 30
1
<?php
2
3
namespace SCI;
4
5
use SMW\MediaWiki\Renderer\WikitextTemplateRenderer;
6
use Parser;
7
8
/**
9
 * @license GNU GPL v2+
10
 * @since 1.0
11
 *
12
 * @author mwjames
13
 */
14
class PreTextFormatter {
15
16
	/**
17
	 * @since 1.4
18
	 *
19
	 * @return string
20
	 */
21
	public function getFormattedSciteFuncFrom( array $parameters ) {
22
		return "<pre>{{#scite:\n" . implode( "\n", $this->format( $parameters ) ) ."\n}}</pre>";
23
	}
24
25
	/**
26
	 * @since 1.4
27
	 *
28
	 * @return array
29
	 */
30
	public function format( array $parameters ) {
31
32
		$formatted = array();
33
34
		foreach ( $parameters as $key => $value ) {
35
36
			if ( $value === '' || $value{0} === '@' ) {
37
				continue;
38
			}
39
40
			if ( $value{0} === '+' ) {
41
				$formatted[$key-1] = $formatted[$key-1] . '|' . $value;
42
				continue;
43
			}
44
45
			$formatted[$key] = ' |' . $value;
46
		}
47
48
		return $formatted;
49
	}
50
51
}
52