ConnectionSettings::getHost()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * @author Threema GmbH
4
 * @copyright Copyright (c) 2015-2016 Threema GmbH
5
 */
6
7
8
namespace Threema\MsgApi;
9
10
class ConnectionSettings
11
{
12
	const tlsOptionForceHttps = 'forceHttps';
13
	const tlsOptionVersion = 'tlsVersion';
14
	const tlsOptionCipher = 'tlsCipher';
15
	const tlsOptionPinnedKey = 'pinnedKey';
16
17
	/**
18
	 * @var string
19
	 */
20
	private $threemaId;
21
22
	/**
23
	 * @var string
24
	 */
25
	private $secret;
26
27
	/**
28
	 * @var string
29
	 */
30
	private $host;
31
32
	/**
33
	 * @var array
34
	 */
35
	private $tlsOptions = [];
36
37
	/**
38
	 * @param string $threemaId valid threema id (8chars)
39
	 * @param string $secret secret
40
	 * @param string|null $host server url
41
	 * @param array|null $tlsOptions advanced TLS options
42
	 */
43
	public function __construct($threemaId, $secret, $host = null, array $tlsOptions = null) {
44
		$this->threemaId = $threemaId;
45
		$this->secret = $secret;
46
		if ($host === null) {
47
			$host = 'https://msgapi.threema.ch';
48
		}
49
		$this->host = $host;
50
51
		// TLS options
52
		if(null !== $tlsOptions && is_array($tlsOptions)) {
53 View Code Duplication
			if(true === array_key_exists(self::tlsOptionForceHttps, $tlsOptions)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
				$this->tlsOptions[self::tlsOptionForceHttps] = $tlsOptions[self::tlsOptionForceHttps] === true;
55
			}
56
57 View Code Duplication
			if(true === array_key_exists(self::tlsOptionVersion, $tlsOptions)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
				$this->tlsOptions[self::tlsOptionVersion] = $tlsOptions[self::tlsOptionVersion];
59
			}
60
61 View Code Duplication
			if(true === array_key_exists(self::tlsOptionCipher, $tlsOptions)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
				$this->tlsOptions[self::tlsOptionCipher] = $tlsOptions[self::tlsOptionCipher];
63
			}
64
65 View Code Duplication
			if(true === array_key_exists(self::tlsOptionPinnedKey, $tlsOptions)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66
				$this->tlsOptions[self::tlsOptionPinnedKey] = $tlsOptions[self::tlsOptionPinnedKey];
67
			}
68
		}
69
	}
70
71
	/**
72
	 * @return string
73
	 */
74
	public function getThreemaId() {
75
		return $this->threemaId;
76
	}
77
78
	/**
79
	 * @return string
80
	 */
81
	public function getSecret() {
82
		return $this->secret;
83
	}
84
85
	/**
86
	 * @return string
87
	 */
88
	public function getHost() {
89
		return $this->host;
90
	}
91
92
	/**
93
	 * @return array
94
	 */
95
	public function getTlsOptions() {
96
		return $this->tlsOptions;
97
	}
98
99
	/**
100
	 * @return string
101
	 */
102
	public function getTlsOption($option, $default = null) {
103
		return true === array_key_exists($option, $this->tlsOptions) ? $this->tlsOptions[$option] : $default;
104
	}
105
}
106