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

PreTextFormatter   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 38
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFormattedSciteFuncFrom() 0 3 1
B format() 0 20 5
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