KeyQueryStringAuthentication   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 54
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getAuthorization() 0 13 2
1
<?php
2
3
namespace Integracao\ControlPay\Impl;
4
5
use Integracao\ControlPay\API\LoginApi;
6
use Integracao\ControlPay\Client;
7
use Integracao\ControlPay\Contracts\Login\LoginRequest;
8
use Integracao\ControlPay\Interfaces\IAuthentication;
9
10
/**
11
 * Class KeyQueryStringAuthentication
12
 * @package Integracao\ControlPay\Impl
13
 */
14
class KeyQueryStringAuthentication implements IAuthentication
15
{
16
    /**
17
     * @var
18
     */
19
    private $user;
20
    /**
21
     * @var
22
     */
23
    private $password;
24
    /**
25
     * @var null
26
     */
27
    private $pessoaId;
28
29
    /**
30
     * @var LoginApi
31
     */
32
    private $_loginApi;
33
    /**
34
     * @var null
35
     */
36
    private $key;
37
38
    /**
39
     * KeyQueryStringAuthentication constructor.
40
     */
41
    public function __construct($user, $password, $key = null, $pessoaId = null, Client $client)
42
    {
43
        $this->_loginApi = new LoginApi($client);
44
        $this->user = $user;
45
        $this->password = $password;
46
        $this->pessoaId = $pessoaId;
47
        $this->key = $key;
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    public function getAuthorization()
54
    {
55
        if(!empty($this->key))
56
            return $this->key;
57
58
        $response = $this->_loginApi->login(
59
            (new LoginRequest())
60
                ->setPessoaId($this->pessoaId)
61
                ->setSenha($this->password)
62
                ->setCpfCnpj($this->user)
63
        );
64
        return $response->getPessoa()->getKey();
65
    }
66
67
}