Completed
Push — main ( 2daa48...b5d932 )
by
unknown
08:38
created

FluentGenerator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 57
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Addwiki\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 string $name;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
15
	private array $params = [];
16
17
	public function __construct( string $name ) {
18
		$this->name = $name;
19
	}
20
21
	/**
22
	 * Convenience method for using this fluidly
23
	 *
24
	 *
25
	 */
26
	public static function factory( string $name ): FluentGenerator {
27
		return new self( $name );
28
	}
29
30
	/**
31
	 * @return string[]
32
	 */
33
	public function getParams(): array {
34
		$params = $this->params;
35
		$params['generator'] = $this->name;
36
		return $params;
37
	}
38
39
	/**
40
	 * @param string $key optionally with the 'g' prefix
41
	 *
42
	 * @return $this
43
	 */
44
	public function set( string $key, string $value ): self {
45
		$key = $this->addKeyPrefixIfNeeded( $key );
46
		$this->params[$key] = $value;
47
		return $this;
48
	}
49
50
	private function addKeyPrefixIfNeeded( string $key ): string {
51
		if ( strtolower( substr( $key, 0, 1 ) ) === 'g' ) {
52
			return $key;
53
		}
54
		return 'g' . $key;
55
	}
56
57
}
58