GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Visitor::__construct()   A
last analyzed

Complexity

Conditions 5
Paths 16

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4555
c 0
b 0
f 0
cc 5
nc 16
nop 1
1
<?php
2
3
namespace LPTracker\models;
4
5
use LPTracker\exceptions\LPTrackerSDKException;
6
7
/**
8
 * This class represents visitor as seen in LPTracker widget and should be treated as opaque.
9
 */
10
final class Visitor extends Model
11
{
12
    /**
13
     * @var int
14
     */
15
    private $version;
16
17
    /**
18
     * @var string
19
     */
20
    private $fingerprint;
21
22
    /**
23
     * @var string
24
     */
25
    private $browser;
26
27
    /**
28
     * @var string
29
     */
30
    private $ip;
31
32
    public function __construct(array $visitorData = [])
33
    {
34
        if (isset($visitorData['version'])) {
35
            $this->version = (int) $visitorData['version'];
36
        }
37
        if (isset($visitorData['fingerprint'])) {
38
            $this->fingerprint = $visitorData['fingerprint'];
39
        }
40
        if (isset($visitorData['browser'])) {
41
            $this->browser = $visitorData['browser'];
42
        }
43
        if (isset($visitorData['ip'])) {
44
            $this->ip = $visitorData['ip'];
45
        }
46
    }
47
48
    /**
49
     * @return array
50
     */
51
    public function toArray()
52
    {
53
        return [
54
            'version' => $this->version,
55
            'fingerprint' => $this->fingerprint,
56
            'browser' => $this->browser,
57
            'ip' => $this->ip,
58
        ];
59
    }
60
61
    /**
62
     * @return bool
63
     * @throws LPTrackerSDKException
64
     */
65
    public function validate()
66
    {
67
        if ($this->version === null) {
68
            throw new LPTrackerSDKException('Visitor version is required');
69
        }
70
71
        if (empty($this->fingerprint)) {
72
            throw new LPTrackerSDKException('Visitor fingerprint is required');
73
        }
74
75
        if (empty($this->browser)) {
76
            throw new LPTrackerSDKException('Visitor user agent is required');
77
        }
78
79
        if (empty($this->ip)) {
80
            throw new LPTrackerSDKException('Visitor IP is required');
81
        }
82
83
        return true;
84
    }
85
}
86