ConnectionSettings   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 96
Duplicated Lines 12.5 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 0
dl 12
loc 96
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 12 27 8
A getThreemaId() 0 3 1
A getSecret() 0 3 1
A getHost() 0 3 1
A getTlsOptions() 0 3 1
A getTlsOption() 0 3 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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