Passed
Push — master ( 8baa4a...fa5dd9 )
by João Felipe Magro
01:17
created

Authentication   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 10
dl 0
loc 98
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setApiKey() 0 5 1
A getIdentification() 0 3 1
A getApiKey() 0 3 1
A setIdentification() 0 5 1
A __construct() 0 4 1
A getPartner() 0 3 1
A setPartner() 0 5 1
A hasPartner() 0 3 1
A serialize() 0 11 2
1
<?php
2
3
namespace Ipag\Classes;
4
5
use Ipag\Classes\Contracts\Emptiable;
6
use Ipag\Classes\Contracts\ObjectSerializable;
7
use Ipag\Classes\Traits\EmptiableTrait;
8
9
final class Authentication implements Emptiable, ObjectSerializable
10
{
11
    use EmptiableTrait;
12
13
    /**
14
     * @var string
15
     */
16
    private $identification;
17
18
    /**
19
     * @var string
20
     */
21
    private $partner;
22
23
    /**
24
     * @var string
25
     */
26
    private $apiKey;
27
28
    public function __construct($identification, $apiKey = null)
29
    {
30
        $this->identification = $identification;
31
        $this->apiKey = $apiKey;
32
    }
33
34
    /**
35
     * @return string
36
     */
37
    public function getIdentification()
38
    {
39
        return $this->identification;
40
    }
41
42
    /**
43
     * @param string $identification
44
     */
45
    public function setIdentification($identification)
46
    {
47
        $this->identification = substr((string) $identification, 0, 50);
48
49
        return $this;
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function getPartner()
56
    {
57
        return $this->partner;
58
    }
59
60
    /**
61
     * @param string $partner
62
     */
63
    public function setPartner($partner)
64
    {
65
        $this->partner = substr((string) $partner, 0, 50);
66
67
        return $this;
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function getApiKey()
74
    {
75
        return $this->apiKey;
76
    }
77
78
    /**
79
     * @param string $apiKey
80
     */
81
    public function setApiKey($apiKey)
82
    {
83
        $this->apiKey = $apiKey;
84
85
        return $this;
86
    }
87
88
    /**
89
     * @return bool
90
     */
91
    public function hasPartner()
92
    {
93
        return (bool) !empty($this->partner);
94
    }
95
96
    public function serialize()
97
    {
98
        $_user = [
99
            'identificacao' => urlencode($this->getIdentification()),
100
        ];
101
102
        if ($this->hasPartner()) {
103
            $_user['identificacao2'] = urlencode($this->getPartner());
104
        }
105
106
        return $_user;
107
    }
108
}
109