@@ -98,6 +98,11 @@
Loading
98 98
     */
99 99
    protected $optionProvider;
100 100
101 +
    /**
102 +
     * @var Clock
103 +
     */
104 +
    protected $clock;
105 +
101 106
    /**
102 107
     * Constructs an OAuth 2.0 service provider.
103 108
     *
@@ -138,6 +143,11 @@
Loading
138 143
            $collaborators['optionProvider'] = new PostAuthOptionProvider();
139 144
        }
140 145
        $this->setOptionProvider($collaborators['optionProvider']);
146 +
147 +
        if (empty($collaborators['clock'])) {
148 +
            $collaborators['clock'] = new Clock();
149 +
        }
150 +
        $this->setClock($collaborators['clock']);
141 151
    }
142 152
143 153
    /**
@@ -252,6 +262,31 @@
Loading
252 262
        return $this->optionProvider;
253 263
    }
254 264
265 +
    /**
266 +
     * Sets the clock.
267 +
     *
268 +
     * @param  Clock $clock
269 +
     *
270 +
     * @return self
271 +
     */
272 +
    public function setClock(Clock $clock)
273 +
    {
274 +
        $this->clock = $clock;
275 +
276 +
        return $this;
277 +
    }
278 +
279 +
280 +
    /**
281 +
     * Returns the clock.
282 +
     *
283 +
     * @return Clock
284 +
     */
285 +
    public function getClock()
286 +
    {
287 +
        return $this->clock;
288 +
    }
289 +
255 290
    /**
256 291
     * Returns the current value of the state parameter.
257 292
     *
@@ -541,6 +576,7 @@
Loading
541 576
            );
542 577
        }
543 578
        $prepared = $this->prepareAccessTokenResponse($response);
579 +
        $prepared['clock'] = $this->clock;
544 580
        $token    = $this->createAccessToken($prepared, $grant);
545 581
546 582
        return $token;

@@ -15,7 +15,7 @@
Loading
15 15
namespace League\OAuth2\Client\Token;
16 16
17 17
use InvalidArgumentException;
18 -
use League\OAuth2\Client\Provider\ProviderClock;
18 +
use League\OAuth2\Client\Provider\Clock;
19 19
use RuntimeException;
20 20
21 21
/**
@@ -58,7 +58,11 @@
Loading
58 58
    private static $timeNow;
59 59
60 60
    /**
61 -
     * Set the time now. This should only be used for testing purposes.
61 +
     * The clock.
62 +
     *
63 +
     * @var Clock
64 +
     */
65 +
    protected $clock;
62 66
63 67
    /**
64 68
     * Sets the current time.
@@ -82,15 +86,25 @@
Loading
82 86
    }
83 87
84 88
    /**
89 +
     * @inheritdoc
90 +
     */
91 +
    public function setClock(Clock $clock)
92 +
    {
93 +
        $this->clock = $clock;
94 +
    }
85 95
86 96
    /**
87 -
     * Get the current time, whether true or simulated.
88 -
     *
89 -
     * @return int
97 +
     * @inheritdoc
90 98
     */
91 99
    public function getTimeNow()
92 100
    {
93 -
        return self::$timeNow ? self::$timeNow : time();
101 +
        if (self::$timeNow) {
102 +
            return self::$timeNow;
103 +
        } elseif (isset($this->clock)) {
104 +
            return $this->clock->now()->getTimestamp();
105 +
        } else {
106 +
            return time();
107 +
        }
94 108
    }
95 109
96 110
    /**
@@ -116,6 +130,10 @@
Loading
116 130
            $this->refreshToken = $options['refresh_token'];
117 131
        }
118 132
133 +
        if (!empty($options['clock'])) {
134 +
            $this->clock = $options['clock'];
135 +
        }
136 +
119 137
        // We need to know when the token expires. Show preference to
120 138
        // 'expires_in' since it is defined in RFC6749 Section 5.1.
121 139
        // Defer to 'expires' if it is provided instead.

@@ -0,0 +1,20 @@
Loading
1 +
<?php
2 +
3 +
namespace League\OAuth2\Client\Provider;
4 +
5 +
/**
6 +
 * Represents an implementation of a Clock.
7 +
 */
8 +
class Clock
9 +
{
10 +
11 +
  /**
12 +
   * Get the current time.
13 +
   *
14 +
   * @return \DateTimeImmutable
15 +
   */
16 +
    public function now()
17 +
    {
18 +
        return new \DateTimeImmutable();
19 +
    }
20 +
}
Files Complexity Coverage
src 187 100.00%
Project Totals (21 files) 187 100.00%
1
codecov:
2
  require_ci_to_pass: yes
3

4
coverage:
5
  precision: 2
6
  round: down
7
  range: "70...100"
8
  status:
9
    project:
10
      default:
11
        target: auto
12
        threshold: 0%
13
    patch:
14
      default:
15
        target: auto
16
        threshold: 0%
17

18
parsers:
19
  gcov:
20
    branch_detection:
21
      conditional: yes
22
      loop: yes
23
      method: no
24
      macro: no
25

26
comment:
27
  layout: "reach,diff,flags,tree"
28
  behavior: default
29
  require_changes: false
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading