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 — develop ( 87fa6e...470348 )
by
unknown
06:45
created

RegistrationExpirationHelper::expiresAt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
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;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Surfnet\StepupBundle\DateTime\DateTime.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
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(DateTime $now = null, $expirationWindow = 'P14D')
43
    {
44
        $this->now = $now;
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(DateTime $registeredAt)
59
    {
60
        $registrationDate = clone $registeredAt;
61
        return $registrationDate->add($this->expirationWindow);
62
    }
63
64
    public function hasExpired(DateTime $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 DateTime();
74
        }
75
        return $this->now;
76
    }
77
}
78