Passed
Pull Request — master (#268)
by
unknown
04:07
created

AndroidGSMmodem   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 15
dl 0
loc 39
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A send() 0 9 2
A __construct() 0 4 1
A getConfig() 0 2 1
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 */
0 ignored issues
show
Bug introduced by
The type OCA\TwoFactorGateway\Ser...r\AndroidGSMmodemConfig 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...
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();
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 or OCA\TwoFactorGateway\Ser...vider\HuaweiE3531Config. 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

36
		/** @scrutinizer ignore-call */ 
37
  $user = $config->getUser();
Loading history...
37
		$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 or OCA\TwoFactorGateway\Ser...vider\HuaweiE3531Config. 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

37
		/** @scrutinizer ignore-call */ 
38
  $password = $config->getPassword();
Loading history...
38
		$host = $config->getHost();
0 ignored issues
show
Bug introduced by
The method getHost() does not exist on OCA\TwoFactorGateway\Ser...rovider\IProviderConfig. ( Ignorable by Annotation )

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

38
		/** @scrutinizer ignore-call */ 
39
  $host = $config->getHost();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
39
		try {
40
			$this->client->get('http://'.$host.'/SendSMS/username='.$user.'&password='.$password.'&phone='.$identifier.'&message='.$message);
41
		} catch (Exception $ex) {
42
			throw new SmsTransmissionException();
43
		}
44
	}
45
46
	/**
47
	 * @return AndroidGSMmodemConfig
48
	 */
49
	public function getConfig(): IProviderConfig {
50
		return $this->config;
51
	}
52
}
53