Passed
Branch refactoring (232535)
by João Felipe Magro
01:20
created

Authentication::hasPartner()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
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