Skip to content

Commit f7c4226

Browse files
committed
fix: use $this->time() instead of time()
For testing, we need to use testTime in all places.
1 parent 6cd0839 commit f7c4226

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

system/Throttle/Throttler.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function check(string $key, int $capacity, int $seconds, int $cost = 1):
100100
// If it hasn't been created, then we'll set it to the maximum
101101
// capacity - 1, and save it to the cache.
102102
$this->cache->save($tokenName, $capacity - $cost, $seconds);
103-
$this->cache->save($tokenName . 'Time', time(), $seconds);
103+
$this->cache->save($tokenName . 'Time', $this->time(), $seconds);
104104

105105
return true;
106106
}
@@ -129,7 +129,7 @@ public function check(string $key, int $capacity, int $seconds, int $cost = 1):
129129
// we need to decrement the number of available tokens.
130130
if ($tokens >= 1) {
131131
$this->cache->save($tokenName, $tokens - $cost, $seconds);
132-
$this->cache->save($tokenName . 'Time', time(), $seconds);
132+
$this->cache->save($tokenName . 'Time', $this->time(), $seconds);
133133

134134
return true;
135135
}
@@ -164,6 +164,8 @@ public function setTestTime(int $time)
164164

165165
/**
166166
* Return the test time, defaulting to current.
167+
*
168+
* @TODO should be private
167169
*/
168170
public function time(): int
169171
{

0 commit comments

Comments
 (0)