Completed
Push — master ( 2dde08...53ace6 )
by Christoph
08:53
created

PuzzelSMS   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 19
dl 0
loc 48
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfig() 0 2 1
A send() 0 18 2
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author Kim Syversen <[email protected]>
7
 *
8
 * Nextcloud - Two-factor Gateway
9
 *
10
 * This code is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License, version 3,
12
 * as published by the Free Software Foundation.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License, version 3,
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
21
 *
22
 */
23
24
namespace OCA\TwoFactorGateway\Service\Gateway\SMS\Provider;
25
26
use Exception;
27
use OCA\TwoFactorGateway\Exception\SmsTransmissionException;
28
use OCP\Http\Client\IClient;
29
use OCP\Http\Client\IClientService;
30
use OCP\IConfig;
31
32
class PuzzelSMS implements IProvider {
33
34
	const PROVIDER_ID = 'puzzelsms';
35
36
	/** @var IClient */
37
	private $client;
38
39
	/** @var PuzzelConfig */
0 ignored issues
show
Bug introduced by
The type OCA\TwoFactorGateway\Ser...S\Provider\PuzzelConfig was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
40
	private $config;
41
42
	public function __construct(IClientService $clientService,
43
								PuzzelSMSConfig $config) {
44
		$this->client = $clientService->newClient();
45
		$this->config = $config;
0 ignored issues
show
Documentation Bug introduced by
It seems like $config of type OCA\TwoFactorGateway\Ser...rovider\PuzzelSMSConfig is incompatible with the declared type OCA\TwoFactorGateway\Ser...S\Provider\PuzzelConfig of property $config.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
46
	}
47
48
	/**
49
	 * @param string $identifier
50
	 * @param string $message
51
	 *
52
	 * @throws SmsTransmissionException
53
	 */
54
	public function send(string $identifier, string $message) {
55
		$config = $this->getConfig();
56
57
		try {
58
			$this->client->get(
59
				$config->getUrl(),
0 ignored issues
show
Bug introduced by
The method getUrl() does not exist on OCA\TwoFactorGateway\Ser...rovider\IProviderConfig. It seems like you code against a sub-type of OCA\TwoFactorGateway\Ser...rovider\IProviderConfig such as OCA\TwoFactorGateway\Ser...\Provider\PlaySMSConfig or OCA\TwoFactorGateway\Ser...rovider\PuzzelSMSConfig. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
				$config->/** @scrutinizer ignore-call */ 
60
             getUrl(),
Loading history...
60
				[
61
					'query' => [
62
						'username' => $config->getUser(),
0 ignored issues
show
Bug introduced by
The method getUser() does not exist on OCA\TwoFactorGateway\Ser...rovider\IProviderConfig. It seems like you code against a sub-type of said class. However, the method does not exist in OCA\TwoFactorGateway\Ser...ider\ClockworkSMSConfig. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

62
						'username' => $config->/** @scrutinizer ignore-call */ getUser(),
Loading history...
63
						'password' => $config->getPassword(),
0 ignored issues
show
Bug introduced by
The method getPassword() does not exist on OCA\TwoFactorGateway\Ser...rovider\IProviderConfig. It seems like you code against a sub-type of said class. However, the method does not exist in OCA\TwoFactorGateway\Ser...ider\ClockworkSMSConfig. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

63
						'password' => $config->/** @scrutinizer ignore-call */ getPassword(),
Loading history...
64
						"message[0].recipient" => "+".$identifier,
65
						"message[0].content" => $message,
66
						'serviceId'=> $config->getServiceId(),
0 ignored issues
show
Bug introduced by
The method getServiceId() does not exist on OCA\TwoFactorGateway\Ser...rovider\IProviderConfig. It seems like you code against a sub-type of OCA\TwoFactorGateway\Ser...rovider\IProviderConfig such as OCA\TwoFactorGateway\Ser...rovider\PuzzelSMSConfig. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
						'serviceId'=> $config->/** @scrutinizer ignore-call */ getServiceId(),
Loading history...
67
					],
68
				]
69
			);
70
		} catch (Exception $ex) {
71
			throw new SmsTransmissionException();
72
		}
73
	}
74
75
	/**
76
	 * @return PuzzelConfig
77
	 */
78
	public function getConfig(): IProviderConfig {
79
		return $this->config;
80
	}
81
82
}