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.
Completed
Push — master ( 5345ef...b3f137 )
by Sergey
01:27
created

Employee::validate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 0
1
<?php
2
3
namespace LPTracker\models;
4
5
use LPTracker\exceptions\LPTrackerSDKException;
6
7
class Employee extends Model
8
{
9
    /**
10
     * @var int
11
     */
12
    protected $id;
13
14
    /**
15
     * @var string
16
     */
17
    protected $name;
18
19
    /**
20
     * @var string
21
     */
22
    protected $job;
23
24
    /**
25
     * @var string
26
     */
27
    protected $type;
28
29
    /**
30
     * @var \DateTimeImmutable
31
     */
32
    protected $lastLoginAt;
33
34
    /**
35
     * @var \DateTimeImmutable
36
     */
37
    protected $createdAt;
38
39
    public function __construct(array $employeeData = [])
40
    {
41
        if (isset($employeeData['id'])) {
42
            $this->id = (int) $employeeData['id'];
43
        }
44
        if (isset($employeeData['name'])) {
45
            $this->name = $employeeData['name'];
46
        }
47
        if (isset($employeeData['job'])) {
48
            $this->job = $employeeData['job'];
49
        }
50
        if (isset($employeeData['type'])) {
51
            $this->type = $employeeData['type'];
52
        }
53
        if (isset($employeeData['last_login_at'])) {
54
            $this->lastLoginAt = (new \DateTimeImmutable())->setTimestamp($employeeData['last_login_at']);
0 ignored issues
show
Documentation Bug introduced by
It seems like (new \DateTimeImmutable(...eData['last_login_at']) can also be of type false. However, the property $lastLoginAt is declared as type object<DateTimeImmutable>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
55
        }
56
        if (isset($employeeData['created_at'])) {
57
            $this->createdAt = (new \DateTimeImmutable())->setTimestamp($employeeData['created_at']);
0 ignored issues
show
Documentation Bug introduced by
It seems like (new \DateTimeImmutable(...oyeeData['created_at']) can also be of type false. However, the property $createdAt is declared as type object<DateTimeImmutable>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
58
        }
59
    }
60
61
    /**
62
     * @return bool
63
     * @throws LPTrackerSDKException
64
     */
65 View Code Duplication
    public function validate()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66
    {
67
        if ($this->id === null) {
68
            throw new LPTrackerSDKException('Employee ID is required');
69
        }
70
71
        if (empty($this->name)) {
72
            throw new LPTrackerSDKException('Employee name is required');
73
        }
74
75
        return true;
76
    }
77
78
    /**
79
     * @return array
80
     */
81
    public function toArray()
82
    {
83
        return [
84
            'id' => $this->getId(),
85
            'name' => $this->getName(),
86
            'job' => $this->getJob(),
87
            'type' => $this->getType(),
88
            'last_login_at' => $this->getLastLoginAt() 
89
                ? $this->getLastLoginAt()->getTimestamp() 
90
                : null,
91
            'created_at' => $this->getCreatedAt() 
92
                ? $this->getCreatedAt()->getTimestamp() 
93
                : null,
94
        ];
95
    }
96
97
    /**
98
     * @return int
99
     */
100
    public function getId()
101
    {
102
        return $this->id;
103
    }
104
105
    /**
106
     * @return string
107
     */
108
    public function getName()
109
    {
110
        return $this->name;
111
    }
112
113
    /**
114
     * @return string
115
     */
116
    public function getJob()
117
    {
118
        return $this->job;
119
    }
120
121
    /**
122
     * @return string
123
     */
124
    public function getType()
125
    {
126
        return $this->type;
127
    }
128
129
    /**
130
     * @return \DateTimeImmutable
131
     */
132
    public function getLastLoginAt()
133
    {
134
        return $this->lastLoginAt;
135
    }
136
137
    /**
138
     * @return \DateTimeImmutable
139
     */
140
    public function getCreatedAt()
141
    {
142
        return $this->createdAt;
143
    }
144
}
145