Completed
Pull Request — master (#268)
by
unknown
25:13
created

AndroidGsmModem   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 20
dl 0
loc 46
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getConfig() 0 2 1
A send() 0 16 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace OCA\TwoFactorGateway\Service\Gateway\SMS\Provider;
6
7
use Exception;
8
use OCA\TwoFactorGateway\Exception\SmsTransmissionException;
9
use OCP\Http\Client\IClient;
10
use OCP\Http\Client\IClientService;
11
12
class AndroidGsmModem implements IProvider {
13
14
	const PROVIDER_ID = 'android_gsm_modem';
15
16
	/** @var IClient */
17
	private $client;
18
19
	/** @var AndroidGsmModemConfig */
20
	private $config;
21
22
	public function __construct(IClientService $clientService,
23
								AndroidGsmModemConfig $config) {
24
		$this->client = $clientService->newClient();
25
		$this->config = $config;
26
	}
27
28
	/**
29
	 * @param string $identifier
30
	 * @param string $message
31
	 *
32
	 * @throws SmsTransmissionException
33
	 */
34
	public function send(string $identifier, string $message) {
35
		$config = $this->getConfig();
36
		$user = $config->getUser();
37
		$password = $config->getPassword();
38
		$host = $config->getHost();
39
		try {
40
			$this->client->get("http://$host/SendSMS", [
41
				'query' => [
42
					'user' => $user,
43
					'password' => $password,
44
					'phone' => $identifier,
45
					'message' => $message,
46
				],
47
			]);
48
		} catch (Exception $ex) {
49
			throw new SmsTransmissionException();
50
		}
51
	}
52
53
	/**
54
	 * @return AndroidGsmModemConfig
55
	 */
56
	public function getConfig(): IProviderConfig {
57
		return $this->config;
58
	}
59
}
60