| Conditions | 2 |
| Paths | 2 |
| Total Lines | 18 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 8 |
| CRAP Score | 2.0054 |
| Changes | 0 | ||
| 1 | <?php |
||
| 28 | 2 | public static function createRedisBackedRateLimiter(array $redisOptions = [], $limit = self::DEFAULT_LIMIT, $window = self::DEFAULT_WINDOW) |
|
| 29 | { |
||
| 30 | 2 | $redisOptions = array_merge([ |
|
| 31 | 2 | 'host' => '127.0.0.1', |
|
| 32 | 'port' => 6379, |
||
| 33 | 'timeout' => 0.0, |
||
| 34 | 2 | ], $redisOptions); |
|
| 35 | |||
| 36 | 2 | if (!class_exists('\Redis')) { |
|
| 37 | throw new \Exception('\Redis class was not found.'); |
||
| 38 | } |
||
| 39 | |||
| 40 | 2 | $redis = new Redis(); |
|
| 41 | |||
| 42 | 2 | $redis->connect($redisOptions['host'], $redisOptions['port'], $redisOptions['timeout']); |
|
| 43 | |||
| 44 | 2 | return new RedisRateLimiter($redis, $limit, $window); |
|
| 45 | } |
||
| 46 | } |
||
| 47 |