ClockworkSMS::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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