Completed
Push — master ( 36ba73...9ed582 )
by mw
04:36
created

PreTextFormatter::getFormattedSciteFuncFrom()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
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 2
	public function getFormattedSciteFuncFrom( array $parameters ) {
22 2
		return "<pre>{{#scite:\n" . implode( "\n", $this->format( $parameters ) ) ."\n}}</pre>";
23
	}
24
25
	/**
26
	 * @since 1.4
27
	 *
28
	 * @return array
29
	 */
30 4
	public function format( array $parameters ) {
31
32 4
		$formatted = array();
33
34 4
		foreach ( $parameters as $key => $value ) {
35
36 4
			if ( $value === '' || $value{0} === '@' ) {
37 4
				continue;
38
			}
39
40 4
			if ( $value{0} === '+' ) {
41 2
				$formatted[$key-1] = $formatted[$key-1] . '|' . $value;
42 2
				continue;
43
			}
44
45 4
			$formatted[$key] = ' |' . $value;
46 4
		}
47
48 4
		return $formatted;
49
	}
50
51
}
52