Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
60.00% covered (warning)
60.00%
3 / 5
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
LimitCondition
60.00% covered (warning)
60.00%
3 / 5
0.00% covered (danger)
0.00%
0 / 2
3.58
0.00% covered (danger)
0.00%
0 / 1
 __construct
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
2.06
 perSecond
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Wikimedia\WRStats;
4
5/**
6 * @since 1.39
7 * @newable
8 */
9class LimitCondition {
10    /** @var int The maximum number of events */
11    public $limit;
12    /** @var float|int The number of seconds over which the number of events may occur */
13    public $window;
14
15    /**
16     * @param int|float|string $limit The maximum number of events
17     * @param int|float|string $window The number of seconds over which the
18     *   number of events may occur
19     */
20    public function __construct( $limit, $window ) {
21        $this->limit = (int)$limit;
22        $this->window = +$window;
23        if ( $this->window <= 0 ) {
24            throw new WRStatsError( 'Condition window must be positive' );
25        }
26    }
27
28    /**
29     * Get the condition as a number of events per second
30     *
31     * @return float|int
32     */
33    public function perSecond() {
34        return $this->limit / $this->window;
35    }
36}