1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Integracao\ControlPay\Factory; |
4
|
|
|
|
5
|
|
|
use Integracao\ControlPay\Client; |
6
|
|
|
use Integracao\ControlPay\Constants\ControlPayParameterConst; |
7
|
|
|
use Integracao\ControlPay\Impl\BasicAuthentication; |
8
|
|
|
use Integracao\ControlPay\Impl\KeyQueryStringAuthentication; |
9
|
|
|
use Integracao\ControlPay\Interfaces\IAuthentication; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class AuthenticationFactory |
13
|
|
|
* @package Integracao\NTKOnline |
14
|
|
|
*/ |
15
|
|
|
class AuthenticationFactory |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @param array $params |
19
|
|
|
* @return IAuthentication |
20
|
|
|
* @throws \Exception |
21
|
|
|
*/ |
22
|
|
|
public static function getInstance(array $params, Client $client = null) |
23
|
|
|
{ |
24
|
|
|
if(!isset($params[ControlPayParameterConst::CONTROLPAY_OAUTH_TYPE])) |
25
|
|
|
throw new \Exception("Tipo de autenticação não especificado"); |
26
|
|
|
|
27
|
|
|
switch ($params[ControlPayParameterConst::CONTROLPAY_OAUTH_TYPE]) |
28
|
|
|
{ |
29
|
|
|
case BasicAuthentication::class: |
30
|
|
|
return new BasicAuthentication( |
31
|
|
|
isset($params[ControlPayParameterConst::CONTROLPAY_USER]) ?$params[ControlPayParameterConst::CONTROLPAY_USER] : null, |
32
|
|
|
isset($params[ControlPayParameterConst::CONTROLPAY_PWD]) ?$params[ControlPayParameterConst::CONTROLPAY_PWD] : null, |
33
|
|
|
isset($params[ControlPayParameterConst::CONTROLPAY_KEY]) ?$params[ControlPayParameterConst::CONTROLPAY_KEY] : null |
34
|
|
|
); |
35
|
|
|
break; |
|
|
|
|
36
|
|
|
case KeyQueryStringAuthentication::class: |
37
|
|
|
return new KeyQueryStringAuthentication( |
38
|
|
|
isset($params[ControlPayParameterConst::CONTROLPAY_USER]) ?$params[ControlPayParameterConst::CONTROLPAY_USER] : null, |
39
|
|
|
isset($params[ControlPayParameterConst::CONTROLPAY_PWD]) ?$params[ControlPayParameterConst::CONTROLPAY_PWD] : null, |
40
|
|
|
isset($params[ControlPayParameterConst::CONTROLPAY_KEY]) ?$params[ControlPayParameterConst::CONTROLPAY_KEY] : null, |
41
|
|
|
isset($params[ControlPayParameterConst::CONTROLPAY_DEFAULT_PESSOA_ID]) ?$params[ControlPayParameterConst::CONTROLPAY_DEFAULT_PESSOA_ID] : null, |
42
|
|
|
$client |
|
|
|
|
43
|
|
|
); |
44
|
|
|
break; |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
throw new \Exception("Implementação não tratada no factory"); |
48
|
|
|
} |
49
|
|
|
} |
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.