Completed
Pull Request — master (#52)
by mw
02:11
created

PreTextFormatter::getFormattedSciteFuncFrom()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
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