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.

RegistrationExpirationHelper::expiresAt()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * Copyright 2018 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupBundle\DateTime;
20
21
use DateInterval;
22
use DateTime as CoreDateTime;
23
use Exception;
24
use Surfnet\StepupBundle\Exception\InvalidArgumentException;
25
26
/**
27
 * Helps with testing if a registration date of a token is within the expiration time frame.
28
 */
29
class RegistrationExpirationHelper
30
{
31
    /**
32
     * The current time, this field can be set for testing purposes
33
     * @var DateTime
34
     */
35
    private $now;
36
37
    /**
38
     * @var string a DateInterval complient $interval_spec string
39
     */
40
    private $expirationWindow;
41
42
    public function __construct(CoreDateTime $now = null, $expirationWindow = 'P14D')
43
    {
44
        $this->now = $now;
0 ignored issues
show
Documentation Bug introduced by
It seems like $now can also be of type object<DateTime>. However, the property $now is declared as type object<Surfnet\StepupBundle\DateTime\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...
45
46
        try {
47
            $this->expirationWindow = new DateInterval($expirationWindow);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \DateInterval($expirationWindow) of type object<DateInterval> is incompatible with the declared type string of property $expirationWindow.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
48
        } catch (Exception $e) {
49
            throw new InvalidArgumentException(
50
                sprintf(
51
                    'The provided DateInterval interval specification ("%s") is invalid',
52
                    $expirationWindow
53
                )
54
            );
55
        }
56
    }
57
58
    public function expiresAt(CoreDateTime $registeredAt)
59
    {
60
        $registrationDate = clone $registeredAt;
61
        return $registrationDate->add($this->expirationWindow);
62
    }
63
64
    public function hasExpired(CoreDateTime $registeredAt)
65
    {
66
        $now = $this->getNow();
67
        return $this->expiresAt($registeredAt) <= $now;
68
    }
69
70
    private function getNow()
71
    {
72
        if (is_null($this->now)) {
73
            $this->now = new CoreDateTime();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \DateTime() of type object<DateTime> is incompatible with the declared type object<Surfnet\StepupBundle\DateTime\DateTime> of property $now.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
74
        }
75
        return $this->now;
76
    }
77
}
78