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.

Comment   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 123
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 6
A toArray() 0 9 1
A validate() 0 8 2
A getId() 0 4 1
A getText() 0 4 1
A setText() 0 5 1
A getOwnerId() 0 4 1
A getCreatedAt() 0 4 1
A setCreatedAt() 0 8 2
1
<?php
2
3
namespace LPTracker\models;
4
5
use LPTracker\exceptions\LPTrackerSDKException;
6
7
class Comment extends Model
8
{
9
    /**
10
     * @var integer
11
     */
12
    protected $id;
13
14
    /**
15
     * @var string
16
     */
17
    protected $text;
18
19
    /**
20
     * @var integer
21
     */
22
    protected $ownerId;
23
24
    /**
25
     * @var \DateTime
26
     */
27
    protected $createdAt;
28
29
    public function __construct(array $commentData = [])
30
    {
31
        if (!empty($commentData['id'])) {
32
            $this->id = (int) $commentData['id'];
33
        }
34
        if (!empty($commentData['text'])) {
35
            $this->text = $commentData['text'];
36
        }
37
        if (!empty($commentData['author'])) {
38
            if ($commentData['author']['type'] === 'main') {
39
                $this->ownerId = 0;
40
            } else {
41
                $this->ownerId = (int) $commentData['author']['id'];
42
            }
43
        }
44
        if (!empty($commentData['created_at'])) {
45
            $this->setCreatedAt($commentData['created_at']);
46
        }
47
    }
48
49
    /**
50
     * @return array
51
     */
52
    public function toArray()
53
    {
54
        return [
55
            'id' => $this->getId(),
56
            'text' => $this->getText(),
57
            'owner' => $this->getOwnerId(),
58
            'created_at' => $this->getCreatedAt()->format('d.m.Y H:i:s'),
59
        ];
60
    }
61
62
    /**
63
     * @return bool
64
     * @throws LPTrackerSDKException
65
     */
66
    public function validate()
67
    {
68
        if (empty($this->text)) {
69
            throw new LPTrackerSDKException('Text is required');
70
        }
71
72
        return true;
73
    }
74
75
    /**
76
     * @return int
77
     */
78
    public function getId()
79
    {
80
        return $this->id;
81
    }
82
83
    /**
84
     * @return string
85
     */
86
    public function getText()
87
    {
88
        return $this->text;
89
    }
90
91
    /**
92
     * @param string $text
93
     * @return $this
94
     */
95
    public function setText($text)
96
    {
97
        $this->text = $text;
98
        return $this;
99
    }
100
101
    /**
102
     * @return int
103
     */
104
    public function getOwnerId()
105
    {
106
        return $this->ownerId;
107
    }
108
109
    /**
110
     * @return \DateTime
111
     */
112
    public function getCreatedAt()
113
    {
114
        return $this->createdAt;
115
    }
116
117
    /**
118
     * @param \DateTime|string $createdAt
119
     * @return $this
120
     */
121
    public function setCreatedAt($createdAt)
122
    {
123
        if (!$createdAt instanceof \DateTime) {
124
            $createdAt = \DateTime::createFromFormat('d.m.Y H:i:s', $createdAt);
125
        }
126
        $this->createdAt = $createdAt;
0 ignored issues
show
Documentation Bug introduced by
It seems like $createdAt can also be of type false. However, the property $createdAt is declared as type object<DateTime>. 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...
127
        return $this;
128
    }
129
}
130