Completed
Push — master ( e01c3b...e3b9fc )
by Jeroen De
04:48 queued 40s
created

CreditCardUrlConfig::getProjectId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Frontend\Presentation;
6
7
/**
8
 * @licence GNU GPL v2+
9
 * @author Kai Nissen < [email protected] >
10
 */
11
class CreditCardUrlConfig {
12
13
	const CONFIG_KEY_BASE_URL = 'base-url';
14
	const CONFIG_KEY_PROJECT_ID = 'project-id';
15
	const CONFIG_KEY_BACKGROUND_COLOR = 'background-color';
16
	const CONFIG_KEY_SKIN = 'skin';
17
	const CONFIG_KEY_THEME = 'theme';
18
	const CONFIG_KEY_TESTMODE = 'testmode';
19
20
	private $baseUrl;
21
	private $projectId;
22
	private $backgroundColor;
23
	private $skin;
24
	private $theme;
25
	private $testMode;
26
27
	private function __construct( string $baseUrl, string $projectId, string $backgroundColor, string $skin, string $theme,
28
								  bool $testMode ) {
29
		$this->baseUrl = $baseUrl;
30
		$this->projectId = $projectId;
31
		$this->backgroundColor = $backgroundColor;
32
		$this->skin = $skin;
33
		$this->theme = $theme;
34
		$this->testMode = $testMode;
35
	}
36
37
	/**
38
	 * @param string[] $config
39
	 * @return CreditCardUrlConfig
40
	 * @throws \RuntimeException
41
	 */
42
	public static function newFromConfig( array $config ): self {
43
		return ( new self(
44
			$config[self::CONFIG_KEY_BASE_URL],
45
			$config[self::CONFIG_KEY_PROJECT_ID],
46
			$config[self::CONFIG_KEY_BACKGROUND_COLOR],
47
			$config[self::CONFIG_KEY_SKIN],
48
			$config[self::CONFIG_KEY_THEME],
49
			$config[self::CONFIG_KEY_TESTMODE]
0 ignored issues
show
Documentation introduced by
$config[self::CONFIG_KEY_TESTMODE] is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
50
		) )->assertNoEmptyFields();
51
	}
52
53
	private function assertNoEmptyFields(): self {
54
		foreach ( get_object_vars( $this ) as $fieldName => $fieldValue ) {
55
			if ( !isset( $fieldValue ) || $fieldValue === '' ) {
56
				throw new \RuntimeException( "Configuration variable '$fieldName' can not be empty" );
57
			}
58
		}
59
60
		return $this;
61
	}
62
63
	public function getBaseUrl(): string {
64
		return $this->baseUrl;
65
	}
66
67
	public function getProjectId(): string {
68
		return $this->projectId;
69
	}
70
71
	public function getBackgroundColor(): string {
72
		return $this->backgroundColor;
73
	}
74
75
	public function getSkin(): string {
76
		return $this->skin;
77
	}
78
79
	public function getTheme(): string {
80
		return $this->theme;
81
	}
82
83
	public function isTestMode() {
84
		return $this->testMode;
85
	}
86
87
}
88