ClockworkSMS   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
wmc 4
eloc 20
dl 0
loc 37
ccs 13
cts 26
cp 0.5
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A send() 0 15 2
A createSettings() 0 8 1
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * SPDX-FileCopyrightText: 2024 Mario Klug <[email protected]>
7
 * SPDX-License-Identifier: AGPL-3.0-or-later
8
 */
9
10
namespace OCA\TwoFactorGateway\Provider\Channel\SMS\Provider\Drivers;
11
12
use Exception;
13
use OCA\TwoFactorGateway\Exception\MessageTransmissionException;
14
use OCA\TwoFactorGateway\Provider\Channel\SMS\Provider\AProvider;
15
use OCA\TwoFactorGateway\Provider\FieldDefinition;
16
use OCA\TwoFactorGateway\Provider\Settings;
17
use OCP\Http\Client\IClient;
18
use OCP\Http\Client\IClientService;
19
20
/**
21
 * @method string getApitoken()
22
 * @method static setApitoken(string $apitoken)
23
 */
24
class ClockworkSMS extends AProvider {
25
	private IClient $client;
26
27 1
	public function __construct(
28
		IClientService $clientService,
29
	) {
30 1
		$this->client = $clientService->newClient();
31
	}
32
33 1
	public function createSettings(): Settings {
34 1
		return new Settings(
35 1
			id: 'clockworksms',
36 1
			name: 'ClockworkSMS',
37 1
			fields: [
38 1
				new FieldDefinition(
39 1
					field: 'apitoken',
40 1
					prompt: 'Please enter your clockworksms api token:',
41 1
				),
42 1
			]
43 1
		);
44
	}
45
46
	#[\Override]
47
	public function send(string $identifier, string $message) {
48
		try {
49
			$response = $this->client->get(
0 ignored issues
show
Unused Code introduced by
The assignment to $response is dead and can be removed.
Loading history...
50
				'https://api.clockworksms.com/http/send.aspx',
51
				[
52
					'query' => [
53
						'key' => $this->getApitoken(),
54
						'to' => $identifier,
55
						'content' => $message,
56
					],
57
				]
58
			);
59
		} catch (Exception $ex) {
60
			throw new MessageTransmissionException();
61
		}
62
	}
63
}
64