FluentGenerator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 57
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A factory() 0 3 1
A getParams() 0 5 1
A set() 0 5 1
A addKeyPrefixIfNeeded() 0 6 2
1
<?php
2
3
namespace Mediawiki\Api\Generator;
4
5
/**
6
 * @access public
7
 *
8
 * @author Addshore
9
 *
10
 * @since 0.5.1
11
 */
12
class FluentGenerator implements ApiGenerator {
13
14
	private $name;
15
	private $params;
16
17
	/**
18
	 * @param string $name
19
	 */
20
	public function __construct( $name ) {
21
		$this->name = $name;
22
	}
23
24
	/**
25
	 * Convenience method for using this fluidly
26
	 *
27
	 * @param string $name
28
	 *
29
	 * @return FluentGenerator
30
	 */
31
	public static function factory( $name ) {
32
		return new self( $name );
33
	}
34
35
	/**
36
	 * @return string[]
37
	 */
38
	public function getParams() {
39
		$params = $this->params;
40
		$params['generator'] = $this->name;
41
		return $params;
42
	}
43
44
	/**
45
	 * @param string $key optionally with the 'g' prefix
46
	 * @param string $value
47
	 *
48
	 * @return $this
49
	 */
50
	public function set( $key, $value ) {
51
		$key = $this->addKeyprefixIfNeeded( $key );
52
		$this->params[$key] = $value;
53
		return $this;
54
	}
55
56
	/**
57
	 * @param string $key
58
	 *
59
	 * @return string
60
	 */
61
	private function addKeyPrefixIfNeeded( $key ) {
62
		if ( strtolower( substr( $key, 0, 1 ) ) === 'g' ) {
63
			return $key;
64
		}
65
		return 'g' . $key;
66
	}
67
68
}
69